From 3b8fe35f684a1d622b6eefa4be24d1b26f96a525 Mon Sep 17 00:00:00 2001
From: dgelessus <dgelessus@users.noreply.github.com>
Date: Fri, 10 May 2024 15:18:20 +0200
Subject: [PATCH] Rename generated Lexer local variables to no shadow instance
 fields

---
 .../java/org/sablecc/sablecc/lexer/Lexer.java | 180 +++++++++---------
 .../resources/org/sablecc/sablecc/lexer.txt   |  26 +--
 2 files changed, 103 insertions(+), 103 deletions(-)

diff --git a/src/main/java/org/sablecc/sablecc/lexer/Lexer.java b/src/main/java/org/sablecc/sablecc/lexer/Lexer.java
index 1325460..2d529b1 100644
--- a/src/main/java/org/sablecc/sablecc/lexer/Lexer.java
+++ b/src/main/java/org/sablecc/sablecc/lexer/Lexer.java
@@ -68,8 +68,8 @@ public class Lexer
         int acceptLine = -1;
         boolean acceptCr = false;
 
-        int[][][] gotoTable = Lexer.gotoTable[this.state.ordinal()];
-        int[] accept = Lexer.accept[this.state.ordinal()];
+        int[][][] gotoTableSub = Lexer.gotoTable[this.state.ordinal()];
+        int[] acceptSub = Lexer.accept[this.state.ordinal()];
         this.text.setLength(0);
 
         while(true)
@@ -126,7 +126,7 @@ public class Lexer
 
                     dfaState = -1;
 
-                    int[][] tmp1 =  gotoTable[oldState];
+                    int[][] tmp1 = gotoTableSub[oldState];
                     int low = 0;
                     int high = tmp1.length - 1;
 
@@ -160,10 +160,10 @@ public class Lexer
 
             if(dfaState >= 0)
             {
-                if(accept[dfaState] != -1)
+                if(acceptSub[dfaState] != -1)
                 {
                     acceptState = dfaState;
-                    acceptToken = accept[dfaState];
+                    acceptToken = acceptSub[dfaState];
                     acceptLength = this.text.length();
                     acceptPos = this.pos;
                     acceptLine = this.line;
@@ -178,7 +178,7 @@ public class Lexer
                     {
                         case 0:
                         {
-                            Token token = new TPkgId(getText(acceptLength), startLine + 1, startPos + 1);
+                            Token tok = new TPkgId(getText(acceptLength), startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
@@ -187,11 +187,11 @@ public class Lexer
                             {
                                 case 1: state = State.PACKAGE; break;
                             }
-                            return token;
+                            return tok;
                         }
                         case 1:
                         {
-                            Token token = new TPackage(startLine + 1, startPos + 1);
+                            Token tok = new TPackage(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
@@ -200,137 +200,137 @@ public class Lexer
                             {
                                 case 0: state = State.PACKAGE; break;
                             }
-                            return token;
+                            return tok;
                         }
                         case 2:
                         {
-                            Token token = new TStates(startLine + 1, startPos + 1);
+                            Token tok = new TStates(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 3:
                         {
-                            Token token = new THelpers(startLine + 1, startPos + 1);
+                            Token tok = new THelpers(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 4:
                         {
-                            Token token = new TTokens(startLine + 1, startPos + 1);
+                            Token tok = new TTokens(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 5:
                         {
-                            Token token = new TIgnored(startLine + 1, startPos + 1);
+                            Token tok = new TIgnored(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 6:
                         {
-                            Token token = new TProductions(startLine + 1, startPos + 1);
+                            Token tok = new TProductions(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 7:
                         {
-                            Token token = new TAbstract(startLine + 1, startPos + 1);
+                            Token tok = new TAbstract(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 8:
                         {
-                            Token token = new TSyntax(startLine + 1, startPos + 1);
+                            Token tok = new TSyntax(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 9:
                         {
-                            Token token = new TTree(startLine + 1, startPos + 1);
+                            Token tok = new TTree(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 10:
                         {
-                            Token token = new TNew(startLine + 1, startPos + 1);
+                            Token tok = new TNew(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 11:
                         {
-                            Token token = new TNull(startLine + 1, startPos + 1);
+                            Token tok = new TNull(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 12:
                         {
-                            Token token = new TTokenSpecifier(startLine + 1, startPos + 1);
+                            Token tok = new TTokenSpecifier(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 13:
                         {
-                            Token token = new TProductionSpecifier(startLine + 1, startPos + 1);
+                            Token tok = new TProductionSpecifier(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 14:
                         {
-                            Token token = new TDot(startLine + 1, startPos + 1);
+                            Token tok = new TDot(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 15:
                         {
-                            Token token = new TDDot(startLine + 1, startPos + 1);
+                            Token tok = new TDDot(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 16:
                         {
-                            Token token = new TSemicolon(startLine + 1, startPos + 1);
+                            Token tok = new TSemicolon(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
@@ -340,214 +340,214 @@ public class Lexer
                                 case 0: state = State.NORMAL; break;
                                 case 1: state = State.NORMAL; break;
                             }
-                            return token;
+                            return tok;
                         }
                         case 17:
                         {
-                            Token token = new TEqual(startLine + 1, startPos + 1);
+                            Token tok = new TEqual(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 18:
                         {
-                            Token token = new TLBkt(startLine + 1, startPos + 1);
+                            Token tok = new TLBkt(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 19:
                         {
-                            Token token = new TRBkt(startLine + 1, startPos + 1);
+                            Token tok = new TRBkt(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 20:
                         {
-                            Token token = new TLPar(startLine + 1, startPos + 1);
+                            Token tok = new TLPar(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 21:
                         {
-                            Token token = new TRPar(startLine + 1, startPos + 1);
+                            Token tok = new TRPar(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 22:
                         {
-                            Token token = new TLBrace(startLine + 1, startPos + 1);
+                            Token tok = new TLBrace(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 23:
                         {
-                            Token token = new TRBrace(startLine + 1, startPos + 1);
+                            Token tok = new TRBrace(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 24:
                         {
-                            Token token = new TPlus(startLine + 1, startPos + 1);
+                            Token tok = new TPlus(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 25:
                         {
-                            Token token = new TMinus(startLine + 1, startPos + 1);
+                            Token tok = new TMinus(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 26:
                         {
-                            Token token = new TQMark(startLine + 1, startPos + 1);
+                            Token tok = new TQMark(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 27:
                         {
-                            Token token = new TStar(startLine + 1, startPos + 1);
+                            Token tok = new TStar(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 28:
                         {
-                            Token token = new TBar(startLine + 1, startPos + 1);
+                            Token tok = new TBar(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 29:
                         {
-                            Token token = new TComma(startLine + 1, startPos + 1);
+                            Token tok = new TComma(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 30:
                         {
-                            Token token = new TSlash(startLine + 1, startPos + 1);
+                            Token tok = new TSlash(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 31:
                         {
-                            Token token = new TArrow(startLine + 1, startPos + 1);
+                            Token tok = new TArrow(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 32:
                         {
-                            Token token = new TColon(startLine + 1, startPos + 1);
+                            Token tok = new TColon(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 33:
                         {
-                            Token token = new TId(getText(acceptLength), startLine + 1, startPos + 1);
+                            Token tok = new TId(getText(acceptLength), startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 34:
                         {
-                            Token token = new TChar(getText(acceptLength), startLine + 1, startPos + 1);
+                            Token tok = new TChar(getText(acceptLength), startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 35:
                         {
-                            Token token = new TDecChar(getText(acceptLength), startLine + 1, startPos + 1);
+                            Token tok = new TDecChar(getText(acceptLength), startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 36:
                         {
-                            Token token = new THexChar(getText(acceptLength), startLine + 1, startPos + 1);
+                            Token tok = new THexChar(getText(acceptLength), startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 37:
                         {
-                            Token token = new TString(getText(acceptLength), startLine + 1, startPos + 1);
+                            Token tok = new TString(getText(acceptLength), startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 38:
                         {
-                            Token token = new TBlank(getText(acceptLength), startLine + 1, startPos + 1);
+                            Token tok = new TBlank(getText(acceptLength), startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                         case 39:
                         {
-                            Token token = new TComment(getText(acceptLength), startLine + 1, startPos + 1);
+                            Token tok = new TComment(getText(acceptLength), startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
                             this.cr = acceptCr;
-                            return token;
+                            return tok;
                         }
                     }
                 }
@@ -596,13 +596,13 @@ public class Lexer
      * @deprecated This method doesn't restore line/column info correctly in some cases
      *     (if a token begins in the middle of a CRLF newline pair).
      *     There is no planned replacement.
-     * @param token the token to push back onto the input
+     * @param tok the token to push back onto the input
      * @throws IOException when thrown by {@link PushbackReader#unread(int)}
      */
     @Deprecated
-    protected void unread(Token token) throws IOException
+    protected void unread(Token tok) throws IOException
     {
-        String text = token.getText();
+        String text = tok.getText();
         int length = text.length();
 
         for(int i = length - 1; i >= 0; i--)
@@ -612,8 +612,8 @@ public class Lexer
             this.in.unread(text.charAt(i));
         }
 
-        this.pos = token.getPos() - 1;
-        this.line = token.getLine() - 1;
+        this.pos = tok.getPos() - 1;
+        this.line = tok.getLine() - 1;
     }
 
     private String getText(int acceptLength)
diff --git a/src/main/resources/org/sablecc/sablecc/lexer.txt b/src/main/resources/org/sablecc/sablecc/lexer.txt
index 66baac8..c449448 100644
--- a/src/main/resources/org/sablecc/sablecc/lexer.txt
+++ b/src/main/resources/org/sablecc/sablecc/lexer.txt
@@ -92,8 +92,8 @@ public class Lexer
         int acceptLine = -1;
         boolean acceptCr = false;
 
-        int[][][] gotoTable = Lexer.gotoTable[this.state.ordinal()];
-        int[] accept = Lexer.accept[this.state.ordinal()];
+        int[][][] gotoTableSub = Lexer.gotoTable[this.state.ordinal()];
+        int[] acceptSub = Lexer.accept[this.state.ordinal()];
         this.text.setLength(0);
 
         while(true)
@@ -150,7 +150,7 @@ public class Lexer
 
                     dfaState = -1;
 
-                    int[][] tmp1 =  gotoTable[oldState];
+                    int[][] tmp1 = gotoTableSub[oldState];
                     int low = 0;
                     int high = tmp1.length - 1;
 
@@ -184,10 +184,10 @@ public class Lexer
 
             if(dfaState >= 0)
             {
-                if(accept[dfaState] != -1)
+                if(acceptSub[dfaState] != -1)
                 {
                     acceptState = dfaState;
-                    acceptToken = accept[dfaState];
+                    acceptToken = acceptSub[dfaState];
                     acceptLength = this.text.length();
                     acceptPos = this.pos;
                     acceptLine = this.line;
@@ -206,7 +206,7 @@ $
 Macro:LexerVariableToken
                         case $0$:
                         {
-                            Token token = new $1$(getText(acceptLength), startLine + 1, startPos + 1);
+                            Token tok = new $1$(getText(acceptLength), startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
@@ -217,7 +217,7 @@ $
 Macro:LexerFixedToken
                         case $0$:
                         {
-                            Token token = new $1$(startLine + 1, startPos + 1);
+                            Token tok = new $1$(startLine + 1, startPos + 1);
                             pushBack(acceptLength);
                             this.pos = acceptPos;
                             this.line = acceptLine;
@@ -242,7 +242,7 @@ Macro:TokenSwitchTail
 $
 
 Macro:LexerTokenTail
-                            return token;
+                            return tok;
                         }
 
 $
@@ -295,13 +295,13 @@ Macro:LexerBody
      * @deprecated This method doesn't restore line/column info correctly in some cases
      *     (if a token begins in the middle of a CRLF newline pair).
      *     There is no planned replacement.
-     * @param token the token to push back onto the input
+     * @param tok the token to push back onto the input
      * @throws IOException when thrown by {@link PushbackReader#unread(int)}
      */
     @Deprecated
-    protected void unread(Token token) throws IOException
+    protected void unread(Token tok) throws IOException
     {
-        String text = token.getText();
+        String text = tok.getText();
         int length = text.length();
 
         for(int i = length - 1; i >= 0; i--)
@@ -311,8 +311,8 @@ Macro:LexerBody
             this.in.unread(text.charAt(i));
         }
 
-        this.pos = token.getPos() - 1;
-        this.line = token.getLine() - 1;
+        this.pos = tok.getPos() - 1;
+        this.line = tok.getLine() - 1;
     }
 
     private String getText(int acceptLength)
-- 
GitLab