diff options
author | Adrian Thurston <thurston@complang.org> | 2012-09-08 15:24:34 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2012-09-08 15:24:34 -0400 |
commit | 78ccb5b0f9fc62b0a893bc8c2adbdf779ad438ae (patch) | |
tree | 9783449e939d1a6a5c26eadc5a0e39128662978c | |
parent | c8bb762a52a9363e9eca92c788878fc82a29ed6d (diff) | |
download | colm-78ccb5b0f9fc62b0a893bc8c2adbdf779ad438ae.tar.gz |
store the parse error in PdaRun, make it accessible with member on parser type
Now that the parse statement returns a parser instead of the parsed tree it
makes sense to store the parse error in the parser and make it accessible with
Parser.error member.
-rw-r--r-- | colm/bytecode.c | 10 | ||||
-rw-r--r-- | colm/bytecode.h | 1 | ||||
-rw-r--r-- | colm/parsedata.h | 2 | ||||
-rw-r--r-- | colm/pdarun.c | 8 | ||||
-rw-r--r-- | colm/pdarun.h | 2 | ||||
-rw-r--r-- | colm/program.c | 1 | ||||
-rw-r--r-- | colm/program.h | 3 | ||||
-rw-r--r-- | colm/synthesis.cc | 16 | ||||
-rw-r--r-- | colm/tree.c | 3 | ||||
-rw-r--r-- | test/export1.lm | 4 | ||||
-rw-r--r-- | test/lookup1.lm | 2 | ||||
-rw-r--r-- | test/multiregion2.lm | 2 | ||||
-rw-r--r-- | test/repeat2.lm | 2 |
13 files changed, 25 insertions, 31 deletions
diff --git a/colm/bytecode.c b/colm/bytecode.c index 4b271b78..34b3f622 100644 --- a/colm/bytecode.c +++ b/colm/bytecode.c @@ -3465,16 +3465,6 @@ again: treeDownref( prg, sp, in ); break; } - case IN_ERROR: { - debug( REALM_BYTECODE, "IN_ERROR\n" ); - - /* Pop the global. */ - Tree *global = vm_pop(); - treeDownref( prg, sp, global ); - treeUpref( prg->lastParseError ); - vm_push( prg->lastParseError ); - break; - } case IN_OPEN_FILE: { debug( REALM_BYTECODE, "IN_OPEN_FILE\n" ); diff --git a/colm/bytecode.h b/colm/bytecode.h index f3661230..376b76f5 100644 --- a/colm/bytecode.h +++ b/colm/bytecode.h @@ -263,7 +263,6 @@ typedef unsigned char uchar; #define IN_TO_UPPER 0xb9 #define IN_TO_LOWER 0xba #define IN_EXIT 0xbb -#define IN_ERROR 0xbc #define IN_LOAD_PARSER_R 0xbd #define IN_LOAD_PARSER_WV 0xbe diff --git a/colm/parsedata.h b/colm/parsedata.h index f550ca77..164cfea8 100644 --- a/colm/parsedata.h +++ b/colm/parsedata.h @@ -817,7 +817,7 @@ struct Compiler void initListFields( GenericType *gen ); void initListFunctions( GenericType *gen ); void initVectorFunctions( GenericType *gen ); - void initParserField( GenericType *gen, const char *name, int offset ); + void initParserField( GenericType *gen, const char *name, int offset, TypeRef *typeRef ); void initParserFunctions( GenericType *gen ); void initParserFields( GenericType *gen ); void initCtxField( GenericType *gen ); diff --git a/colm/pdarun.c b/colm/pdarun.c index c521b52b..93e2f2af 100644 --- a/colm/pdarun.c +++ b/colm/pdarun.c @@ -532,9 +532,9 @@ static void reportParseError( Program *prg, Tree **sp, PdaRun *pdaRun ) } Tree *tree = constructString( prg, errorHead ); - treeDownref( prg, sp, prg->lastParseError ); - prg->lastParseError = tree; - treeUpref( prg->lastParseError ); + treeDownref( prg, sp, pdaRun->parseErrorText ); + pdaRun->parseErrorText = tree; + treeUpref( pdaRun->parseErrorText ); } static void attachRightIgnore( Program *prg, Tree **sp, PdaRun *pdaRun, ParseTree *parseTree ) @@ -1484,6 +1484,8 @@ void clearPdaRun( Program *prg, Tree **sp, PdaRun *pdaRun ) rcodeDownrefAll( prg, sp, &pdaRun->reverseCode ); rtCodeVectEmpty( &pdaRun->reverseCode ); rtCodeVectEmpty( &pdaRun->rcodeCollect ); + + treeDownref( prg, sp, pdaRun->parseErrorText ); } int isParserStopFinished( PdaRun *pdaRun ) diff --git a/colm/pdarun.h b/colm/pdarun.h index 0c877f7e..d402a83f 100644 --- a/colm/pdarun.h +++ b/colm/pdarun.h @@ -342,6 +342,8 @@ typedef struct _PdaRun Code *code; int rcBlockCount; + + Tree *parseErrorText; } PdaRun; void rtCodeVectReplace( RtCodeVect *vect, long pos, const Code *val, long len ); diff --git a/colm/program.c b/colm/program.c index 079a3fd7..d1f8893c 100644 --- a/colm/program.c +++ b/colm/program.c @@ -255,7 +255,6 @@ int colmDeleteProgram( Program *prg ) int exitStatus = prg->exitStatus; treeDownref( prg, sp, prg->returnVal ); - treeDownref( prg, sp, prg->lastParseError ); clearGlobal( prg, sp ); /* Clear the heap. */ diff --git a/colm/program.h b/colm/program.h index aec024ae..1f593364 100644 --- a/colm/program.h +++ b/colm/program.h @@ -132,9 +132,6 @@ typedef struct ColmProgram /* Returned from the main line. Should have exports instead. */ Tree *returnVal; - - /* The most recent parse error. Should be returned from the parsing function. */ - Tree *lastParseError; } Program; #endif diff --git a/colm/synthesis.cc b/colm/synthesis.cc index 988fcaf2..9d18139f 100644 --- a/colm/synthesis.cc +++ b/colm/synthesis.cc @@ -2939,10 +2939,9 @@ void Compiler::initParserFunctions( GenericType *gen ) IN_PARSE_FINISH_WV, IN_PARSE_FINISH_WC, true ); } -void Compiler::initParserField( GenericType *gen, const char *name, int offset ) +void Compiler::initParserField( GenericType *gen, const char *name, int offset, TypeRef *typeRef ) { /* Make the type ref and create the field. */ - TypeRef *typeRef = TypeRef::cons( InputLoc(), gen->utArg ); ObjField *el = new ObjField( InputLoc(), typeRef, name ); el->inGetR = IN_GET_PARSER_MEM_R; @@ -2989,8 +2988,14 @@ void Compiler::initParserFields( GenericType *gen ) LangEl *langEl = gen->utArg->langEl; if ( langEl->contextIn != 0 ) initCtxField( gen ); - - initParserField( gen, "tree", 0 ); + + TypeRef *typeRef; + + typeRef = TypeRef::cons( InputLoc(), gen->utArg ); + initParserField( gen, "tree", 0, typeRef ); + + typeRef = TypeRef::cons( InputLoc(), uniqueTypeStr ); + initParserField( gen, "error", 1, typeRef ); } void Compiler::initGenericTypes() @@ -3355,9 +3360,6 @@ void Compiler::initGlobalFunctions() method = initFunction( uniqueTypeInt, globalObjectDef, "exit", IN_EXIT, IN_EXIT, uniqueTypeInt, true ); - method = initFunction( uniqueTypeStr, globalObjectDef, "error", - IN_ERROR, IN_ERROR, true ); - addStdin(); addStdout(); addStderr(); diff --git a/colm/tree.c b/colm/tree.c index 5cdbf755..1d76e9b2 100644 --- a/colm/tree.c +++ b/colm/tree.c @@ -1593,6 +1593,9 @@ Tree *getParserMem( Parser *parser, Word field ) case 0: result = parser->result; break; + case 1: + result = parser->pdaRun->parseErrorText; + break; default: assert( false ); break; diff --git a/test/export1.lm b/test/export1.lm index 653f7dcc..e7e8b400 100644 --- a/test/export1.lm +++ b/test/export1.lm @@ -10,5 +10,5 @@ def start export Start: start export Error: str -parse start[ stdin ] -Error = error() +parse P: start[ stdin ] +Error = P.error diff --git a/test/lookup1.lm b/test/lookup1.lm index 586af7b5..f1f2ead2 100644 --- a/test/lookup1.lm +++ b/test/lookup1.lm @@ -2190,7 +2190,7 @@ Lookup.declarationData.push( construct lookup::declaration_data( 0 0 0 ) [] ) parse SP: lookup::start( Lookup )[ stdin ] S: lookup::start = SP.tree if ! S { - print( error() ) + print( SP.error ) exit( 1 ) } diff --git a/test/multiregion2.lm b/test/multiregion2.lm index 815783c1..c2a4312b 100644 --- a/test/multiregion2.lm +++ b/test/multiregion2.lm @@ -73,7 +73,7 @@ parse RP: request*[ stdin ] R: request* = RP.tree if !R { - print( error() ) + print( RP.error ) exit( 1 ) } diff --git a/test/repeat2.lm b/test/repeat2.lm index e2bce933..60c7a0d1 100644 --- a/test/repeat2.lm +++ b/test/repeat2.lm @@ -243,7 +243,7 @@ def start parse Start: start[ stdin ] if ( ! Start.tree ) { - print( error() '\n' ) + print( Start.error '\n' ) exit( 1 ) } |