summaryrefslogtreecommitdiff
path: root/colm
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2011-12-30 01:16:15 +0000
committerAdrian Thurston <thurston@complang.org>2011-12-30 01:16:15 +0000
commit0212ac36927c953325fd42d881bd21838082ea5b (patch)
treecb4a4e50d3fae0be0cb6bca401ddb742a07f416e /colm
parent63b74beec0dea0beeba7e59db0051c7475492480 (diff)
downloadcolm-0212ac36927c953325fd42d881bd21838082ea5b.tar.gz
Eliminating the rest of the testing functions from the input interface.
refs #342.
Diffstat (limited to 'colm')
-rw-r--r--colm/ctinput.cc37
-rw-r--r--colm/input.c111
-rw-r--r--colm/input.h10
-rw-r--r--colm/pdarun.c26
4 files changed, 9 insertions, 175 deletions
diff --git a/colm/ctinput.cc b/colm/ctinput.cc
index 251f6611..6f34b111 100644
--- a/colm/ctinput.cc
+++ b/colm/ctinput.cc
@@ -37,21 +37,9 @@ SourceFuncs replFuncs;
* Implementation
*/
-int inputStreamStaticIsTree( SourceStream *is )
-{
- return false;
-}
-
-int inputStreamStaticIsIgnore( SourceStream *is )
-{
- return false;
-}
-
extern "C" void initStaticFuncs()
{
memcpy( &staticFuncs, &baseFuncs, sizeof(SourceFuncs) );
- staticFuncs.isTree = &inputStreamStaticIsTree;
- staticFuncs.isIgnore = &inputStreamStaticIsIgnore;
}
/*
@@ -69,11 +57,6 @@ SourceStream *newInputStreamPattern( Pattern *pattern )
return is;
}
-int inputStreamPatternIsLangEl( SourceStream *is )
-{
- return is->patItem != 0 && is->patItem->type == PatternItem::FactorType;
-}
-
int inputStreamPatternShouldFlush( SourceStream *is )
{
return is->patItem == 0 || is->patItem->type == PatternItem::FactorType;
@@ -132,11 +115,6 @@ int inputStreamPatternGetData( SourceStream *is, int skip, char *dest, int lengt
return INPUT_DATA;
}
-int inputStreamPatternIsEof( SourceStream *is, int offset )
-{
- return is->patItem == 0;
-}
-
void inputStreamPatternBackup( SourceStream *is )
{
if ( is->patItem == 0 )
@@ -206,8 +184,6 @@ extern "C" void initPatternFuncs()
patternFuncs.consumeData = &inputStreamPatternConsumeData;
patternFuncs.undoConsumeData = &inputStreamPatternUndoConsumeData;
- patternFuncs.isLangEl = &inputStreamPatternIsLangEl;
- patternFuncs.isEof = &inputStreamPatternIsEof;
patternFuncs.getLangEl = &inputStreamPatternGetLangEl;
patternFuncs.pushBackNamed = &inputStreamPatternPushBackNamed;
}
@@ -228,12 +204,6 @@ SourceStream *newInputStreamRepl( Replacement *replacement )
return is;
}
-int inputStreamReplIsLangEl( SourceStream *is )
-{
- return is->replItem != 0 && ( is->replItem->type == ReplItem::ExprType ||
- is->replItem->type == ReplItem::FactorType );
-}
-
int inputStreamReplShouldFlush( SourceStream *is )
{
return is->replItem == 0 || ( is->replItem->type == ReplItem::ExprType ||
@@ -304,11 +274,6 @@ int inputStreamReplGetData( SourceStream *is, int offset, char *dest, int length
return INPUT_DATA;
}
-int inputStreamReplIsEof( SourceStream *is, int offset )
-{
- return is->replItem == 0;
-}
-
void inputStreamReplBackup( SourceStream *is )
{
if ( is->replItem == 0 )
@@ -361,8 +326,6 @@ extern "C" void initReplFuncs()
{
memcpy( &replFuncs, &staticFuncs, sizeof(SourceFuncs) );
replFuncs.getData = &inputStreamReplGetData;
- replFuncs.isLangEl = &inputStreamReplIsLangEl;
- replFuncs.isEof = &inputStreamReplIsEof;
replFuncs.getLangEl = &inputStreamReplGetLangEl;
replFuncs.pushBackNamed = &inputStreamReplPushBackNamed;
replFuncs.consumeData = &inputStreamReplConsumeData;
diff --git a/colm/input.c b/colm/input.c
index 76aa43c6..bff0d1de 100644
--- a/colm/input.c
+++ b/colm/input.c
@@ -170,39 +170,6 @@ void initInputFuncs()
* Base run-time input streams.
*/
-int inputStreamDynamicIsTree( SourceStream *is )
-{
- if ( is->queue != 0 && is->queue->type == RunBufTokenType )
- return true;
- return false;
-}
-
-int inputStreamDynamicIsIgnore( SourceStream *is )
-{
- if ( is->queue != 0 && is->queue->type == RunBufIgnoreType )
- return true;
- return false;
-}
-
-int inputStreamDynamicIsLangEl( SourceStream *is )
-{
- return false;
-}
-
-int inputStreamDynamicIsEof( SourceStream *is, int offset )
-{
- int isEof = false;
- if ( is->eof ) {
- if ( is->queue == 0 )
- isEof = true;
- else if ( is->queue != 0 && is->queue->offset + offset >= is->queue->length )
- isEof = true;
- }
-
- debug( REALM_INPUT, "is eof: %d\n", (int)isEof );
- return isEof;
-}
-
int inputStreamDynamicGetData( SourceStream *is, int skip, char *dest, int length, int *copied )
{
int ret = 0;
@@ -403,10 +370,6 @@ Tree *inputStreamDynamicUndoAppend( SourceStream *is, int length )
void initDynamicFuncs()
{
memcpy( &dynamicFuncs, &baseFuncs, sizeof(struct SourceFuncs) );
- dynamicFuncs.isTree = &inputStreamDynamicIsTree;
- dynamicFuncs.isIgnore = &inputStreamDynamicIsIgnore;
- dynamicFuncs.isLangEl = &inputStreamDynamicIsLangEl;
- dynamicFuncs.isEof = &inputStreamDynamicIsEof;
dynamicFuncs.getData = &inputStreamDynamicGetData;
dynamicFuncs.consumeData = &inputStreamDynamicConsumeData;
dynamicFuncs.undoConsumeData = &inputStreamDynamicUndoConsumeData;
@@ -537,60 +500,6 @@ static int isSourceStream( InputStream *is )
return false;
}
-
-//dynamicFuncs.isTree = &inputStreamDynamicIsTree;
-int isTree( InputStream *is )
-{
- if ( isSourceStream( is ) ) {
- Stream *stream = (Stream*)is->queue->tree;
- return stream->in->funcs->isTree( stream->in );
- }
- else {
- if ( is->queue != 0 && is->queue->type == RunBufTokenType )
- return true;
- return false;
- }
-}
-
-//dynamicFuncs.isIgnore = &inputStreamDynamicIsIgnore;
-int isIgnore( InputStream *is )
-{
- if ( isSourceStream( is ) ) {
- Stream *stream = (Stream*)is->queue->tree;
- return stream->in->funcs->isIgnore( stream->in );
- }
- else {
- if ( is->queue != 0 && is->queue->type == RunBufIgnoreType )
- return true;
- return false;
- }
-}
-
-//dynamicFuncs.isLangEl = &inputStreamDynamicIsLangEl;
-int isLangEl( InputStream *is )
-{
- if ( isSourceStream( is ) ) {
- Stream *stream = (Stream*)is->queue->tree;
- return stream->in->funcs->isLangEl( stream->in );
- }
- else {
- return false;
- }
-}
-
-//dynamicFuncs.isEof = &inputStreamDynamicIsEof;
-int isEof( InputStream *is, int offset )
-{
- if ( isSourceStream( is ) ) {
- Stream *stream = (Stream*)is->queue->tree;
- return stream->in->funcs->isEof( stream->in, offset );
- }
- else {
- debug( REALM_INPUT, "checking input stream eof\n" );
- return is->queue == 0 && is->eof;
- }
-}
-
void setEof( InputStream *is )
{
debug( REALM_INPUT, "setting EOF in input stream\n" );
@@ -651,6 +560,11 @@ int getData( InputStream *is, int skip, char *dest, int length, int *copied )
break;
}
+ if ( buf->type == RunBufIgnoreType ) {
+ ret = INPUT_IGNORE;
+ break;
+ }
+
int avail = buf->length - buf->offset;
/* Anything available in the current buffer. */
@@ -695,6 +609,9 @@ int getData( InputStream *is, int skip, char *dest, int length, int *copied )
case INPUT_TREE:
debug( REALM_INPUT, "get data: TREE\n" );
break;
+ case INPUT_IGNORE:
+ debug( REALM_INPUT, "get data: IGNORE\n" );
+ break;
case INPUT_LANG_EL:
debug( REALM_INPUT, "get data: LANG_EL\n" );
break;
@@ -744,18 +661,6 @@ int undoConsumeData( InputStream *is, const char *data, int length )
}
}
-int getDataImpl( InputStream *is, char *dest, int length )
-{
- if ( isSourceStream( is ) ) {
- Stream *stream = (Stream*)is->queue->tree;
- return stream->in->funcs->getDataImpl( stream->in, dest, length );
- }
- else {
- /* No source of data, it is all done with RunBuf list appends. */
- return 0;
- }
-}
-
//dynamicFuncs.getTree = &inputStreamDynamicGetTree;
Tree *getTree( InputStream *is )
{
diff --git a/colm/input.h b/colm/input.h
index b87e9a60..ed7bd733 100644
--- a/colm/input.h
+++ b/colm/input.h
@@ -37,6 +37,7 @@ extern "C" {
#define INPUT_EOF 3
#define INPUT_LANG_EL 4
#define INPUT_TREE 5
+#define INPUT_IGNORE 6
/*
* pdaRun <- fsmRun <- stream
@@ -90,10 +91,6 @@ struct SourceFuncs
int (*consumeData)( SourceStream *is, int length );
int (*undoConsumeData)( SourceStream *is, const char *data, int length );
- int (*isTree)( SourceStream *is );
- int (*isIgnore)( SourceStream *is );
- int (*isLangEl)( SourceStream *is );
- int (*isEof)( SourceStream *is, int offset );
int (*getDataImpl)( SourceStream *is, char *dest, int length );
struct ColmTree *(*getTree)( SourceStream *is );
struct LangEl *(*getLangEl)( SourceStream *is, long *bindId, char **data, long *length );
@@ -196,15 +193,10 @@ int getData( InputStream *in, int offset, char *dest, int length, int *copied );
int consumeData( InputStream *in, int length );
int undoConsumeData( InputStream *is, const char *data, int length );
-int isTree( InputStream *in );
-int isIgnore( InputStream *in );
-int isLangEl( InputStream *in );
-int isEof( InputStream *in, int offset );
int tryAgainLater( InputStream *in, int offset );
void setEof( InputStream *is );
void unsetEof( InputStream *is );
void unsetLater( InputStream *is );
-int getDataImpl( InputStream *in, char *dest, int length );
struct ColmTree *getTree( InputStream *in );
struct LangEl *getLangEl( InputStream *in, long *bindId, char **data, long *length );
void pushTree( InputStream *in, struct ColmTree *tree, int ignore );
diff --git a/colm/pdarun.c b/colm/pdarun.c
index 77607a05..c0a1be10 100644
--- a/colm/pdarun.c
+++ b/colm/pdarun.c
@@ -934,37 +934,11 @@ long scanToken( Program *prg, PdaRun *pdaRun, FsmRun *fsmRun, InputStream *input
// /* Check for a named language element or constructed trees. Note that
// * we can do this only when data == de otherwise we get ahead of what's
// * already in the buffer. */
-// if ( isLangEl( inputStream ) ) {
-// breakRunBuf( fsmRun );
-// return SCAN_LANG_EL;
-// }
-// if ( isTree( inputStream ) ) {
-// breakRunBuf( fsmRun );
-// return SCAN_TREE;
-// }
// else if ( isIgnore( inputStream ) ) {
// breakRunBuf( fsmRun );
// return SCAN_IGNORE;
// }
//
-// /* Maybe need eof. */
-// int offset = fsmRun->tokstart != 0 ? fsmRun->p - fsmRun->tokstart : 0 ;
-// if ( isEof( inputStream, offset ) ) {
-// if ( fsmRun->tokstart != 0 ) {
-// /* If a token has been started, but not finshed
-// * this is an error. */
-// fsmRun->cs = fsmRun->tables->errorState;
-// return SCAN_ERROR;
-// }
-// else {
-// return SCAN_EOF;
-// }
-// }
-// /* Maybe need to pause parsing until more data is inserted into the
-// * input inputStream. */
-// if ( tryAgainLater( inputStream, offset ) )
-// return SCAN_TRY_AGAIN_LATER;
-
/* There may be space left in the current buffer. If not then we need
* to make some. */
long space = fsmRun->runBuf->data + FSM_BUFSIZE - fsmRun->pe;