diff options
-rw-r--r-- | colm/bytecode.cpp | 2 | ||||
-rw-r--r-- | colm/fsmrun.cpp | 21 | ||||
-rw-r--r-- | colm/fsmrun.h | 3 |
3 files changed, 15 insertions, 11 deletions
diff --git a/colm/bytecode.cpp b/colm/bytecode.cpp index b40326f3..89056443 100644 --- a/colm/bytecode.cpp +++ b/colm/bytecode.cpp @@ -164,7 +164,7 @@ void undo_parse( Tree **&sp, Program *prg, Stream *stream, Tree *stream_pull( Program *prg, PdaRun *parser, Stream *stream, Tree *length ) { long len = ((Int*)length)->value; - Head *tokdata = stream->fsmRun->extractToken( parser, len ); + Head *tokdata = stream->fsmRun->extractPrefix( parser, len ); return construct_string( prg, tokdata ); } diff --git a/colm/fsmrun.cpp b/colm/fsmrun.cpp index 3280242b..42cb6788 100644 --- a/colm/fsmrun.cpp +++ b/colm/fsmrun.cpp @@ -607,8 +607,7 @@ void exec_gen( FsmRun *fsmRun, PdaRun *parser, long id ) #endif /* Make the token data. */ - long length = fsmRun->p - fsmRun->tokstart; - Head *tokdata = string_alloc_const( fsmRun->prg, fsmRun->tokstart, length ); + Head *tokdata = fsmRun->extractMatch(); /* Note that we don't update the position now. It is done when the token * data is pulled from the stream. */ @@ -627,9 +626,8 @@ void send_ignore( FsmRun *fsmRun, PdaRun *parser, long id ) #endif /* Make the ignore string. */ - int length = fsmRun->p - fsmRun->tokstart; - Head *ignoreStr = string_alloc_const( fsmRun->prg, fsmRun->tokstart, length ); - update_position( fsmRun, fsmRun->tokstart, length ); + Head *ignoreStr = fsmRun->extractMatch(); + update_position( fsmRun, fsmRun->tokstart, ignoreStr->length ); Tree *tree = fsmRun->prg->treePool.allocate(); tree->refs = 1; @@ -640,6 +638,12 @@ void send_ignore( FsmRun *fsmRun, PdaRun *parser, long id ) parser->ignore( tree ); } +Head *FsmRun::extractMatch( ) +{ + long length = p - tokstart; + return string_alloc_const( prg, tokstart, length ); +} + void send_token( FsmRun *fsmRun, PdaRun *parser, long id ) { #ifdef COLM_LOG_PARSE @@ -649,9 +653,8 @@ void send_token( FsmRun *fsmRun, PdaRun *parser, long id ) #endif /* Make the token data. */ - long length = fsmRun->p - fsmRun->tokstart; - Head *tokdata = string_alloc_const( fsmRun->prg, fsmRun->tokstart, length ); - update_position( fsmRun, fsmRun->tokstart, length ); + Head *tokdata = fsmRun->extractMatch(); + update_position( fsmRun, fsmRun->tokstart, tokdata->length ); Kid *input = make_token( fsmRun, parser, id, tokdata, false, 0 ); send_handle_error( fsmRun, parser, input ); @@ -659,7 +662,7 @@ void send_token( FsmRun *fsmRun, PdaRun *parser, long id ) /* Load up a token, starting from tokstart if it is set. If not set then * start it at p. */ -Head *FsmRun::extractToken( PdaRun *parser, long length ) +Head *FsmRun::extractPrefix( PdaRun *parser, long length ) { /* How much do we have already? Tokstart may or may not be set. */ assert( tokstart == 0 ); diff --git a/colm/fsmrun.h b/colm/fsmrun.h index 8fed546c..6b963917 100644 --- a/colm/fsmrun.h +++ b/colm/fsmrun.h @@ -103,7 +103,8 @@ struct FsmRun void streamPush( const char *data, long length ); void undoStreamPush( long length ); - Head *extractToken( PdaRun *parser, long len ); + Head *extractMatch(); + Head *extractPrefix( PdaRun *parser, long len ); void execute(); |