Skip to content

Commit

Permalink
Fixed issue triggered by lang::java:syntax::Java15
Browse files Browse the repository at this point in the history
Alternatives in syntax rules all got the same name "production", now
changed to "alternative-<n>" with increasing n;
  • Loading branch information
PaulKlint committed Mar 14, 2024
1 parent 80a2dad commit 8703b41
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ void collect (current: (SyntaxDefinition) `<Start strt> syntax <Sym defined> = <
declareSyntax(current, contextFreeSyntax(), nonterminalId(), c);
}

int nalternatives = 0;

void declareSyntax(SyntaxDefinition current, SyntaxRole syntaxRole, IdRole idRole, Collector c, Vis vis=publicVis()){
//println("declareSyntax: <current>");
Sym defined = current.defined;
Expand All @@ -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("<current>");

// Define the syntax symbol itself and all labelled alternatives as constructors
c.define(adtName, idRole, current, dt);
Expand Down Expand Up @@ -156,7 +158,7 @@ void collect(current: (Prod) `<ProdModifier* modifiers> <Name name> : <Sym* syms
//def = \start(sdef) := def ? sdef : unset(def, "alabel");
return acons(def, fields, [], alabel=unescape("<name>"));
} else throw "Unexpected type of production: <ptype>";
})[md5=md5Hash(current)]);
})[md5=md5Hash("<adt><current>")]);
collect(symbols, c);
} else {
throw "collect Named Prod: currentAdt not found";
Expand Down Expand Up @@ -223,7 +225,8 @@ void collect(current: (Prod) `<Prod lhs> | <Prod rhs>`, Collector c){
collect(alts, c);
c.pop(inAlternative);
if(isEmpty(c.getStack(inAlternative))){
c.define("production", nonterminalId(), current, defType(current)[md5=md5Hash("<current>")]);
nalternatives += 1;
c.define("alternative-<nalternatives>", nonterminalId(), current, defType(current)[md5=md5Hash("<current>")]);
}
} else {
throw "collect alt: currentAdt not found";
Expand Down
Original file line number Diff line number Diff line change
@@ -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(){
Expand Down

0 comments on commit 8703b41

Please sign in to comment.