Skip to content
Snippets Groups Projects
Commit 392709d7 authored by dgelessus's avatar dgelessus
Browse files

Prepare sharing code between cases of generated Lexer accept switch

parent 14cdedba
No related branches found
No related tags found
No related merge requests found
...@@ -174,11 +174,11 @@ public class Lexer ...@@ -174,11 +174,11 @@ public class Lexer
{ {
if(acceptState != -1) if(acceptState != -1)
{ {
Token tok;
switch(acceptToken) switch(acceptToken)
{ {
case 0: case 0:
{ tok = new TPkgId(getText(acceptLength), startLine + 1, startPos + 1);
Token tok = new TPkgId(getText(acceptLength), startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
...@@ -187,11 +187,10 @@ public class Lexer ...@@ -187,11 +187,10 @@ public class Lexer
{ {
case 1: state = State.PACKAGE; break; case 1: state = State.PACKAGE; break;
} }
return tok; break;
}
case 1: case 1:
{ tok = new TPackage(startLine + 1, startPos + 1);
Token tok = new TPackage(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
...@@ -200,137 +199,122 @@ public class Lexer ...@@ -200,137 +199,122 @@ public class Lexer
{ {
case 0: state = State.PACKAGE; break; case 0: state = State.PACKAGE; break;
} }
return tok; break;
}
case 2: case 2:
{ tok = new TStates(startLine + 1, startPos + 1);
Token tok = new TStates(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 3: case 3:
{ tok = new THelpers(startLine + 1, startPos + 1);
Token tok = new THelpers(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 4: case 4:
{ tok = new TTokens(startLine + 1, startPos + 1);
Token tok = new TTokens(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 5: case 5:
{ tok = new TIgnored(startLine + 1, startPos + 1);
Token tok = new TIgnored(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 6: case 6:
{ tok = new TProductions(startLine + 1, startPos + 1);
Token tok = new TProductions(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 7: case 7:
{ tok = new TAbstract(startLine + 1, startPos + 1);
Token tok = new TAbstract(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 8: case 8:
{ tok = new TSyntax(startLine + 1, startPos + 1);
Token tok = new TSyntax(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 9: case 9:
{ tok = new TTree(startLine + 1, startPos + 1);
Token tok = new TTree(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 10: case 10:
{ tok = new TNew(startLine + 1, startPos + 1);
Token tok = new TNew(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 11: case 11:
{ tok = new TNull(startLine + 1, startPos + 1);
Token tok = new TNull(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 12: case 12:
{ tok = new TTokenSpecifier(startLine + 1, startPos + 1);
Token tok = new TTokenSpecifier(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 13: case 13:
{ tok = new TProductionSpecifier(startLine + 1, startPos + 1);
Token tok = new TProductionSpecifier(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 14: case 14:
{ tok = new TDot(startLine + 1, startPos + 1);
Token tok = new TDot(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 15: case 15:
{ tok = new TDDot(startLine + 1, startPos + 1);
Token tok = new TDDot(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 16: case 16:
{ tok = new TSemicolon(startLine + 1, startPos + 1);
Token tok = new TSemicolon(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
...@@ -340,216 +324,196 @@ public class Lexer ...@@ -340,216 +324,196 @@ public class Lexer
case 0: state = State.NORMAL; break; case 0: state = State.NORMAL; break;
case 1: state = State.NORMAL; break; case 1: state = State.NORMAL; break;
} }
return tok; break;
}
case 17: case 17:
{ tok = new TEqual(startLine + 1, startPos + 1);
Token tok = new TEqual(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 18: case 18:
{ tok = new TLBkt(startLine + 1, startPos + 1);
Token tok = new TLBkt(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 19: case 19:
{ tok = new TRBkt(startLine + 1, startPos + 1);
Token tok = new TRBkt(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 20: case 20:
{ tok = new TLPar(startLine + 1, startPos + 1);
Token tok = new TLPar(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 21: case 21:
{ tok = new TRPar(startLine + 1, startPos + 1);
Token tok = new TRPar(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 22: case 22:
{ tok = new TLBrace(startLine + 1, startPos + 1);
Token tok = new TLBrace(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 23: case 23:
{ tok = new TRBrace(startLine + 1, startPos + 1);
Token tok = new TRBrace(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 24: case 24:
{ tok = new TPlus(startLine + 1, startPos + 1);
Token tok = new TPlus(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 25: case 25:
{ tok = new TMinus(startLine + 1, startPos + 1);
Token tok = new TMinus(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 26: case 26:
{ tok = new TQMark(startLine + 1, startPos + 1);
Token tok = new TQMark(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 27: case 27:
{ tok = new TStar(startLine + 1, startPos + 1);
Token tok = new TStar(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 28: case 28:
{ tok = new TBar(startLine + 1, startPos + 1);
Token tok = new TBar(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 29: case 29:
{ tok = new TComma(startLine + 1, startPos + 1);
Token tok = new TComma(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 30: case 30:
{ tok = new TSlash(startLine + 1, startPos + 1);
Token tok = new TSlash(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 31: case 31:
{ tok = new TArrow(startLine + 1, startPos + 1);
Token tok = new TArrow(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 32: case 32:
{ tok = new TColon(startLine + 1, startPos + 1);
Token tok = new TColon(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 33: case 33:
{ tok = new TId(getText(acceptLength), startLine + 1, startPos + 1);
Token tok = new TId(getText(acceptLength), startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 34: case 34:
{ tok = new TChar(getText(acceptLength), startLine + 1, startPos + 1);
Token tok = new TChar(getText(acceptLength), startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 35: case 35:
{ tok = new TDecChar(getText(acceptLength), startLine + 1, startPos + 1);
Token tok = new TDecChar(getText(acceptLength), startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 36: case 36:
{ tok = new THexChar(getText(acceptLength), startLine + 1, startPos + 1);
Token tok = new THexChar(getText(acceptLength), startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 37: case 37:
{ tok = new TString(getText(acceptLength), startLine + 1, startPos + 1);
Token tok = new TString(getText(acceptLength), startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 38: case 38:
{ tok = new TBlank(getText(acceptLength), startLine + 1, startPos + 1);
Token tok = new TBlank(getText(acceptLength), startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
case 39: case 39:
{ tok = new TComment(getText(acceptLength), startLine + 1, startPos + 1);
Token tok = new TComment(getText(acceptLength), startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
this.cr = acceptCr; this.cr = acceptCr;
return tok; break;
}
default:
throw new LexerException("[" + (startLine + 1) + "," + (startPos + 1) + "] Internal lexer error: invalid accept table entry " + acceptToken + ", current text: " + this.text);
} }
return tok;
} }
else else
{ {
......
...@@ -198,6 +198,7 @@ public class Lexer ...@@ -198,6 +198,7 @@ public class Lexer
{ {
if(acceptState != -1) if(acceptState != -1)
{ {
Token tok;
switch(acceptToken) switch(acceptToken)
{ {
...@@ -205,8 +206,7 @@ $ ...@@ -205,8 +206,7 @@ $
Macro:LexerVariableToken Macro:LexerVariableToken
case $0$: case $0$:
{ tok = new $1$(getText(acceptLength), startLine + 1, startPos + 1);
Token tok = new $1$(getText(acceptLength), startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
...@@ -216,8 +216,7 @@ $ ...@@ -216,8 +216,7 @@ $
Macro:LexerFixedToken Macro:LexerFixedToken
case $0$: case $0$:
{ tok = new $1$(startLine + 1, startPos + 1);
Token tok = new $1$(startLine + 1, startPos + 1);
pushBack(acceptLength); pushBack(acceptLength);
this.pos = acceptPos; this.pos = acceptPos;
this.line = acceptLine; this.line = acceptLine;
...@@ -242,13 +241,16 @@ Macro:TokenSwitchTail ...@@ -242,13 +241,16 @@ Macro:TokenSwitchTail
$ $
Macro:LexerTokenTail Macro:LexerTokenTail
return tok; break;
}
$ $
Macro:LexerBody Macro:LexerBody
default:
throw new LexerException("[" + (startLine + 1) + "," + (startPos + 1) + "] Internal lexer error: invalid accept table entry " + acceptToken + ", current text: " + this.text);
} }
return tok;
} }
else else
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment