summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2009-03-08 03:47:55 +0000
committerAdrian Thurston <thurston@complang.org>2009-03-08 03:47:55 +0000
commit9104dd570ccd0216b6068f1d19e8b77c49884ba8 (patch)
tree28aa725c2dbd2f0db648c48791b90bf4e3729e8e
parent5bb41f82c1c8a9edf8bf7b73de20425888de639c (diff)
downloadcolm-9104dd570ccd0216b6068f1d19e8b77c49884ba8.tar.gz
Scanner error handling code moved to separate function.
-rw-r--r--colm/fsmrun.cpp114
1 files changed, 60 insertions, 54 deletions
diff --git a/colm/fsmrun.cpp b/colm/fsmrun.cpp
index 24e40ae2..43d63687 100644
--- a/colm/fsmrun.cpp
+++ b/colm/fsmrun.cpp
@@ -836,6 +836,64 @@ long PdaRun::undoParse( Tree *tree, CodeVect *rev )
#define SCAN_LANG_EL -2
#define SCAN_EOF -1
+void scanner_error( FsmRun *fsmRun, PdaRun *parser )
+{
+ if ( parser->getNextRegion( 1 ) != 0 ) {
+ #ifdef COLM_LOG_PARSE
+ if ( colm_log_parse ) {
+ cerr << "scanner failed, trying next region" << endl;
+ }
+ #endif
+
+ /* May have accumulated ignore tokens from a previous region.
+ * need to rescan them since we won't be sending tokens from
+ * this region. */
+ parser->sendBackIgnore();
+
+ parser->nextRegionInd += 1;
+ fsmRun->region = parser->getNextRegion();
+ fsmRun->cs = fsmRun->tables->entryByRegion[fsmRun->region];
+ #ifdef COLM_LOG_PARSE
+ if ( colm_log_parse ) {
+ cerr << "new token region: " <<
+ parser->tables->rtd->regionInfo[fsmRun->region].name << endl;
+ }
+ #endif
+ return;
+ }
+
+ if ( parser->numRetry > 0 ) {
+ /* Invoke the parser's error handling. */
+ #ifdef COLM_LOG_PARSE
+ if ( colm_log_parse ) {
+ cerr << "invoking parse error from the scanner" << endl;
+ }
+ #endif
+
+ parser->sendBackIgnore();
+ parser->parseToken( 0 );
+
+ if ( parser->errCount > 0 ) {
+ /* Error occured in the top-level parser. */
+ cerr << "PARSE ERROR" << endp;
+ }
+ else {
+ fsmRun->region = parser->getNextRegion();
+ fsmRun->cs = fsmRun->tables->entryByRegion[fsmRun->region];
+ #ifdef COLM_LOG_PARSE
+ if ( colm_log_parse ) {
+ cerr << "new token region: " <<
+ parser->tables->rtd->regionInfo[fsmRun->region].name << endl;
+ }
+ #endif
+ return;
+ }
+ }
+
+ /* Machine failed before finding a token. */
+ cerr << "error:" << fsmRun->inputStream->line << ": scanner error" << endp;
+}
+
void parse( FsmRun *fsmRun, PdaRun *parser )
{
parser->init();
@@ -871,60 +929,8 @@ void parse( FsmRun *fsmRun, PdaRun *parser )
/* Check for error. */
if ( tokenId == SCAN_ERROR ) {
- if ( parser->getNextRegion( 1 ) != 0 ) {
- #ifdef COLM_LOG_PARSE
- if ( colm_log_parse ) {
- cerr << "scanner failed, trying next region" << endl;
- }
- #endif
-
- /* May have accumulated ignore tokens from a previous region.
- * need to rescan them since we won't be sending tokens from
- * this region. */
- parser->sendBackIgnore();
-
- parser->nextRegionInd += 1;
- fsmRun->region = parser->getNextRegion();
- fsmRun->cs = fsmRun->tables->entryByRegion[fsmRun->region];
- #ifdef COLM_LOG_PARSE
- if ( colm_log_parse ) {
- cerr << "new token region: " <<
- parser->tables->rtd->regionInfo[fsmRun->region].name << endl;
- }
- #endif
- continue;
- }
-
- if ( parser->numRetry > 0 ) {
- /* Invoke the parser's error handling. */
- #ifdef COLM_LOG_PARSE
- if ( colm_log_parse ) {
- cerr << "invoking parse error from the scanner" << endl;
- }
- #endif
-
- parser->sendBackIgnore();
- parser->parseToken( 0 );
-
- if ( parser->errCount > 0 ) {
- /* Error occured in the top-level parser. */
- cerr << "PARSE ERROR" << endp;
- }
- else {
- fsmRun->region = parser->getNextRegion();
- fsmRun->cs = fsmRun->tables->entryByRegion[fsmRun->region];
- #ifdef COLM_LOG_PARSE
- if ( colm_log_parse ) {
- cerr << "new token region: " <<
- parser->tables->rtd->regionInfo[fsmRun->region].name << endl;
- }
- #endif
- continue;
- }
- }
-
- /* Machine failed before finding a token. */
- cerr << "error:" << fsmRun->inputStream->line << ": scanner error" << endp;
+ scanner_error( fsmRun, parser );
+ continue;
}
bool ctxDepParsing = fsmRun->prg->ctxDepParsing;