From debed84028980dd8d0b9845aaced00a082045154 Mon Sep 17 00:00:00 2001 From: Alexander Hellwig Date: Tue, 5 Sep 2023 19:15:04 +0200 Subject: [PATCH] Fix: Tokens are no longer implicitly defined in antlr parser grammar when they originate from a ConstantGroup --- .../de/monticore/codegen/parser/antlr/Grammar2Antlr.java | 2 +- .../constantgroups/SpecialLexerTokensInConstantGroup.mc4 | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 monticore-test/it/src/main/grammars/mc/feature/constantgroups/SpecialLexerTokensInConstantGroup.mc4 diff --git a/monticore-generator/src/main/java/de/monticore/codegen/parser/antlr/Grammar2Antlr.java b/monticore-generator/src/main/java/de/monticore/codegen/parser/antlr/Grammar2Antlr.java index 67c8bc9238..8b73f69d24 100644 --- a/monticore-generator/src/main/java/de/monticore/codegen/parser/antlr/Grammar2Antlr.java +++ b/monticore-generator/src/main/java/de/monticore/codegen/parser/antlr/Grammar2Antlr.java @@ -371,7 +371,7 @@ public void handle(ASTConstantGroup ast) { } else if (grammarInfo.getKeywordRules().contains(x.getName())) { addToCodeSection(parserHelper.getKeyRuleName(x.getName())); } else { - addToCodeSection("'" + x.getName() + "'"); + addToCodeSection(parserHelper.getLexSymbolName(x.getName())); } if (embeddedJavaCode) { diff --git a/monticore-test/it/src/main/grammars/mc/feature/constantgroups/SpecialLexerTokensInConstantGroup.mc4 b/monticore-test/it/src/main/grammars/mc/feature/constantgroups/SpecialLexerTokensInConstantGroup.mc4 new file mode 100644 index 0000000000..a2eb7bc75e --- /dev/null +++ b/monticore-test/it/src/main/grammars/mc/feature/constantgroups/SpecialLexerTokensInConstantGroup.mc4 @@ -0,0 +1,7 @@ +/* (c) https://github.com/MontiCore/monticore */ +package mc.feature.constantgroups; + +grammar SpecialLexerTokensInConstantGroup { + Start = ALTQUESTION bar:["?" | "!"]; + token ALTQUESTION = '?'; +}