diff --git a/src/main/java/org/sablecc/sablecc/lexer/Lexer.java b/src/main/java/org/sablecc/sablecc/lexer/Lexer.java index f397d6cc723c1cad118e96c9c8eebdb67b2ef174..69e7501c94e72129c46c8b315d0a2b5631f510c4 100644 --- a/src/main/java/org/sablecc/sablecc/lexer/Lexer.java +++ b/src/main/java/org/sablecc/sablecc/lexer/Lexer.java @@ -179,10 +179,6 @@ public class Lexer { case 0: tok = new TPkgId(getText(acceptLength), startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; switch(state.ordinal()) { case 1: state = State.PACKAGE; break; @@ -191,10 +187,6 @@ public class Lexer case 1: tok = new TPackage(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; switch(state.ordinal()) { case 0: state = State.PACKAGE; break; @@ -203,122 +195,62 @@ public class Lexer case 2: tok = new TStates(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 3: tok = new THelpers(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 4: tok = new TTokens(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 5: tok = new TIgnored(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 6: tok = new TProductions(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 7: tok = new TAbstract(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 8: tok = new TSyntax(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 9: tok = new TTree(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 10: tok = new TNew(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 11: tok = new TNull(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 12: tok = new TTokenSpecifier(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 13: tok = new TProductionSpecifier(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 14: tok = new TDot(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 15: tok = new TDDot(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 16: tok = new TSemicolon(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; switch(state.ordinal()) { case 0: state = State.NORMAL; break; @@ -328,191 +260,103 @@ public class Lexer case 17: tok = new TEqual(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 18: tok = new TLBkt(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 19: tok = new TRBkt(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 20: tok = new TLPar(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 21: tok = new TRPar(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 22: tok = new TLBrace(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 23: tok = new TRBrace(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 24: tok = new TPlus(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 25: tok = new TMinus(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 26: tok = new TQMark(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 27: tok = new TStar(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 28: tok = new TBar(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 29: tok = new TComma(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 30: tok = new TSlash(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 31: tok = new TArrow(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 32: tok = new TColon(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 33: tok = new TId(getText(acceptLength), startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 34: tok = new TChar(getText(acceptLength), startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 35: tok = new TDecChar(getText(acceptLength), startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 36: tok = new THexChar(getText(acceptLength), startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 37: tok = new TString(getText(acceptLength), startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 38: tok = new TBlank(getText(acceptLength), startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; case 39: tok = new TComment(getText(acceptLength), startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; break; default: throw new LexerException("[" + (startLine + 1) + "," + (startPos + 1) + "] Internal lexer error: invalid accept table entry " + acceptToken + ", current text: " + this.text); } + pushBack(acceptLength); + this.pos = acceptPos; + this.line = acceptLine; + this.cr = acceptCr; return tok; } else diff --git a/src/main/resources/org/sablecc/sablecc/lexer.txt b/src/main/resources/org/sablecc/sablecc/lexer.txt index d9e3e82a7ca7bf64cbdb6125a9d955cb018f3e51..7ca66cac7888a8a30934891d406a8d5c06c38cfa 100644 --- a/src/main/resources/org/sablecc/sablecc/lexer.txt +++ b/src/main/resources/org/sablecc/sablecc/lexer.txt @@ -207,20 +207,12 @@ $ Macro:LexerVariableToken case $0$: tok = new $1$(getText(acceptLength), startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; $ Macro:LexerFixedToken case $0$: tok = new $1$(startLine + 1, startPos + 1); - pushBack(acceptLength); - this.pos = acceptPos; - this.line = acceptLine; - this.cr = acceptCr; $ @@ -250,6 +242,10 @@ Macro:LexerBody default: throw new LexerException("[" + (startLine + 1) + "," + (startPos + 1) + "] Internal lexer error: invalid accept table entry " + acceptToken + ", current text: " + this.text); } + pushBack(acceptLength); + this.pos = acceptPos; + this.line = acceptLine; + this.cr = acceptCr; return tok; } else