/* Generated By:JavaCC: Do not edit this line. ParamStringScanner.java */
package org.openstreetmap.josm.plugins.roadsigns.javacc;
import java.util.ArrayList;
import java.util.List;
import org.openstreetmap.josm.plugins.roadsigns.ParametrizedString.Prm;
import org.openstreetmap.josm.plugins.roadsigns.ParametrizedString.Str;
import org.openstreetmap.josm.plugins.roadsigns.ParametrizedString.StringOrParameter;
public class ParamStringScanner implements ParamStringScannerConstants {
public static List<StringOrParameter> parseIt(String s) throws ParseException {
ParamStringScanner parser = new ParamStringScanner(new java.io.StringReader(s));
return parser.parse();
}
final public List<StringOrParameter> parse() throws ParseException {
String val;
Token t;
List<StringOrParameter> lst = new ArrayList<>();
label_1:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case ID:
case ESC:
case REST:
;
break;
default:
jj_la1[0] = jj_gen;
break label_1;
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case ID:
val = id();
lst.add(new Prm(val));
break;
case ESC:
val = esc();
lst.add(new Str(val));
break;
case REST:
t = jj_consume_token(REST);
lst.add(new Str(t.image));
break;
default:
jj_la1[1] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
{if (true) return lst;}
throw new Error("Missing return statement in function");
}
final public String id() throws ParseException {
Token t;
String ret;
t = jj_consume_token(ID);
ret = t.image;
ret = ret.substring(1);
if (ret.startsWith("{")) {
ret = ret.substring(1, ret.length()-1);
}
{if (true) return ret;}
throw new Error("Missing return statement in function");
}
final public String esc() throws ParseException {
Token t;
t = jj_consume_token(ESC);
if (t.image.equals("\\\\")) {
{if (true) return "\\";}
} else if (t.image.equals("\\$")) {
{if (true) return "$";}
} else
{if (true) throw new AssertionError();}
throw new Error("Missing return statement in function");
}
/** Generated Token Manager. */
public ParamStringScannerTokenManager token_source;
SimpleCharStream jj_input_stream;
/** Current token. */
public Token token;
/** Next token. */
public Token jj_nt;
private int jj_ntk;
private int jj_gen;
final private int[] jj_la1 = new int[2];
static private int[] jj_la1_0;
static {
jj_la1_init_0();
}
private static void jj_la1_init_0() {
jj_la1_0 = new int[] {0xe,0xe,};
}
/** Constructor with InputStream. */
public ParamStringScanner(java.io.InputStream stream) {
this(stream, null);
}
/** Constructor with InputStream and supplied encoding */
public ParamStringScanner(java.io.InputStream stream, String encoding) {
try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
token_source = new ParamStringScannerTokenManager(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 2; i++) jj_la1[i] = -1;
}
/** Reinitialise. */
public void ReInit(java.io.InputStream stream) {
ReInit(stream, null);
}
/** Reinitialise. */
public void ReInit(java.io.InputStream stream, String encoding) {
try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
token_source.ReInit(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 2; i++) jj_la1[i] = -1;
}
/** Constructor. */
public ParamStringScanner(java.io.Reader stream) {
jj_input_stream = new SimpleCharStream(stream, 1, 1);
token_source = new ParamStringScannerTokenManager(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 2; i++) jj_la1[i] = -1;
}
/** Reinitialise. */
public void ReInit(java.io.Reader stream) {
jj_input_stream.ReInit(stream, 1, 1);
token_source.ReInit(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 2; i++) jj_la1[i] = -1;
}
/** Constructor with generated Token Manager. */
public ParamStringScanner(ParamStringScannerTokenManager tm) {
token_source = tm;
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 2; i++) jj_la1[i] = -1;
}
/** Reinitialise. */
public void ReInit(ParamStringScannerTokenManager tm) {
token_source = tm;
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 2; i++) jj_la1[i] = -1;
}
private Token jj_consume_token(int kind) throws ParseException {
Token oldToken;
if ((oldToken = token).next != null) token = token.next;
else token = token.next = token_source.getNextToken();
jj_ntk = -1;
if (token.kind == kind) {
jj_gen++;
return token;
}
token = oldToken;
jj_kind = kind;
throw generateParseException();
}
/** Get the next Token. */
final public Token getNextToken() {
if (token.next != null) token = token.next;
else token = token.next = token_source.getNextToken();
jj_ntk = -1;
jj_gen++;
return token;
}
/** Get the specific Token. */
final public Token getToken(int index) {
Token t = token;
for (int i = 0; i < index; i++) {
if (t.next != null) t = t.next;
else t = t.next = token_source.getNextToken();
}
return t;
}
private int jj_ntk() {
if ((jj_nt=token.next) == null)
return (jj_ntk = (token.next=token_source.getNextToken()).kind);
else
return (jj_ntk = jj_nt.kind);
}
private java.util.List<int[]> jj_expentries = new java.util.ArrayList<>();
private int[] jj_expentry;
private int jj_kind = -1;
/** Generate ParseException. */
public ParseException generateParseException() {
jj_expentries.clear();
boolean[] la1tokens = new boolean[4];
if (jj_kind >= 0) {
la1tokens[jj_kind] = true;
jj_kind = -1;
}
for (int i = 0; i < 2; i++) {
if (jj_la1[i] == jj_gen) {
for (int j = 0; j < 32; j++) {
if ((jj_la1_0[i] & (1<<j)) != 0) {
la1tokens[j] = true;
}
}
}
}
for (int i = 0; i < 4; i++) {
if (la1tokens[i]) {
jj_expentry = new int[1];
jj_expentry[0] = i;
jj_expentries.add(jj_expentry);
}
}
int[][] exptokseq = new int[jj_expentries.size()][];
for (int i = 0; i < jj_expentries.size(); i++) {
exptokseq[i] = (int[])jj_expentries.get(i);
}
return new ParseException(token, exptokseq, tokenImage);
}
/** Enable tracing. */
final public void enable_tracing() {
}
/** Disable tracing. */
final public void disable_tracing() {
}
}