diff options
author | Adrian Thurston <thurston@complang.org> | 2012-08-23 10:08:02 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2012-08-23 10:08:02 -0400 |
commit | 6309b7dca74e713372df4d3ddb7cf305e785eac6 (patch) | |
tree | 408037855983b0f1fbd2d3b8519b5e03faed34bf | |
parent | 177559c6f450b01a4b54c2bdd5157c211534d783 (diff) | |
download | colm-6309b7dca74e713372df4d3ddb7cf305e785eac6.tar.gz |
eliminated global and old parse syntaxes
-rw-r--r-- | colm.vim | 2 | ||||
-rw-r--r-- | colm/lmparse.kh | 2 | ||||
-rw-r--r-- | colm/lmparse.kl | 117 | ||||
-rw-r--r-- | colm/lmscan.rl | 1 |
4 files changed, 20 insertions, 102 deletions
@@ -54,7 +54,7 @@ syntax match tlNumber "false" syntax keyword Type \ commit include literal iter - \ namespace lex reducefirst global include export + \ namespace lex reducefirst include export \ construct cons parse parse_stop match require send \ preeof left right nonassoc prec accum context parser alias diff --git a/colm/lmparse.kh b/colm/lmparse.kh index 97d8738e..50baa500 100644 --- a/colm/lmparse.kh +++ b/colm/lmparse.kh @@ -53,7 +53,7 @@ struct ColmParser # Defining things. token KW_Rl, KW_Def, KW_Lex, KW_Context, KW_Ignore, KW_Token, KW_Commit, KW_Namespace, - KW_Literal, KW_ReduceFirst, KW_Map, KW_List, KW_Vector, KW_Parser, KW_Global, KW_Export, + KW_Literal, KW_ReduceFirst, KW_Map, KW_List, KW_Vector, KW_Parser, KW_Export, KW_Iter, KW_Reject, KW_Ptr, KW_Ref, KW_Deref; # Language. diff --git a/colm/lmparse.kl b/colm/lmparse.kl index e7015119..d972e248 100644 --- a/colm/lmparse.kl +++ b/colm/lmparse.kl @@ -76,7 +76,7 @@ root_item: context_def commit final { $$->stmt = 0; }; root_item: namespace_def commit final { $$->stmt = 0; }; root_item: function_def commit final { $$->stmt = 0; }; root_item: iter_def commit final { $$->stmt = 0; }; -root_item: global_def commit final { $$->stmt = $1->stmt; }; +root_item: export_def commit final { $$->stmt = 0; }; root_item: statement commit final { $$->stmt = $1->stmt; }; root_item: pre_eof commit final { $$->stmt = 0; }; root_item: precedence commit final { $$->stmt = 0; }; @@ -189,9 +189,9 @@ reference_type_ref: KW_Ref type_ref $$->typeRef = TypeRef::cons( $1->loc, TypeRef::Ref, $2->typeRef ); }; -nonterm global_def uses statement; +nonterm export_def uses statement; -global_def: KW_Export var_def opt_def_init +export_def: KW_Export var_def opt_def_init final { $$->stmt = 0; @@ -215,33 +215,6 @@ global_def: KW_Export var_def opt_def_init } }; -global_def: KW_Global var_def opt_def_init - final { - $$->stmt = 0; - - ObjectDef *object; - if ( contextStack.length() == 0 ) - object = pd->globalObjectDef; - else { - Context *context = contextStack.top(); - $2->objField->context = context; - object = context->contextObjDef; - } - - if ( object->checkRedecl( $2->objField->name ) != 0 ) - error($2->objField->loc) << "object field renamed" << endp; - - object->insertField( $2->objField->name, $2->objField ); - - if ( $3->expr != 0 ) { - LangVarRef *varRef = LangVarRef::cons( $2->objField->loc, - $2->objField->name ); - - $$->stmt = LangStmt::cons( $2->objField->loc, - $3->assignType, varRef, $3->expr ); - } - }; - precedence: pred_type pred_token_list final { pd->predValue++; }; pred_type: KW_Left final { predType = PredLeft; }; @@ -523,6 +496,7 @@ context_item: region_def commit; context_item: context_def commit; context_item: function_def commit; context_item: iter_def commit; +context_item: export_def commit; context_item: pre_eof commit; context_item: precedence commit; @@ -1987,7 +1961,7 @@ code_factor: }; code_factor: - E1 parse_cmd opt_capture type_ref opt_field_init accumulate + parse_cmd opt_capture type_ref opt_field_init accumulate final { Namespace *nspace = namespaceStack.top(); TokenRegion *region = regionStack.top(); @@ -1996,96 +1970,41 @@ code_factor: * Thisis the constructor for the parser. */ ConsItemList *emptyConsItemList = new ConsItemList; - Constructor *constructor = Constructor::cons( $2->loc, nspace, region, + Constructor *constructor = Constructor::cons( $1->loc, nspace, region, emptyConsItemList, pd->nextPatConsId++ ); pd->replList.append( constructor ); /* The parser may be referenced. */ LangVarRef *varRef = 0; - if ( $3->objField != 0 ) - varRef = LangVarRef::cons( $3->objField->loc, $3->objField->name ); + if ( $2->objField != 0 ) + varRef = LangVarRef::cons( $2->objField->loc, $2->objField->name ); /* The typeref for the parser. */ NamespaceQual *nspaceQual = new NamespaceQual( namespaceStack.top(), regionStack.top() ); TypeRef *parserTypeRef = TypeRef::cons( InputLoc(), - TypeRef::Parser, nspaceQual, $4->typeRef, 0 ); + TypeRef::Parser, nspaceQual, $3->typeRef, 0 ); - ParserText *parserText = ParserText::cons( $3->loc, nspace, region, $6->list ); + ParserText *parserText = ParserText::cons( $2->loc, nspace, region, $5->list ); pd->parserTextList.append( parserText ); - $$->expr = LangExpr::cons( LangTerm::cons( $2->loc, - $2->stop ? LangTerm::ParseStopType : LangTerm::ParseType, - varRef, $3->objField, parserTypeRef, $5->fieldInitVect, constructor, parserText ) ); + $$->expr = LangExpr::cons( LangTerm::cons( $1->loc, + $1->stop ? LangTerm::ParseStopType : LangTerm::ParseType, + varRef, $2->objField, parserTypeRef, $4->fieldInitVect, constructor, parserText ) ); /* Check for redeclaration. */ - if ( $3->objField != 0 ) { - if ( pd->curLocalFrame->checkRedecl( $3->objField->name ) != 0 ) { - error( $3->objField->loc ) << "variable " << $3->objField->name << + 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. */ - $3->objField->typeRef = parserTypeRef; - pd->curLocalFrame->insertField( $3->objField->name, $3->objField ); + $2->objField->typeRef = parserTypeRef; + pd->curLocalFrame->insertField( $2->objField->name, $2->objField ); } }; -code_factor: - E2 parse_cmd opt_capture type_ref '(' opt_code_expr_list ')' - final { - String parserName = $4->typeRef->typeName + "_parser"; - - /* Get the language element. */ - Namespace *nspace = namespaceStack.top(); - TokenRegion *region = regionStack.top(); - - NamespaceQual *nspaceQual = new NamespaceQual( - namespaceStack.top(), regionStack.top() ); - TypeRef *parserTypeRef = TypeRef::cons( InputLoc(), - TypeRef::Parser, nspaceQual, $4->typeRef, 0 ); - - Constructor *constructor = Constructor::cons( $2->loc, nspace, pd->rootRegion, - new ConsItemList, pd->nextPatConsId++ ); - pd->replList.append( constructor ); - - ConsItemList *consItemList = new ConsItemList; - FieldInitVect *fieldInitVect = new FieldInitVect; - if ( $6->exprVect->length() == 1 ) { - ConsItem *consItem = ConsItem::cons( $2->loc, ConsItem::ExprType, $6->exprVect->data[0] ); - consItemList->append( consItem ); - } - else if ( $6->exprVect->length() == 2 ) { - FieldInit *fieldInit = new FieldInit( InputLoc(), "_name", $6->exprVect->data[0] ); - fieldInitVect->append( fieldInit ); - - ConsItem *consItem = ConsItem::cons( $2->loc, ConsItem::ExprType, $6->exprVect->data[1] ); - consItemList->append( consItem ); - } - - LangVarRef *varRef = 0; - if ( $3->objField != 0 ) - varRef = LangVarRef::cons( $3->objField->loc, $3->objField->name ); - - ParserText *parserText = ParserText::cons( $3->loc, nspace, region, consItemList ); - pd->parserTextList.append( parserText ); - - $$->expr = LangExpr::cons( LangTerm::cons( $2->loc, - $2->stop ? LangTerm::OrigParseStopType : LangTerm::OrigParseType, - varRef, $3->objField, parserTypeRef, fieldInitVect, constructor, parserText ) ); - - /* Check for redeclaration. */ - if ( $3->objField != 0 ) { - if ( pd->curLocalFrame->checkRedecl( $3->objField->name ) != 0 ) { - error( $3->objField->loc ) << "variable " << $3->objField->name << - " redeclared" << endp; - } - - /* Insert it into the field map. */ - $3->objField->typeRef = $4->typeRef; - pd->curLocalFrame->insertField( $3->objField->name, $3->objField ); - } - }; code_factor: var_ref TK_LtLt accumulate diff --git a/colm/lmscan.rl b/colm/lmscan.rl index d38df495..b53f0657 100644 --- a/colm/lmscan.rl +++ b/colm/lmscan.rl @@ -463,7 +463,6 @@ void ColmScanner::endSection( ) 'false' => { token( KW_False ); }; 'parse' => { token( KW_Parse ); }; 'parse_stop' => { token( KW_ParseStop ); }; - 'global' => { token( KW_Global ); }; 'export' => { token( KW_Export ); }; 'ptr' => { token( KW_Ptr ); }; 'ref' => { token( KW_Ref ); }; |