diff options
author | Adrian Thurston <thurston@complang.org> | 2012-07-15 21:33:52 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2012-07-15 21:33:52 -0400 |
commit | db03a8019692eac96f33890e5a7a775606f16263 (patch) | |
tree | 90436136c46f39ad8ef42739145da0441213f291 /src/lmparse.kl | |
parent | a44805dbfcfd7707fc10ca23fda0aa439b350888 (diff) | |
download | colm-db03a8019692eac96f33890e5a7a775606f16263.tar.gz |
a new parse statement syntax
Added a parse statement constructs the parser, sends some text in the style of
the send statement, then returns the parser. More can be sent. When done finish
is called. The goal here is to eliminate the parse statements that return the
parsed tree because there is no way to get the parse error. The parser is
immediately destroyed.
Diffstat (limited to 'src/lmparse.kl')
-rw-r--r-- | src/lmparse.kl | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/lmparse.kl b/src/lmparse.kl index cd8f9255..9f46de95 100644 --- a/src/lmparse.kl +++ b/src/lmparse.kl @@ -1857,6 +1857,45 @@ code_factor: pd->curLocalFrame->insertField( $2->objField->name, $2->objField ); } }; +code_factor: + KW_Parse opt_capture type_ref opt_field_init accumulate + final { + Namespace *nspace = namespaceStack.top(); + TokenRegion *region = regionStack.top(); + + ReplItemList *emptyReplItemList = new ReplItemList; + + Replacement *replacement = Replacement::cons( $1->loc, nspace, region, + emptyReplItemList, pd->nextPatReplId++ ); + pd->replList.append( replacement ); + + LangVarRef *varRef = 0; + if ( $2->objField != 0 ) + varRef = new LangVarRef( $2->objField->loc, new QualItemVect, $2->objField->name ); + + NamespaceQual *nspaceQual = new NamespaceQual( + namespaceStack.top(), regionStack.top() ); + TypeRef *parserTypeRef = TypeRef::cons( TypeRef::Parser, + InputLoc(), nspaceQual, $3->typeRef, 0 ); + + ParserText *parserText = ParserText::cons( $2->loc, nspace, region, replItemList ); + pd->parserTextList.append( parserText ); + + $$->expr = LangExpr::cons( LangTerm::cons( $1->loc, LangTerm::Parser2Type, + varRef, $2->objField, parserTypeRef, $4->fieldInitVect, replacement, parserText ) ); + + /* Check for redeclaration. */ + if ( $2->objField != 0 ) { + if ( pd->curLocalFrame->checkRedecl( $2->objField->name ) != 0 ) { + error( $2->objField->loc ) << "variable " << $2->objField->name << + " redeclared" << endp; + } + + /* Insert it into the field map. */ + $2->objField->typeRef = parserTypeRef; + pd->curLocalFrame->insertField( $2->objField->name, $2->objField ); + } + }; code_factor: KW_Parse opt_capture type_ref '(' opt_code_expr_list ')' final { String parserName = $3->typeRef->typeName + "_parser"; |