diff options
-rw-r--r-- | colm/fsmrun.cpp | 114 |
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; |