From 8703b4197775b25074577aae4053edb9e8db6d33 Mon Sep 17 00:00:00 2001 From: paulklint Date: Thu, 14 Mar 2024 17:37:16 +0100 Subject: [PATCH] Fixed issue triggered by lang::java:syntax::Java15 Alternatives in syntax rules all got the same name "production", now changed to "alternative-" with increasing n; --- .../rascalcore/check/BasicRascalConfig.rsc | 3 +- .../check/CollectSyntaxDeclaration.rsc | 9 ++++-- .../lang/rascalcore/compile/Examples/Tst5.rsc | 28 +++++++++++++++---- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/check/BasicRascalConfig.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/check/BasicRascalConfig.rsc index 1b323dca..f2cb667f 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/check/BasicRascalConfig.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/check/BasicRascalConfig.rsc @@ -41,7 +41,8 @@ public set[IdRole] positionalFormalRoles = {formalId(), nestedFormalId()}; public set[IdRole] formalRoles = outerFormalRoles + {nestedFormalId()}; public set[IdRole] variableRoles = formalRoles + {variableId(), moduleVariableId(), patternVariableId()}; public set[IdRole] inferrableRoles = formalRoles + {variableId(), moduleVariableId(), patternVariableId()}; -public set[IdRole] keepInTModelRoles = dataOrSyntaxRoles + {moduleId(), constructorId(), functionId(), fieldId(), keywordFieldId(), annoId(), moduleVariableId()}; +public set[IdRole] keepInTModelRoles = dataOrSyntaxRoles + {moduleId(), constructorId(), functionId(), fieldId(), keywordFieldId(), + annoId(), moduleVariableId(), productionId(), nonterminalId()}; public set[IdRole] assignableRoles = variableRoles; data PathRole diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectSyntaxDeclaration.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectSyntaxDeclaration.rsc index 7cc24bd9..25c1cd99 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectSyntaxDeclaration.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectSyntaxDeclaration.rsc @@ -34,6 +34,8 @@ void collect (current: (SyntaxDefinition) ` syntax = < declareSyntax(current, contextFreeSyntax(), nonterminalId(), c); } +int nalternatives = 0; + void declareSyntax(SyntaxDefinition current, SyntaxRole syntaxRole, IdRole idRole, Collector c, Vis vis=publicVis()){ //println("declareSyntax: "); Sym defined = current.defined; @@ -50,7 +52,7 @@ void declareSyntax(SyntaxDefinition current, SyntaxRole syntaxRole, IdRole idRol dt = defType(nonterminalType); dt.vis = vis; - dt.md5 = md5Hash(current); + dt.md5 = md5Hash(""); // Define the syntax symbol itself and all labelled alternatives as constructors c.define(adtName, idRole, current, dt); @@ -156,7 +158,7 @@ void collect(current: (Prod) ` : ")); } else throw "Unexpected type of production: "; - })[md5=md5Hash(current)]); + })[md5=md5Hash("")]); collect(symbols, c); } else { throw "collect Named Prod: currentAdt not found"; @@ -223,7 +225,8 @@ void collect(current: (Prod) ` | `, Collector c){ collect(alts, c); c.pop(inAlternative); if(isEmpty(c.getStack(inAlternative))){ - c.define("production", nonterminalId(), current, defType(current)[md5=md5Hash("")]); + nalternatives += 1; + c.define("alternative-", nonterminalId(), current, defType(current)[md5=md5Hash("")]); } } else { throw "collect alt: currentAdt not found"; diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst5.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst5.rsc index b3ce3eca..5ac54ee7 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst5.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst5.rsc @@ -1,12 +1,28 @@ module lang::rascalcore::compile::Examples::Tst5 -// #1464 en #1446 -int f6(&T x) { return x; } - -value main() = f6(1); - - &T get(list[&T] _) = 1; +syntax Expr = "e"; + +syntax Expr = + right + ( right postIncr: Expr "++" + | right postDecr: Expr "--" + ) + > left + ( left div: Expr "/" !>> [/] Expr + | left remain: Expr "%" Expr + ) + ; + +syntax Expr = + castPrim: "(" "PrimType" ")" Expr + > left + ( left div: Expr "/" !>> [/] Expr + | left remain: Expr "%" Expr + ) + ; + + //import List; // //value main(){