summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2009-03-08 17:50:02 +0000
committerAdrian Thurston <thurston@complang.org>2009-03-08 17:50:02 +0000
commit510380a31d6a5114753709ec0f6e90fc8ee85921 (patch)
treec50f0518979f5c7f171f477af20f433a595e5924
parent2ca2d1eed5449f90b8fb63556f0f465121667fb2 (diff)
downloadcolm-510380a31d6a5114753709ec0f6e90fc8ee85921.tar.gz
Since there is no longer a continually run scanner loop that pushes tokens, we
can initialize FsmRun::cs and FsmRun::tokstart at the beginning of teach run of the scanner in which we attempt to fetch a token.
-rw-r--r--colm/fsmrun.cpp47
-rw-r--r--colm/fsmrun.h2
2 files changed, 4 insertions, 45 deletions
diff --git a/colm/fsmrun.cpp b/colm/fsmrun.cpp
index 811899f1..f5968585 100644
--- a/colm/fsmrun.cpp
+++ b/colm/fsmrun.cpp
@@ -192,9 +192,6 @@ void FsmRun::sendBackText( const char *data, long length )
assert( memcmp( data, p, length ) == 0 );
undo_position( this, data, length );
-
- /* We are adjusting p so this must be reset. */
- tokstart = 0;
}
void FsmRun::queueBack( PdaRun *parser, Kid *input )
@@ -397,10 +394,6 @@ void send_queued_tokens( FsmRun *fsmRun, PdaRun *parser )
parser->ignore( send->tree );
fsmRun->prg->kidPool.free( send );
-
- /* Set the current state from the next region. */
- fsmRun->region = parser->getNextRegion();
- fsmRun->cs = fsmRun->tables->entryByRegion[fsmRun->region];
}
else {
#ifdef COLM_LOG_PARSE
@@ -583,10 +576,6 @@ void send_handle_error( FsmRun *fsmRun, PdaRun *parser, Kid *input )
parser->parse_error(id, input->tree) << "parse error" << endp;
}
else {
- /* Set the current state from the next region. */
- fsmRun->region = parser->getNextRegion();
- fsmRun->cs = fsmRun->tables->entryByRegion[fsmRun->region];
-
if ( parser->isParserStopFinished() ) {
#ifdef COLM_LOG_PARSE
if ( colm_log_parse ) {
@@ -636,11 +625,8 @@ void exec_gen( FsmRun *fsmRun, PdaRun *parser, long id )
* data is pulled from the stream. */
fsmRun->p = fsmRun->tokstart;
- fsmRun->tokstart = 0;
generation_action( fsmRun, parser, id, tokdata, false, 0 );
-
- memset( fsmRun->mark, 0, sizeof(fsmRun->mark) );
}
void send_ignore( FsmRun *fsmRun, PdaRun *parser, long id )
@@ -659,7 +645,6 @@ void send_ignore( FsmRun *fsmRun, PdaRun *parser, long id )
int length = fsmRun->p - fsmRun->tokstart;
Head *ignoreStr = string_alloc_const( fsmRun->prg, fsmRun->tokstart, length );
update_position( fsmRun, fsmRun->tokstart, length );
- fsmRun->tokstart = 0;
Tree *tree = fsmRun->prg->treePool.allocate();
tree->refs = 1;
@@ -668,12 +653,6 @@ void send_ignore( FsmRun *fsmRun, PdaRun *parser, long id )
/* Send it to the parser. */
parser->ignore( tree );
-
- /* Prepare for more scanning. */
- fsmRun->region = parser->getNextRegion();
- fsmRun->cs = fsmRun->tables->entryByRegion[fsmRun->region];
-
- memset( fsmRun->mark, 0, sizeof(fsmRun->mark) );
}
void send_token( FsmRun *fsmRun, PdaRun *parser, long id )
@@ -693,14 +672,8 @@ void send_token( FsmRun *fsmRun, PdaRun *parser, long id )
Head *tokdata = string_alloc_const( fsmRun->prg, fsmRun->tokstart, length );
update_position( fsmRun, fsmRun->tokstart, length );
- /* By default the match is consumed and this is what we need. Just
- * need to reset tokstart. */
- fsmRun->tokstart = 0;
-
Kid *input = make_token( fsmRun, parser, id, tokdata, false, 0 );
send_handle_error( fsmRun, parser, input );
-
- memset( fsmRun->mark, 0, sizeof(fsmRun->mark) );
}
/* Load up a token, starting from tokstart if it is set. If not set then
@@ -774,10 +747,6 @@ void send_eof( FsmRun *fsmRun, PdaRun *parser )
parser->parse_error( input->tree->id, input->tree ) <<
"parse error" << endp;
}
-
- fsmRun->tokstart = 0;
- fsmRun->region = parser->getNextRegion();
- fsmRun->cs = fsmRun->tables->entryByRegion[fsmRun->region];
}
@@ -839,8 +808,6 @@ void scanner_error( FsmRun *fsmRun, PdaRun *parser )
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: " <<
@@ -866,8 +833,6 @@ void scanner_error( FsmRun *fsmRun, PdaRun *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: " <<
@@ -887,7 +852,7 @@ void parse( FsmRun *fsmRun, PdaRun *parser )
parser->init();
while ( true ) {
- int tokenId = fsmRun->scan( parser );
+ int tokenId = fsmRun->scanToken( parser );
/* Check for EOF. */
if ( tokenId == SCAN_EOF ) {
@@ -932,10 +897,8 @@ void parse( FsmRun *fsmRun, PdaRun *parser )
}
}
-long FsmRun::scan( PdaRun *parser )
+long FsmRun::scanToken( PdaRun *parser )
{
- long space;
-
/* Init the scanner vars. */
act = 0;
tokstart = 0;
@@ -949,9 +912,6 @@ long FsmRun::scan( PdaRun *parser )
/* Clear the mark array. */
memset( mark, 0, sizeof(mark) );
- /* Start with the EOF test. The pattern and replacement input sources can
- * be EOF from the start. */
-
while ( true ) {
execute();
@@ -1002,7 +962,7 @@ long FsmRun::scan( PdaRun *parser )
/* There may be space left in the current buffer. If not then we need
* to make some. */
- space = runBuf->buf + FSM_BUFSIZE - pe;
+ long space = runBuf->buf + FSM_BUFSIZE - pe;
if ( space == 0 ) {
/* Create a new run buf. */
RunBuf *newBuf = new RunBuf;
@@ -1058,7 +1018,6 @@ long FsmRun::scan( PdaRun *parser )
pe = p + len;
if ( inputStream->needFlush() )
peof = pe;
-
}
/* Should not be reached. */
diff --git a/colm/fsmrun.h b/colm/fsmrun.h
index 920508f3..8fed546c 100644
--- a/colm/fsmrun.h
+++ b/colm/fsmrun.h
@@ -98,7 +98,7 @@ struct FsmRun
void sendBackText( const char *data, long length );
void execAction( GenAction *action );
- long scan( PdaRun *parser );
+ long scanToken( PdaRun *parser );
void attachInputStream( InputStream *in );
void streamPush( const char *data, long length );
void undoStreamPush( long length );