summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2013-01-07 08:14:10 -0500
committerAdrian Thurston <thurston@complang.org>2013-01-07 08:14:10 -0500
commitad15ebcb3326f7a63516618383aae3f24ee2c7be (patch)
treec60f66ca9bde7bd3c42761ed5b001bad733c7b64
parent205da42c6f7f9aef3caa4acda774249e58dd7c20 (diff)
downloadcolm-ad15ebcb3326f7a63516618383aae3f24ee2c7be.tar.gz
added support for pushing streams
Still need to properly handle EOF on non-accum streams that have other streams pushed.
-rw-r--r--colm/bytecode.c5
-rw-r--r--colm/input.c45
-rw-r--r--colm/input.h16
-rw-r--r--colm/pdarun.c7
-rw-r--r--colm/pdarun.h1
5 files changed, 50 insertions, 24 deletions
diff --git a/colm/bytecode.c b/colm/bytecode.c
index df92e2e5..94e7d9b6 100644
--- a/colm/bytecode.c
+++ b/colm/bytecode.c
@@ -334,6 +334,11 @@ long streamPush( Program *prg, Tree **sp, FsmRun *fsmRun, StreamImpl *in, Tree *
return length;
}
+ else if ( tree->id == LEL_ID_STREAM ) {
+ treeUpref( tree );
+ streamPushStream( fsmRun, in, tree );
+ return -1;
+ }
else {
treeUpref( tree );
streamPushTree( fsmRun, in, tree, ignore );
diff --git a/colm/input.c b/colm/input.c
index 2d60cee8..ba144d94 100644
--- a/colm/input.c
+++ b/colm/input.c
@@ -150,17 +150,17 @@ void initStreamFuncs()
streamFuncs.unsetEof = &_unsetEof;
streamFuncs.prependData = &_prependData;
- streamFuncs.undoPrependData = &_undoPrependData;
-
streamFuncs.prependTree = &_prependTree;
+ streamFuncs.prependStream = &_prependStream;
+ streamFuncs.undoPrependData = &_undoPrependData;
streamFuncs.undoPrependTree = &_undoPrependTree;
streamFuncs.appendData = &_appendData;
streamFuncs.appendTree = &_appendTree;
streamFuncs.appendStream = &_appendStream;
streamFuncs.undoAppendData = &_undoAppendData;
- streamFuncs.undoAppendStream = &_undoAppendStream;
streamFuncs.undoAppendTree = &_undoAppendTree;
+ streamFuncs.undoAppendStream = &_undoAppendStream;
}
@@ -693,6 +693,31 @@ void _prependData( StreamImpl *is, const char *data, long length )
}
}
+void _prependTree( StreamImpl *is, Tree *tree, int ignore )
+{
+ if ( is->attached != 0 )
+ detachStream( is->attached, is );
+
+ /* Create a new buffer for the data. This is the easy implementation.
+ * Something better is needed here. It puts a max on the amount of
+ * data that can be pushed back to the inputStream. */
+ RunBuf *newBuf = newRunBuf();
+ newBuf->type = ignore ? RunBufIgnoreType : RunBufTokenType;
+ newBuf->tree = tree;
+ inputStreamPrepend( is, newBuf );
+}
+
+void _prependStream( StreamImpl *in, struct ColmTree *tree )
+{
+ /* Create a new buffer for the data. This is the easy implementation.
+ * Something better is needed here. It puts a max on the amount of
+ * data that can be pushed back to the inputStream. */
+ RunBuf *newBuf = newRunBuf();
+ newBuf->type = RunBufSourceType;
+ newBuf->tree = tree;
+ inputStreamPrepend( in, newBuf );
+}
+
int _undoPrependData( StreamImpl *is, int length )
{
if ( is->attached != 0 )
@@ -742,20 +767,6 @@ int _undoPrependData( StreamImpl *is, int length )
return consumed;
}
-void _prependTree( StreamImpl *is, Tree *tree, int ignore )
-{
- if ( is->attached != 0 )
- detachStream( is->attached, is );
-
- /* Create a new buffer for the data. This is the easy implementation.
- * Something better is needed here. It puts a max on the amount of
- * data that can be pushed back to the inputStream. */
- RunBuf *newBuf = newRunBuf();
- newBuf->type = ignore ? RunBufIgnoreType : RunBufTokenType;
- newBuf->tree = tree;
- inputStreamPrepend( is, newBuf );
-}
-
Tree *_undoPrependTree( StreamImpl *is )
{
if ( is->attached != 0 )
diff --git a/colm/input.h b/colm/input.h
index 2bbcdae6..3bfc43c5 100644
--- a/colm/input.h
+++ b/colm/input.h
@@ -106,18 +106,21 @@ struct StreamFuncs
void (*setEof)( StreamImpl *is );
void (*unsetEof)( StreamImpl *is );
+ /* Prepending to a stream. */
void (*prependData)( StreamImpl *in, const char *data, long len );
- int (*undoPrependData)( StreamImpl *is, int length );
-
void (*prependTree)( StreamImpl *is, struct ColmTree *tree, int ignore );
+ void (*prependStream)( StreamImpl *in, struct ColmTree *tree );
+ int (*undoPrependData)( StreamImpl *is, int length );
struct ColmTree *(*undoPrependTree)( StreamImpl *is );
+ struct ColmTree *(*undoPrependStream)( StreamImpl *in );
+ /* Appending to a stream. */
void (*appendData)( StreamImpl *in, const char *data, long len );
void (*appendTree)( StreamImpl *in, struct ColmTree *tree );
void (*appendStream)( StreamImpl *in, struct ColmTree *tree );
struct ColmTree *(*undoAppendData)( StreamImpl *in, int length );
- struct ColmTree *(*undoAppendStream)( StreamImpl *in );
struct ColmTree *(*undoAppendTree)( StreamImpl *in );
+ struct ColmTree *(*undoAppendStream)( StreamImpl *in );
};
/* List of source streams. Enables streams to be pushed/popped. */
@@ -177,17 +180,18 @@ void _setEof( StreamImpl *is );
void _unsetEof( StreamImpl *is );
void _prependData( StreamImpl *in, const char *data, long len );
-int _undoPrependData( StreamImpl *is, int length );
-
void _prependTree( StreamImpl *is, struct ColmTree *tree, int ignore );
+void _prependStream( StreamImpl *in, struct ColmTree *tree );
+int _undoPrependData( StreamImpl *is, int length );
struct ColmTree *_undoPrependTree( StreamImpl *is );
+struct ColmTree *_undoPrependStream( StreamImpl *in );
void _appendData( StreamImpl *in, const char *data, long len );
void _appendTree( StreamImpl *in, struct ColmTree *tree );
void _appendStream( StreamImpl *in, struct ColmTree *tree );
struct ColmTree *_undoAppendData( StreamImpl *in, int length );
-struct ColmTree *_undoAppendStream( StreamImpl *in );
struct ColmTree *_undoAppendTree( StreamImpl *in );
+struct ColmTree *_undoAppendStream( StreamImpl *in );
#ifdef __cplusplus
}
diff --git a/colm/pdarun.c b/colm/pdarun.c
index 648538c3..1a14c43c 100644
--- a/colm/pdarun.c
+++ b/colm/pdarun.c
@@ -168,6 +168,11 @@ void streamPushTree( FsmRun *fsmRun, StreamImpl *is, Tree *tree, int ignore )
is->funcs->prependTree( is, tree, ignore );
}
+void streamPushStream( FsmRun *fsmRun, StreamImpl *is, Tree *tree )
+{
+ is->funcs->prependStream( is, tree );
+}
+
void undoStreamPush( Program *prg, Tree **sp, FsmRun *fsmRun, StreamImpl *is, long length )
{
if ( length < 0 ) {
@@ -1672,7 +1677,7 @@ backup:
void commitFull( Program *prg, Tree **sp, PdaRun *pdaRun, long causeReduce )
{
- debug( REALM_PARSE, "running full commit" );
+ debug( REALM_PARSE, "running full commit\n" );
ParseTree *parseTree = pdaRun->stackTop;
Code *rcode = pdaRun->reverseCode.data + pdaRun->reverseCode.tabLen;
diff --git a/colm/pdarun.h b/colm/pdarun.h
index cf159ead..4b37c5cd 100644
--- a/colm/pdarun.h
+++ b/colm/pdarun.h
@@ -431,6 +431,7 @@ Head *stringAllocPointer( struct ColmProgram *prg, const char *data, long length
void streamPushText( FsmRun *fsmRun, StreamImpl *inputStream, const char *data, long length );
void streamPushTree( FsmRun *fsmRun, StreamImpl *inputStream, Tree *tree, int ignore );
+void streamPushStream( FsmRun *fsmRun, StreamImpl *inputStream, Tree *tree );
void undoStreamPush( struct ColmProgram *prg, Tree **sp, FsmRun *fsmRun, StreamImpl *inputStream, long length );
void undoStreamAppend( struct ColmProgram *prg, Tree **sp, FsmRun *fsmRun, StreamImpl *inputStream, struct ColmTree *tree, long length );
Kid *makeTokenWithData( struct ColmProgram *prg, PdaRun *pdaRun, FsmRun *fsmRun,