rascal icon indicating copy to clipboard operation
rascal copied to clipboard

Merging grammars with overlapping non-terminal names in different roles breaks the parser generator

Open jurgenvinju opened this issue 2 years ago • 1 comments

Describe the bug

In one module we have: lexical A = ... and in the other syntax A = ... and then we merge those modules by extending them into a third.

The result is:

org.rascalmpl.exceptions.JavaCompilation: Java compilation failed due to method A() is already defined in class org.rascalmpl.java.parser.object.$GENERATED_PARSER$687122369
        at org.rascalmpl.interpreter.utils.JavaBridge.compileJava(JavaBridge.java:134)
        at org.rascalmpl.interpreter.utils.JavaBridge.compileJava(JavaBridge.java:113)
        at org.rascalmpl.parser.ParserGenerator.getNewParser(ParserGenerator.java:245)
        at org.rascalmpl.parser.ParserGenerator.getNewParser(ParserGenerator.java:207)

This is because the name of the methods and nested classes for non-terminals (lexical or syntax) are both just the name of the non-terminal without a prefix.

jurgenvinju avatar Nov 22 '23 14:11 jurgenvinju

If the non-terminals have the same role, then the rules are simply merged. But since these non-terminals are not the same, the rules are not merged. Yet the generator picks the same name.

jurgenvinju avatar Nov 22 '23 14:11 jurgenvinju