Skip to content

Commit

Permalink
Improve error messages (AntlrTool)
Browse files Browse the repository at this point in the history
  • Loading branch information
maritabreuer committed Nov 19, 2024
1 parent 792b782 commit 8e9e2e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import de.monticore.grammar.grammar._symboltable.MCGrammarSymbol;
import de.monticore.grammar.grammar._symboltable.ProdSymbol;
import de.se_rwth.commons.SourcePosition;
import de.se_rwth.commons.SourcePositionBuilder;
import de.se_rwth.commons.StringTransformations;
import de.se_rwth.commons.logging.Log;
import org.antlr.v4.Tool;
Expand Down Expand Up @@ -59,7 +60,7 @@ protected void createMessage(ANTLRMessage message, boolean isError) {

ST msgST = errMgr.getMessageTemplate(message);
String origMessage = msgST.render();
Log.debug(origMessage, "AnltrTool");
Log.debug(origMessage, "AntlrTool");

// Change arguments corresponding to names in MC grammar
Object[] args = message.getArgs();
Expand All @@ -84,7 +85,11 @@ protected void createMessage(ANTLRMessage message, boolean isError) {
String output = "0xA1129 " + "Error from Antlr subsystem: "
+ messageST.render() + " (see e.g. www.antlr.org)";
if (position.equals(SourcePosition.getDefaultSourcePosition())) {
Log.error(output);
SourcePosition sourcePosition = new SourcePositionBuilder().
setFileName(message.fileName).
setLine(message.line).
setColumn(message.charPosition).build();
Log.error(output, sourcePosition);
}
else {
Log.error(output, position);
Expand Down
4 changes: 3 additions & 1 deletion monticore-generator/src/main/resources/parser/Lexer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ options {

${tc.includeArgs("parser.LexerMember", [antlrGenerator, parserHelper.getGrammarSymbol().getName()])}

// Implicit token
<#list genHelper.getLexSymbolsWithInherited() as lexSymbol>
${genHelper.getLexSymbolName(lexSymbol)} : '${lexSymbol}';
</#list>


// Explicit token
<#list genHelper.getLexerRulesToGenerate() as lexProd>
<#list antlrGenerator.createAntlrCode(lexProd) as lexerRule>
${lexerRule}
Expand Down

0 comments on commit 8e9e2e6

Please sign in to comment.