From 3e837b13fe2ed7ed1ad6abe379b623db9a064a10 Mon Sep 17 00:00:00 2001 From: dgelessus <dgelessus@users.noreply.github.com> Date: Wed, 20 Apr 2022 16:07:16 +0200 Subject: [PATCH] Remove manual type check from Parser.checkResult template Instead, let the cast throw a ClassCastException. (In practice, this should never happen anyway.) --- src/main/java/org/sablecc/sablecc/parser/Parser.java | 11 ++--------- src/main/resources/org/sablecc/sablecc/parser.txt | 11 ++--------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/sablecc/sablecc/parser/Parser.java b/src/main/java/org/sablecc/sablecc/parser/Parser.java index edc50fa..9cf150b 100644 --- a/src/main/java/org/sablecc/sablecc/parser/Parser.java +++ b/src/main/java/org/sablecc/sablecc/parser/Parser.java @@ -71,16 +71,9 @@ public class Parser implements IParser } } - if (!(elementToCheck instanceof PositionedNode)) { - throw new Error( - "Unexpected elementToCheck (not instanceof PositionedNode): " - + elementToCheck.getClass().getSimpleName() + "/" - + elementToCheck); - } - - if (!this.getMapping().containsKey(elementToCheck) || slurp ) { - final PositionedNode node = (PositionedNode) elementToCheck; + final PositionedNode node = (PositionedNode) elementToCheck; + if (!this.getMapping().containsKey(node) || slurp ) { // dealing with a one-token element if (this.lastPopped == null) { this.lastPopped = this.firstPopped; diff --git a/src/main/resources/org/sablecc/sablecc/parser.txt b/src/main/resources/org/sablecc/sablecc/parser.txt index e5596f9..65db0e6 100644 --- a/src/main/resources/org/sablecc/sablecc/parser.txt +++ b/src/main/resources/org/sablecc/sablecc/parser.txt @@ -79,16 +79,9 @@ public class Parser implements IParser } } - if (!(elementToCheck instanceof PositionedNode)) { - throw new Error( - "Unexpected elementToCheck (not instanceof PositionedNode): " - + elementToCheck.getClass().getSimpleName() + "/" - + elementToCheck); - } - - if (!this.getMapping().containsKey(elementToCheck) || slurp ) { - final PositionedNode node = (PositionedNode) elementToCheck; + final PositionedNode node = (PositionedNode) elementToCheck; + if (!this.getMapping().containsKey(node) || slurp ) { // dealing with a one-token element if (this.lastPopped == null) { this.lastPopped = this.firstPopped; -- GitLab