Skip to content
Snippets Groups Projects
Commit 7e1e5ead authored by dgelessus's avatar dgelessus
Browse files

Make generated Lexer.State an enum

Mostly so that the values have readable toString representations.
parent fbaac47b
No related branches found
No related tags found
No related merge requests found
Pipeline #116557 passed
...@@ -286,18 +286,14 @@ public class GenLexer extends AnalysisAdapter ...@@ -286,18 +286,14 @@ public class GenLexer extends AnalysisAdapter
if(ids.stateList.size() > 0) if(ids.stateList.size() > 0)
{ {
for(ListIterator<String> i = ids.stateList.listIterator(); i.hasNext();) for (String s : ids.stateList)
{ {
String s = i.next(); macros.apply(file, "LexerStateBody", new String[] {s});
macros.apply(file, "LexerStateBody",
new String[] {s, "" + i.previousIndex()});
} }
} }
else else
{ {
macros.apply(file, "LexerStateBody", macros.apply(file, "LexerStateBody", new String[] {"INITIAL"});
new String[] {"INITIAL", "" + 0});
} }
macros.apply(file, "LexerStateTail"); macros.apply(file, "LexerStateTail");
......
...@@ -110,8 +110,8 @@ public class Lexer implements ITokenListContainer ...@@ -110,8 +110,8 @@ public class Lexer implements ITokenListContainer
int accept_pos = -1; int accept_pos = -1;
int accept_line = -1; int accept_line = -1;
int[][][] gotoTable = Lexer.gotoTable[this.state.id()]; int[][][] gotoTable = Lexer.gotoTable[this.state.ordinal()];
int[] accept = Lexer.accept[this.state.id()]; int[] accept = Lexer.accept[this.state.ordinal()];
this.text.setLength(0); this.text.setLength(0);
while(true) while(true)
...@@ -212,7 +212,7 @@ public class Lexer implements ITokenListContainer ...@@ -212,7 +212,7 @@ public class Lexer implements ITokenListContainer
pushBack(accept_length); pushBack(accept_length);
this.pos = accept_pos; this.pos = accept_pos;
this.line = accept_line; this.line = accept_line;
switch(state.id()) switch(state.ordinal())
{ {
case 1: state = State.PACKAGE; break; case 1: state = State.PACKAGE; break;
} }
...@@ -226,7 +226,7 @@ public class Lexer implements ITokenListContainer ...@@ -226,7 +226,7 @@ public class Lexer implements ITokenListContainer
pushBack(accept_length); pushBack(accept_length);
this.pos = accept_pos; this.pos = accept_pos;
this.line = accept_line; this.line = accept_line;
switch(state.id()) switch(state.ordinal())
{ {
case 0: state = State.PACKAGE; break; case 0: state = State.PACKAGE; break;
} }
...@@ -380,7 +380,7 @@ public class Lexer implements ITokenListContainer ...@@ -380,7 +380,7 @@ public class Lexer implements ITokenListContainer
pushBack(accept_length); pushBack(accept_length);
this.pos = accept_pos; this.pos = accept_pos;
this.line = accept_line; this.line = accept_line;
switch(state.id()) switch(state.ordinal())
{ {
case 0: state = State.NORMAL; break; case 0: state = State.NORMAL; break;
case 1: state = State.NORMAL; break; case 1: state = State.NORMAL; break;
...@@ -995,21 +995,15 @@ public class Lexer implements ITokenListContainer ...@@ -995,21 +995,15 @@ public class Lexer implements ITokenListContainer
};*/ };*/
public static class State public enum State
{ {
public final static State NORMAL = new State(0); NORMAL,
public final static State PACKAGE = new State(1); PACKAGE,
;
private int id;
private State(int id)
{
this.id = id;
}
public int id() public int id()
{ {
return this.id; return this.ordinal();
} }
} }
......
...@@ -134,8 +134,8 @@ public class Lexer implements ITokenListContainer ...@@ -134,8 +134,8 @@ public class Lexer implements ITokenListContainer
int accept_pos = -1; int accept_pos = -1;
int accept_line = -1; int accept_line = -1;
int[][][] gotoTable = Lexer.gotoTable[this.state.id()]; int[][][] gotoTable = Lexer.gotoTable[this.state.ordinal()];
int[] accept = Lexer.accept[this.state.id()]; int[] accept = Lexer.accept[this.state.ordinal()];
this.text.setLength(0); this.text.setLength(0);
while(true) while(true)
...@@ -256,7 +256,7 @@ Macro:LexerFixedToken ...@@ -256,7 +256,7 @@ Macro:LexerFixedToken
$ $
Macro:TokenSwitchHeader Macro:TokenSwitchHeader
switch(state.id()) switch(state.ordinal())
{ {
$ $
...@@ -382,28 +382,22 @@ Macro:LexerAcceptTail ...@@ -382,28 +382,22 @@ Macro:LexerAcceptTail
$ $
Macro:LexerStateHeader Macro:LexerStateHeader
public static class State public enum State
{ {
$ $
Macro:LexerStateBody Macro:LexerStateBody
public final static State $0$ = new State($1$); $0$,
$ $
Macro:LexerStateTail Macro:LexerStateTail
;
private int id;
private State(int id)
{
this.id = id;
}
public int id() public int id()
{ {
return this.id; return this.ordinal();
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment