diff options
-rw-r--r-- | src/lmparse.kl | 27 | ||||
-rw-r--r-- | src/parsetree.h | 82 |
2 files changed, 57 insertions, 52 deletions
diff --git a/src/lmparse.kl b/src/lmparse.kl index 1505667b..e5b28a5a 100644 --- a/src/lmparse.kl +++ b/src/lmparse.kl @@ -449,14 +449,12 @@ nonterm basic_type_ref uses type_ref; basic_type_ref: region_qual TK_Word opt_repeat final { - $$->typeRef = TypeRef::cons( $2->loc, $1->nspaceQual, $2->data ); - $$->typeRef->repeatType = $3->repeatType; + $$->typeRef = TypeRef::cons( $2->loc, $1->nspaceQual, $2->data, $3->repeatType ); }; basic_type_ref: KW_Ptr region_qual TK_Word opt_repeat final { - $$->typeRef = TypeRef::cons( $1->loc, $2->nspaceQual, $3->data ); - $$->typeRef->repeatType = $4->repeatType; + $$->typeRef = TypeRef::cons( $1->loc, $2->nspaceQual, $3->data, $4->repeatType ); $$->typeRef = TypeRef::cons( $1->loc, TypeRef::Ptr, $$->typeRef ); }; @@ -654,8 +652,7 @@ nonterm pattern_el_type_or_lit pattern_el_type_or_lit: region_qual TK_Word opt_repeat final { - TypeRef *typeRef = TypeRef::cons( $2->loc, $1->nspaceQual, $2->data ); - typeRef->repeatType = $3->repeatType; + TypeRef *typeRef = TypeRef::cons( $2->loc, $1->nspaceQual, $2->data, $3->repeatType ); ProdEl *factor = new ProdEl( ProdEl::ReferenceType, $2->loc, 0, false, typeRef, 0 ); $$->patternItem = PatternItem::cons( $2->loc, factor, PatternItem::FactorType ); patternItemList->append( $$->patternItem ); @@ -664,8 +661,7 @@ pattern_el_type_or_lit: region_qual TK_Word opt_repeat pattern_el_type_or_lit: region_qual TK_Literal opt_repeat final { PdaLiteral *literal = new PdaLiteral( $2->loc, *$2 ); - TypeRef *typeRef = TypeRef::cons( $2->loc, $1->nspaceQual, literal ); - typeRef->repeatType = $3->repeatType; + TypeRef *typeRef = TypeRef::cons( $2->loc, $1->nspaceQual, literal, $3->repeatType ); ProdEl *factor = new ProdEl( ProdEl::ReferenceType, $2->loc, 0, false, typeRef, 0 ); $$->patternItem = PatternItem::cons( $2->loc, factor, PatternItem::FactorType ); @@ -722,7 +718,6 @@ repl_el: region_qual TK_Literal final { PdaLiteral *literal = new PdaLiteral( $2->loc, *$2 ); TypeRef *typeRef = TypeRef::cons( $2->loc, $1->nspaceQual, literal ); - typeRef->repeatType = RepeatNone; ProdEl *factor = new ProdEl( ProdEl::LiteralType, $2->loc, 0, false, typeRef, 0 ); ReplItem *replItem = ReplItem::cons( $2->loc, ReplItem::FactorType, factor ); replItemList->append( replItem ); @@ -842,8 +837,7 @@ nonterm prod_el prod_el: opt_capture opt_commit region_qual TK_Word opt_repeat final { - TypeRef *typeRef = TypeRef::cons( $4->loc, $3->nspaceQual, $4->data ); - typeRef->repeatType = $5->repeatType; + TypeRef *typeRef = TypeRef::cons( $4->loc, $3->nspaceQual, $4->data, $5->repeatType ); $$->factor = new ProdEl( ProdEl::ReferenceType, $4->loc, $1->objField, $2->commit, typeRef, 0 ); /* If there is a capture, create the field. */ @@ -871,8 +865,7 @@ prod_el: final { /* Create a new factor node going to a concat literal. */ PdaLiteral *literal = new PdaLiteral( $4->loc, *$4 ); - TypeRef *typeRef = TypeRef::cons( $4->loc, $3->nspaceQual, literal ); - typeRef->repeatType = $5->repeatType; + TypeRef *typeRef = TypeRef::cons( $4->loc, $3->nspaceQual, literal, $5->repeatType ); $$->factor = new ProdEl( ProdEl::LiteralType, $4->loc, $1->objField, $2->commit, typeRef, 0 ); /* If there is a capture, create the field. */ @@ -1879,8 +1872,6 @@ code_factor: /* Get the language element. */ Namespace *nspace = namespaceStack.top(); - GenericType *generic = 0; - NamespaceQual *nspaceQual = new NamespaceQual( namespaceStack.top(), regionStack.top() ); TypeRef *parserTypeRef = TypeRef::cons( InputLoc(), @@ -1895,7 +1886,7 @@ code_factor: varRef = new LangVarRef( $2->objField->loc, new QualItemVect, $2->objField->name ); $$->expr = LangExpr::cons( LangTerm::cons( $1->loc, LangTerm::OrigParseType, - varRef, $2->objField, $3->typeRef, generic, parserTypeRef, replacement ) ); + varRef, $2->objField, $3->typeRef, parserTypeRef, replacement ) ); $$->expr->term->args = $5->exprVect; /* Check for redeclaration. */ @@ -1919,8 +1910,6 @@ code_factor: /* Get the language element. */ Namespace *nspace = namespaceStack.top(); - GenericType *generic = 0; - NamespaceQual *nspaceQual = new NamespaceQual( namespaceStack.top(), regionStack.top() ); TypeRef *parserTypeRef = TypeRef::cons( InputLoc(), @@ -1935,7 +1924,7 @@ code_factor: varRef = new LangVarRef( $2->objField->loc, new QualItemVect, $2->objField->name ); $$->expr = LangExpr::cons( LangTerm::cons( $1->loc, LangTerm::OrigParseStopType, - varRef, $2->objField, $3->typeRef, generic, parserTypeRef, replacement ) ); + varRef, $2->objField, $3->typeRef, parserTypeRef, replacement ) ); $$->expr->term->args = $5->exprVect; /* Check for redeclaration. */ diff --git a/src/parsetree.h b/src/parsetree.h index b7bca14b..92428a0a 100644 --- a/src/parsetree.h +++ b/src/parsetree.h @@ -1910,7 +1910,7 @@ struct TypeRef iterDef(0), typeRef1(0), typeRef2(0), - repeatType((RepeatType)-1), + repeatType(RepeatNone), nspace(0), uniqueType(0), searchUniqueType(0), @@ -1921,11 +1921,19 @@ struct TypeRef static TypeRef *cons( const InputLoc &loc, NamespaceQual *nspaceQual, String typeName ) { TypeRef *t = new TypeRef; - t->type = (Name); - t->loc = (loc); - t->nspaceQual = (nspaceQual); - t->typeName = (typeName); - t->repeatType = (RepeatNone); + t->type = Name; + t->loc = loc; + t->nspaceQual = nspaceQual; + t->typeName = typeName; + t->repeatType = RepeatNone; + return t; + } + + /* Qualification and a type name. These require lookup. */ + static TypeRef *cons( const InputLoc &loc, NamespaceQual *nspaceQual, String typeName, RepeatType repeatType ) + { + TypeRef *t = cons( loc, nspaceQual, typeName ); + t->repeatType = repeatType; return t; } @@ -1933,11 +1941,19 @@ struct TypeRef static TypeRef *cons( const InputLoc &loc, NamespaceQual *nspaceQual, PdaLiteral *pdaLiteral ) { TypeRef *t = new TypeRef; - t->type = (Literal); - t->loc = (loc); - t->nspaceQual = (nspaceQual); - t->pdaLiteral = (pdaLiteral); - t->repeatType = (RepeatNone); + t->type = Literal; + t->loc = loc; + t->nspaceQual = nspaceQual; + t->pdaLiteral = pdaLiteral; + t->repeatType = RepeatNone; + return t; + } + + /* Qualification and a type name. These require lookup. */ + static TypeRef *cons( const InputLoc &loc, NamespaceQual *nspaceQual, PdaLiteral *pdaLiteral, RepeatType repeatType ) + { + TypeRef *t = cons( loc, nspaceQual, pdaLiteral ); + t->repeatType = repeatType; return t; } @@ -1945,12 +1961,12 @@ struct TypeRef static TypeRef *cons( const InputLoc &loc, Type type, NamespaceQual *nspaceQual, TypeRef *typeRef1, TypeRef *typeRef2 ) { TypeRef *t = new TypeRef; - t->type = (type); - t->loc = (loc); - t->nspaceQual = (nspaceQual); - t->typeRef1 = (typeRef1); - t->typeRef2 = (typeRef2); - t->repeatType = (RepeatNone); + t->type = type; + t->loc = loc; + t->nspaceQual = nspaceQual; + t->typeRef1 = typeRef1; + t->typeRef2 = typeRef2; + t->repeatType = RepeatNone; return t; } @@ -1958,10 +1974,10 @@ struct TypeRef static TypeRef *cons( const InputLoc &loc, Type type, TypeRef *typeRef1 ) { TypeRef *t = new TypeRef; - t->type = (type); - t->loc = (loc); - t->typeRef1 = (typeRef1); - t->repeatType = (RepeatNone); + t->type = type; + t->loc = loc; + t->typeRef1 = typeRef1; + t->repeatType = RepeatNone; return t; } @@ -1972,12 +1988,12 @@ struct TypeRef UniqueType *searchUniqueType ) { TypeRef *t = new TypeRef; - t->type = (Iterator); - t->loc = (loc); - t->iterDef = (iterDef); - t->repeatType = (RepeatNone); - t->uniqueType = (uniqueType); - t->searchUniqueType = (searchUniqueType); + t->type = Iterator; + t->loc = loc; + t->iterDef = iterDef; + t->repeatType = RepeatNone; + t->uniqueType = uniqueType; + t->searchUniqueType = searchUniqueType; return t; } @@ -1985,10 +2001,10 @@ struct TypeRef static TypeRef *cons( const InputLoc &loc, UniqueType *uniqueType ) { TypeRef *t = new TypeRef; - t->type = (Unspecified); - t->loc = (loc); - t->repeatType = (RepeatNone); - t->uniqueType = (uniqueType); + t->type = Unspecified; + t->loc = loc; + t->repeatType = RepeatNone; + t->uniqueType = uniqueType; return t; } @@ -2350,6 +2366,7 @@ struct LangTerm LangTerm() : + generic(0), parserText(0) {} @@ -2503,7 +2520,7 @@ struct LangTerm } static LangTerm *cons( const InputLoc &loc, Type type, LangVarRef *varRef, - ObjField *objField, TypeRef *typeRef, GenericType *generic, TypeRef *parserTypeRef, + ObjField *objField, TypeRef *typeRef, TypeRef *parserTypeRef, Replacement *replacement ) { LangTerm *t = new LangTerm; @@ -2512,7 +2529,6 @@ struct LangTerm t->varRef = varRef; t->objField = objField; t->typeRef = typeRef; - t->generic = generic; t->parserTypeRef = parserTypeRef; t->replacement = replacement; return t; |