diff options
author | Adrian Thurston <thurston@complang.org> | 2012-01-02 20:48:25 +0000 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2012-01-02 20:48:25 +0000 |
commit | 6cbcc51e9a2e911584340fed83c635655407044f (patch) | |
tree | 6139ec63207fc74f01b1251f20e06f3571748f23 | |
parent | 38e5314851fba1e548ea687519044644a8941879 (diff) | |
download | colm-6cbcc51e9a2e911584340fed83c635655407044f.tar.gz |
Added some more attaching/detaching code in the input stream functions.
Fixed the rubyhere test case. It cannot pull rest of line off stdin directly
because the data may be on the input stream.
-rw-r--r-- | colm/bytecode.c | 6 | ||||
-rw-r--r-- | colm/input.c | 26 | ||||
-rw-r--r-- | test/rubyhere.lm | 4 |
3 files changed, 27 insertions, 9 deletions
diff --git a/colm/bytecode.c b/colm/bytecode.c index a3313b58..6184f631 100644 --- a/colm/bytecode.c +++ b/colm/bytecode.c @@ -2098,10 +2098,10 @@ again: case IN_SET_ACCUM_CTX_WC: { debug( REALM_BYTECODE, "IN_SET_ACCUM_CTX_WC\n" ); - Tree *obj = vm_pop(); + Tree *parser = vm_pop(); Tree *val = vm_pop(); - parserSetContext( prg, sp, (Parser*)obj, val ); - treeDownref( prg, sp, obj ); + parserSetContext( prg, sp, (Parser*)parser, val ); + treeDownref( prg, sp, parser ); break; } diff --git a/colm/input.c b/colm/input.c index a4deb06c..82902dfb 100644 --- a/colm/input.c +++ b/colm/input.c @@ -634,6 +634,9 @@ void undoConsumeLangEl( InputStream *is ) void prependData( InputStream *is, const char *data, long length ) { + if ( is->attached1 != 0 ) + detachInput1( is->attached1, 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. */ @@ -648,6 +651,9 @@ void prependData( InputStream *is, const char *data, long length ) int undoPrependData( InputStream *is, int length ) { + if ( is->attached1 != 0 ) + detachInput1( is->attached1, is ); + debug( REALM_INPUT, "consuming %d bytes\n", length ); int consumed = 0; @@ -708,6 +714,9 @@ void prependTree( InputStream *is, Tree *tree, int ignore ) Tree *undoPrependTree( InputStream *is ) { + if ( is->attached1 != 0 ) + detachInput1( is->attached1, is ); + while ( is->queue != 0 && is->queue->type == RunBufDataType && is->queue->offset == is->queue->length ) { RunBuf *runBuf = inputStreamPopHead( is ); free( runBuf ); @@ -745,6 +754,9 @@ void appendData( InputStream *is, const char *data, long len ) Tree *undoAppendData( InputStream *is, int length ) { + if ( is->attached1 != 0 ) + detachInput1( is->attached1, is ); + int consumed = 0; /* Move over skip bytes. */ @@ -802,17 +814,23 @@ void appendStream( InputStream *in, struct ColmTree *tree ) ad->length = 0; } -Tree *undoAppendStream( InputStream *in ) +Tree *undoAppendStream( InputStream *is ) { - RunBuf *runBuf = inputStreamPopTail( in ); + if ( is->attached1 != 0 ) + detachInput1( is->attached1, is ); + + RunBuf *runBuf = inputStreamPopTail( is ); Tree *tree = runBuf->tree; free( runBuf ); return tree; } -Tree *undoAppendTree( InputStream *in ) +Tree *undoAppendTree( InputStream *is ) { - RunBuf *runBuf = inputStreamPopTail( in ); + if ( is->attached1 != 0 ) + detachInput1( is->attached1, is ); + + RunBuf *runBuf = inputStreamPopTail( is ); Tree *tree = runBuf->tree; free( runBuf ); return tree; diff --git a/test/rubyhere.lm b/test/rubyhere.lm index c3a5054a..37004aaa 100644 --- a/test/rubyhere.lm +++ b/test/rubyhere.lm @@ -24,10 +24,10 @@ lex here_start HereId = input.pull( match_length ) # Get the data up to the rest of the line. - parse_stop ROL: rest_of_line( stdin ) + parse_stop ROL: rest_of_line( input ) # Parse the heredoc data. - parse_stop HereData: here_data( stdin ) + parse_stop HereData: here_data( input ) # Push the rest-of-line data back to the input stream. input.push( $ROL ) |