From de00b343a72fb9cddcd3d44c08364c5509c0b71a Mon Sep 17 00:00:00 2001
From: dgelessus <dgelessus@users.noreply.github.com>
Date: Wed, 15 May 2024 19:39:42 +0200
Subject: [PATCH] Try removing another check from generated
 Parser.computePositions

---
 .../org/sablecc/sablecc/parser/Parser.java    | 19 ++-----------------
 .../resources/org/sablecc/sablecc/parser.txt  | 19 ++-----------------
 2 files changed, 4 insertions(+), 34 deletions(-)

diff --git a/src/main/java/org/sablecc/sablecc/parser/Parser.java b/src/main/java/org/sablecc/sablecc/parser/Parser.java
index 1ab72f9..307f9d1 100644
--- a/src/main/java/org/sablecc/sablecc/parser/Parser.java
+++ b/src/main/java/org/sablecc/sablecc/parser/Parser.java
@@ -14,7 +14,6 @@ import java.util.ListIterator;
 
 import de.hhu.stups.sablecc.patch.IParser;
 import de.hhu.stups.sablecc.patch.PositionedNode;
-import de.hhu.stups.sablecc.patch.SourcePosition;
 
 import org.sablecc.sablecc.lexer.Lexer;
 import org.sablecc.sablecc.lexer.LexerException;
@@ -44,16 +43,7 @@ public class Parser implements IParser
         assert node.getEndPos() == null;
 
         PositionedNode beginNode = findBeginNode(beginNodeList);
-        if (beginNode == null) {
-            /*
-             * Sometimes (haven't found out why) we get empty list here. In
-             * the only observed cases we were looking for the source range
-             * of the whole parse unit. Then the start pos is the first char.
-             */
-            node.setStartPos(new SourcePosition(1, 1));
-        } else {
-            node.setStartPos(beginNode.getStartPos());
-        }
+        node.setStartPos(beginNode.getStartPos());
 
         PositionedNode endNode = findEndNode(endNodeList);
         node.setEndPos(endNode.getEndPos());
@@ -63,12 +53,7 @@ public class Parser implements IParser
         Object first = list.get(0);
         if (first instanceof List<?>) {
             List<?> list2 = (List<?>) first;
-
-            if (!list2.isEmpty()) {
-                return (PositionedNode)list2.get(0);
-            } else {
-                return null;
-            }
+            return (PositionedNode)list2.get(0);
         }
 
         return (PositionedNode)first;
diff --git a/src/main/resources/org/sablecc/sablecc/parser.txt b/src/main/resources/org/sablecc/sablecc/parser.txt
index 7a52153..74b289f 100644
--- a/src/main/resources/org/sablecc/sablecc/parser.txt
+++ b/src/main/resources/org/sablecc/sablecc/parser.txt
@@ -22,7 +22,6 @@ import java.util.ListIterator;
 
 import de.hhu.stups.sablecc.patch.IParser;
 import de.hhu.stups.sablecc.patch.PositionedNode;
-import de.hhu.stups.sablecc.patch.SourcePosition;
 
 import $0$lexer.Lexer;
 import $0$lexer.LexerException;
@@ -52,16 +51,7 @@ public class Parser implements IParser
         assert node.getEndPos() == null;
 
         PositionedNode beginNode = findBeginNode(beginNodeList);
-        if (beginNode == null) {
-            /*
-             * Sometimes (haven't found out why) we get empty list here. In
-             * the only observed cases we were looking for the source range
-             * of the whole parse unit. Then the start pos is the first char.
-             */
-            node.setStartPos(new SourcePosition(1, 1));
-        } else {
-            node.setStartPos(beginNode.getStartPos());
-        }
+        node.setStartPos(beginNode.getStartPos());
 
         PositionedNode endNode = findEndNode(endNodeList);
         node.setEndPos(endNode.getEndPos());
@@ -71,12 +61,7 @@ public class Parser implements IParser
         Object first = list.get(0);
         if (first instanceof List<?>) {
             List<?> list2 = (List<?>) first;
-
-            if (!list2.isEmpty()) {
-                return (PositionedNode)list2.get(0);
-            } else {
-                return null;
-            }
+            return (PositionedNode)list2.get(0);
         }
 
         return (PositionedNode)first;
-- 
GitLab