summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2018-07-07 08:41:27 +0800
committerAdrian Thurston <thurston@colm.net>2018-07-07 08:41:27 +0800
commit13627232094ba6b31937448f011553f44b1f8519 (patch)
tree72f6c378dc99f386ffc7d70e6be2deae776facba
parent975d403f75b2dfa2b8de57021614759ce5ae9d3f (diff)
downloadcolm-13627232094ba6b31937448f011553f44b1f8519.tar.gz
some improvements to the the stream funcs
-rw-r--r--src/ctinput.cc82
-rw-r--r--src/input.c80
-rw-r--r--src/input.h26
3 files changed, 88 insertions, 100 deletions
diff --git a/src/ctinput.cc b/src/ctinput.cc
index 8f8ae58f..28d0d30a 100644
--- a/src/ctinput.cc
+++ b/src/ctinput.cc
@@ -87,19 +87,6 @@ struct stream_impl *colm_impl_new_pat( char *name, Pattern *pattern )
return (struct stream_impl*) ss;
}
-LangEl *pat_get_lang_el( struct colm_program *prg, struct stream_impl_ct *ss, long *bindId,
- char **data, long *length )
-{
- LangEl *klangEl = ss->pat_item->prodEl->langEl;
- *bindId = ss->pat_item->bindId;
- *data = 0;
- *length = 0;
-
- ss->pat_item = ss->pat_item->next;
- ss->offset = 0;
- return klangEl;
-}
-
int pat_get_parse_block( struct colm_program *prg, struct stream_impl_ct *ss, int *pskip,
char **pdp, int *copied )
{
@@ -148,6 +135,7 @@ int pat_get_parse_block( struct colm_program *prg, struct stream_impl_ct *ss, in
return INPUT_DATA;
}
+
int pat_get_data( struct colm_program *prg, struct stream_impl_ct *ss, char *dest, int length )
{
int copied = 0;
@@ -193,12 +181,6 @@ void pat_backup( struct stream_impl_ct *ss )
ss->pat_item = ss->pat_item->prev;
}
-void pat_undo_consume_lang_el( struct colm_program *prg, struct stream_impl_ct *ss )
-{
- pat_backup( ss );
- ss->offset = ss->pat_item->data.length();
-}
-
int pat_consume_data( struct colm_program *prg, struct stream_impl_ct *ss, int length, location_t *loc )
{
//debug( REALM_INPUT, "consuming %ld bytes\n", length );
@@ -239,6 +221,25 @@ int pat_undo_consume_data( struct colm_program *prg, struct stream_impl_ct *ss,
return length;
}
+LangEl *pat_consume_lang_el( struct colm_program *prg, struct stream_impl_ct *ss, long *bindId,
+ char **data, long *length )
+{
+ LangEl *klangEl = ss->pat_item->prodEl->langEl;
+ *bindId = ss->pat_item->bindId;
+ *data = 0;
+ *length = 0;
+
+ ss->pat_item = ss->pat_item->next;
+ ss->offset = 0;
+ return klangEl;
+}
+
+void pat_undo_consume_lang_el( struct colm_program *prg, struct stream_impl_ct *ss )
+{
+ pat_backup( ss );
+ ss->offset = ss->pat_item->data.length();
+}
+
void ct_stream_set_eof( struct colm_program *prg, struct stream_impl_ct *si )
{
si->eof = true;
@@ -262,38 +263,37 @@ stream_funcs_ct pat_funcs =
&pat_get_parse_block,
&pat_get_data,
+ 0, /* get_data_source */
+
&pat_consume_data,
&pat_undo_consume_data,
0, /* consume_tree */
0, /* undo_consume_tree */
- &pat_get_lang_el,
+ &pat_consume_lang_el,
&pat_undo_consume_lang_el,
-
- 0, /* get_data_source */
-
- &ct_stream_set_eof, &ct_stream_unset_eof,
0, 0, 0, 0, 0, 0, /* prepend funcs. */
0, 0, 0, 0, 0, 0, /* append funcs */
- &ct_destructor,
+ &ct_stream_set_eof,
+ &ct_stream_unset_eof,
+ &ct_get_eof_sent,
+ &ct_set_eof_sent,
+ &ct_transfer_loc_seq,
0, /* get_collect */
0, /* flush_stream */
0, /* close_stream */
0, /* print_tree */
- &ct_get_eof_sent,
- &ct_set_eof_sent,
-
- &ct_transfer_loc_seq,
+ &ct_destructor,
};
/*
- * Constructor
+ * Replacements
*/
struct stream_impl *colm_impl_new_cons( char *name, Constructor *constructor )
@@ -306,7 +306,7 @@ struct stream_impl *colm_impl_new_cons( char *name, Constructor *constructor )
return (struct stream_impl*)ss;
}
-LangEl *repl_get_lang_el( struct colm_program *prg, struct stream_impl_ct *ss, long *bindId, char **data, long *length )
+LangEl *repl_consume_lang_el( struct colm_program *prg, struct stream_impl_ct *ss, long *bindId, char **data, long *length )
{
LangEl *klangEl = ss->cons_item->type == ConsItem::ExprType ?
ss->cons_item->langEl : ss->cons_item->prodEl->langEl;
@@ -490,34 +490,32 @@ stream_funcs_ct repl_funcs =
&repl_get_parse_block,
&repl_get_data,
+ 0, /* get_data_source */
+
&repl_consume_data,
&repl_undo_consume_data,
0, /* consume_tree */
0, /* undo_consume_tree. */
- &repl_get_lang_el,
+ &repl_consume_lang_el,
&repl_undo_consume_lang_el,
- 0, /* get_data_source */
-
- &ct_stream_set_eof,
- &ct_stream_unset_eof,
-
0, 0, 0, 0, 0, 0, /* prepend. */
0, 0, 0, 0, 0, 0, /* append. */
- &ct_destructor,
+ &ct_stream_set_eof,
+ &ct_stream_unset_eof,
+ &ct_get_eof_sent,
+ &ct_set_eof_sent,
+ &ct_transfer_loc_seq,
0, /* get_collect */
0, /* flush_stream */
0, /* close_stream */
0, /* print_tree */
- &ct_get_eof_sent,
- &ct_set_eof_sent,
-
- &ct_transfer_loc_seq,
+ &ct_destructor,
};
void pushBinding( pda_run *pdaRun, parse_tree_t *parseTree )
diff --git a/src/input.c b/src/input.c
index a52f7233..a20cd8f2 100644
--- a/src/input.c
+++ b/src/input.c
@@ -565,7 +565,6 @@ static int text_get_data_source( struct colm_program *prg, struct stream_impl_da
return take;
}
-
/*
* StreamImpl struct, this wraps the list of input streams.
*/
@@ -1126,59 +1125,54 @@ static tree_t *stream_undo_append_stream( struct colm_program *prg, struct strea
struct stream_funcs_seq stream_funcs =
{
- .get_parse_block = &stream_get_parse_block,
- .get_data = &stream_get_data,
-
- /*
- * Consume.
- */
- .consume_data = &stream_consume_data,
- .undo_consume_data = &stream_undo_consume_data,
+ &stream_get_parse_block,
+ &stream_get_data,
+ 0 /* get_data_source */,
- .consume_tree = &stream_consume_tree,
- .undo_consume_tree = &stream_undo_consume_tree,
+ /* Consume. */
+ &stream_consume_data,
+ &stream_undo_consume_data,
- .consume_lang_el = &stream_consume_lang_el,
- .undo_consume_lang_el = &stream_undo_consume_lang_el,
+ &stream_consume_tree,
+ &stream_undo_consume_tree,
+ &stream_consume_lang_el,
+ &stream_undo_consume_lang_el,
- /*
- * Prepend
- */
- .prepend_data = &stream_prepend_data,
- .undo_prepend_data = &stream_undo_prepend_data,
+ /* Prepend */
+ &stream_prepend_data,
+ &stream_undo_prepend_data,
- .prepend_tree = &stream_prepend_tree,
- .undo_prepend_tree = &stream_undo_prepend_tree,
+ &stream_prepend_tree,
+ &stream_undo_prepend_tree,
- .prepend_stream = &stream_prepend_stream,
- .undo_prepend_stream = &stream_undo_prepend_stream,
+ &stream_prepend_stream,
+ &stream_undo_prepend_stream,
- /*
- * Append
- */
- .append_data = &stream_append_data,
- .undo_append_data = &stream_undo_append_data,
+ /* Append */
+ &stream_append_data,
+ &stream_undo_append_data,
- .append_tree = &stream_append_tree,
- .undo_append_tree = &stream_undo_append_tree,
+ &stream_append_tree,
+ &stream_undo_append_tree,
- .append_stream = &stream_append_stream,
- .undo_append_stream = &stream_undo_append_stream,
-
- .destructor = &stream_destructor,
- .get_collect = &stream_get_collect,
- .flush_stream = &stream_flush_stream,
- .close_stream = &stream_close_stream,
- .print_tree = &stream_print_tree,
+ &stream_append_stream,
+ &stream_undo_append_stream,
/* EOF */
- .set_eof = &stream_set_eof,
- .unset_eof = &stream_unset_eof,
- .get_eof_sent = &stream_get_eof_sent,
- .set_eof_sent = &stream_set_eof_sent,
-
- .transfer_loc = &transfer_loc_seq,
+ &stream_set_eof,
+ &stream_unset_eof,
+ &stream_get_eof_sent,
+ &stream_set_eof_sent,
+
+ /* Util. */
+ &transfer_loc_seq,
+ &stream_get_collect,
+ &stream_flush_stream,
+ &stream_close_stream,
+ &stream_print_tree,
+
+ &stream_destructor,
};
struct stream_funcs_data file_funcs =
diff --git a/src/input.h b/src/input.h
index ac727c81..b1577464 100644
--- a/src/input.h
+++ b/src/input.h
@@ -84,40 +84,36 @@ struct stream_funcs \
{ \
int (*get_parse_block)( struct colm_program *prg, struct stream_impl *si, int *pskip, char **pdp, int *copied ); \
int (*get_data)( struct colm_program *prg, struct stream_impl *si, char *dest, int length ); \
-\
+ int (*get_data_source)( struct colm_program *prg, struct stream_impl *si, char *dest, int length ); \
int (*consume_data)( struct colm_program *prg, struct stream_impl *si, int length, struct colm_location *loc ); \
int (*undo_consume_data)( struct colm_program *prg, struct stream_impl *si, const char *data, int length ); \
-\
struct colm_tree *(*consume_tree)( struct colm_program *prg, struct stream_impl *si ); \
void (*undo_consume_tree)( struct colm_program *prg, struct stream_impl *si, struct colm_tree *tree, int ignore ); \
-\
struct LangEl *(*consume_lang_el)( struct colm_program *prg, struct stream_impl *si, long *bind_id, char **data, long *length ); \
void (*undo_consume_lang_el)( struct colm_program *prg, struct stream_impl *si ); \
-\
- int (*get_data_source)( struct colm_program *prg, struct stream_impl *si, char *dest, int length ); \
- void (*set_eof)( struct colm_program *prg, struct stream_impl *si ); \
- void (*unset_eof)( struct colm_program *prg, struct stream_impl *si ); \
void (*prepend_data)( struct colm_program *prg, struct stream_impl *si, const char *data, long len ); \
- void (*prepend_tree)( struct colm_program *prg, struct stream_impl *si, struct colm_tree *tree, int ignore ); \
- void (*prepend_stream)( struct colm_program *prg, struct stream_impl *si, struct colm_stream *stream ); \
int (*undo_prepend_data)( struct colm_program *prg, struct stream_impl *si, int length ); \
+ void (*prepend_tree)( struct colm_program *prg, struct stream_impl *si, struct colm_tree *tree, int ignore ); \
struct colm_tree *(*undo_prepend_tree)( struct colm_program *prg, struct stream_impl *si ); \
+ void (*prepend_stream)( struct colm_program *prg, struct stream_impl *si, struct colm_stream *stream ); \
struct colm_tree *(*undo_prepend_stream)( struct colm_program *prg, struct stream_impl *si ); \
void (*append_data)( struct colm_program *prg, struct stream_impl *si, const char *data, long len ); \
- void (*append_tree)( struct colm_program *prg, struct stream_impl *si, struct colm_tree *tree ); \
- void (*append_stream)( struct colm_program *prg, struct stream_impl *si, struct colm_stream *stream ); \
struct colm_tree *(*undo_append_data)( struct colm_program *prg, struct stream_impl *si, int length ); \
+ void (*append_tree)( struct colm_program *prg, struct stream_impl *si, struct colm_tree *tree ); \
struct colm_tree *(*undo_append_tree)( struct colm_program *prg, struct stream_impl *si ); \
+ void (*append_stream)( struct colm_program *prg, struct stream_impl *si, struct colm_stream *stream ); \
struct colm_tree *(*undo_append_stream)( struct colm_program *prg, struct stream_impl *si ); \
- void (*destructor)( struct colm_program *prg, struct colm_tree **sp, struct stream_impl *si ); \
+ void (*set_eof)( struct colm_program *prg, struct stream_impl *si ); \
+ void (*unset_eof)( struct colm_program *prg, struct stream_impl *si ); \
+ char (*get_eof_sent)( struct colm_program *prg, struct stream_impl *si ); \
+ void (*set_eof_sent)( struct colm_program *prg, struct stream_impl *si, char eof_sent ); \
+ void (*transfer_loc)( struct colm_program *prg, struct colm_location *loc, struct stream_impl *si ); \
struct colm_str_collect *(*get_collect)( struct colm_program *prg, struct stream_impl *si ); \
void (*flush_stream)( struct colm_program *prg, struct stream_impl *si ); \
void (*close_stream)( struct colm_program *prg, struct stream_impl *si ); \
void (*print_tree)( struct colm_program *prg, struct colm_tree **sp, \
struct stream_impl *impl, struct colm_tree *tree, int trim ); \
- char (*get_eof_sent)( struct colm_program *prg, struct stream_impl *si ); \
- void (*set_eof_sent)( struct colm_program *prg, struct stream_impl *si, char eof_sent ); \
- void (*transfer_loc)( struct colm_program *prg, struct colm_location *loc, struct stream_impl *si ); \
+ void (*destructor)( struct colm_program *prg, struct colm_tree **sp, struct stream_impl *si ); \
}
DEF_STREAM_FUNCS( stream_funcs, stream_impl );