summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2018-07-02 15:22:08 +0700
committerAdrian Thurston <thurston@colm.net>2018-07-02 15:22:08 +0700
commite87efd2f55958dc4f915890091ecf436d33d8c4f (patch)
tree39e8c902ace9bc929469892a7251b9b83e2f48b7
parent3ce0e39214953549c3da7bc6125afb364b4dd310 (diff)
downloadcolm-e87efd2f55958dc4f915890091ecf436d33d8c4f.tar.gz
use stream_impl_ct directly
Don't put it behind a stream_impl_seq
-rw-r--r--src/compiler.cc10
-rw-r--r--src/ctinput.cc68
-rw-r--r--src/input.c2
3 files changed, 62 insertions, 18 deletions
diff --git a/src/compiler.cc b/src/compiler.cc
index 1df9cda2..79e36627 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -994,18 +994,10 @@ void Compiler::initEmptyScanners()
pda_run *Compiler::parsePattern( program_t *prg, tree_t **sp, const InputLoc &loc,
int parserId, struct stream_impl *sourceStream )
{
- struct stream_impl *in = colm_impl_new_generic( strdup("<internal>") );
-
struct pda_run *pdaRun = new pda_run;
colm_pda_init( prg, pdaRun, pdaTables, parserId, 0, false, 0, false );
- stream_t *stream = colm_stream_new_struct( prg );
- stream->impl = sourceStream;
-
- in->funcs->append_stream( prg, in, stream );
- in->funcs->set_eof( prg, in );
-
- long pcr = colm_parse_loop( prg, sp, pdaRun, in, PCR_START );
+ long pcr = colm_parse_loop( prg, sp, pdaRun, sourceStream, PCR_START );
assert( pcr == PCR_DONE );
if ( pdaRun->parse_error ) {
cerr << ( loc.fileName != 0 ? loc.fileName : "<input>" ) <<
diff --git a/src/ctinput.cc b/src/ctinput.cc
index 77b4ec9c..cbc62b29 100644
--- a/src/ctinput.cc
+++ b/src/ctinput.cc
@@ -54,6 +54,7 @@ struct stream_impl_ct
struct ConsItem *cons_item;
char eof_sent;
+ char eof;
int offset;
};
@@ -118,7 +119,7 @@ int inputStreamPatternGetParseBlock( struct colm_program *prg, struct stream_imp
while ( true ) {
if ( buf == 0 )
- return INPUT_EOD;
+ return INPUT_EOF;
if ( buf->form == PatternItem::TypeRefForm )
return INPUT_LANG_EL;
@@ -247,6 +248,46 @@ int inputStreamPatternUndoConsumeData( struct colm_program *prg, struct stream_i
return length;
}
+void pat_stream_set_eof( struct colm_program *prg, struct stream_impl_ct *si )
+{
+ si->eof = true;
+}
+
+void pat_stream_unset_eof( struct colm_program *prg, struct stream_impl_ct *si )
+{
+// if ( is_source_stream( si ) ) {
+// struct stream_impl_data *sid = (struct stream_impl_data*)si->queue->si;
+// sid->eof = false;
+// }
+// else {
+ si->eof = false;
+// }
+}
+
+void repl_stream_set_eof( struct colm_program *prg, struct stream_impl_ct *si )
+{
+ si->eof = true;
+}
+
+void repl_stream_unset_eof( struct colm_program *prg, struct stream_impl_ct *si )
+{
+// if ( is_source_stream( si ) ) {
+// struct stream_impl_data *sid = (struct stream_impl_data*)si->queue->si;
+// sid->eof = false;
+// }
+// else {
+ si->eof = false;
+// }
+}
+
+void pat_transfer_loc_seq( struct colm_program *prg, location_t *loc, struct stream_impl_ct *ss )
+{
+ loc->name = ss->name;
+ loc->line = ss->line;
+ loc->column = ss->column;
+ loc->byte = ss->byte;
+}
+
stream_funcs_ct patternFuncs =
{
&inputStreamPatternGetParseBlock,
@@ -260,9 +301,12 @@ stream_funcs_ct patternFuncs =
/* unused */ 0,
&inputStreamPatternUndoConsumeLangEl,
- 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0,
+ 0,
+
+ &pat_stream_set_eof, &pat_stream_unset_eof,
+
+ 0, 0, 0, 0, 0, 0, /* prepend. */
+ 0, 0, 0, 0, 0, 0, /* append. */
&inputStreamPatternDestructor,
@@ -270,6 +314,8 @@ stream_funcs_ct patternFuncs =
&inputStreamGetEofSent,
&inputStreamSetEofSent,
+
+ &pat_transfer_loc_seq,
};
@@ -327,7 +373,7 @@ int inputStreamConsGetParseBlock( struct colm_program *prg, struct stream_impl_c
while ( true ) {
if ( buf == 0 )
- return INPUT_EOD;
+ return INPUT_EOF;
if ( buf->type == ConsItem::ExprType || buf->type == ConsItem::LiteralType )
return INPUT_LANG_EL;
@@ -416,6 +462,7 @@ void inputStreamConsUndoConsumeLangEl( struct colm_program *prg, struct stream_i
ss->offset = ss->cons_item->data.length();
}
+
int inputStreamConsConsumeData( struct colm_program *prg, struct stream_impl_ct *ss, int length, location_t *loc )
{
int consumed = 0;
@@ -482,9 +529,12 @@ stream_funcs_ct replFuncs =
/* unused. */ 0,
&inputStreamConsUndoConsumeLangEl,
- 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0,
+ 0,
+
+ &repl_stream_set_eof, &repl_stream_unset_eof,
+
+ 0, 0, 0, 0, 0, 0, /* prepend. */
+ 0, 0, 0, 0, 0, 0, /* append. */
&inputStreamConsDestructor,
@@ -492,6 +542,8 @@ stream_funcs_ct replFuncs =
&inputStreamGetEofSent,
&inputStreamSetEofSent,
+
+ &pat_transfer_loc_seq,
};
void pushBinding( pda_run *pdaRun, parse_tree_t *parseTree )
diff --git a/src/input.c b/src/input.c
index 27b033ab..dcead096 100644
--- a/src/input.c
+++ b/src/input.c
@@ -115,7 +115,7 @@ static void default_loc( location_t *loc )
loc->byte = 1;
}
-static void transfer_loc_seq( struct colm_program *prg, location_t *loc, struct stream_impl_seq *ss )
+void transfer_loc_seq( struct colm_program *prg, location_t *loc, struct stream_impl_seq *ss )
{
loc->name = ss->name;
loc->line = ss->line;