summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2009-03-08 22:10:38 +0000
committerAdrian Thurston <thurston@complang.org>2009-03-08 22:10:38 +0000
commit263d0ae256493a4295addb38bc24d5f0dc3b65fb (patch)
treeb5bb0d0c5584265d29ba1373128e262539b26b4f
parent03be7ac1612f8469698059373fa8be130610b13b (diff)
downloadcolm-263d0ae256493a4295addb38bc24d5f0dc3b65fb.tar.gz
Some cleanup.
-rw-r--r--colm/bytecode.cpp2
-rw-r--r--colm/fsmrun.cpp21
-rw-r--r--colm/fsmrun.h3
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();