From 984d0dcb532b8ec45457ddbd3729f77fda76f02b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20L=C3=BCpges?= Date: Wed, 1 Jan 2025 23:13:42 +0100 Subject: [PATCH] Only replace text if found --- .../src/main/java/de/monticore/antlr4/MCErrorListener.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/monticore-runtime/src/main/java/de/monticore/antlr4/MCErrorListener.java b/monticore-runtime/src/main/java/de/monticore/antlr4/MCErrorListener.java index 8545a0be7..201441b83 100644 --- a/monticore-runtime/src/main/java/de/monticore/antlr4/MCErrorListener.java +++ b/monticore-runtime/src/main/java/de/monticore/antlr4/MCErrorListener.java @@ -52,7 +52,9 @@ public void syntaxError(Recognizer recognizer, Object offendingSymbol, int // Due to our substitute-no-keyword handling, we remove no-keywords from the expected list (as they are included within Name) if (parser.getNoKeywordRuleNames() != null) { int index = msg.indexOf("' expecting "); // We strip everything after the expecting - msg = msg.substring(0, index) + "', expecting "; + if (index >= 0) { + msg = msg.substring(0, index) + "', expecting "; + } // Check for the rules which the ATN would change into using epsilon transitions (to find nokeywor rules) Set> epsilonRules = new HashSet<>();