// Token Subtype Handlers /////////////////////////////////////////////////////////
+ // FIXME: convert to a string switch
private int getKeyword(String s) throws IOException {
char c;
switch (s.length()) {
case 'n': return s.equals("null") ? NULL : -1;
case 't': c=s.charAt(3);
if (c=='e') { if (s.charAt(2)=='u' && s.charAt(1)=='r') return TRUE; }
- else if (c=='s') { if (s.charAt(2)=='i' && s.charAt(1)=='h') return THIS; }
return -1;
case 'w': if (s.equals("with")) return RESERVED; else return -1;
case 'v': if (s.equals("void")) return RESERVED; else return -1;
}
}
- if (!isInteger) this.number = new Double(dval);
- else if (Byte.MIN_VALUE <= longval && longval <= Byte.MAX_VALUE) this.number = new Byte((byte)longval);
- else if (Short.MIN_VALUE <= longval && longval <= Short.MAX_VALUE) this.number = new Short((short)longval);
- else if (Integer.MIN_VALUE <= longval && longval <= Integer.MAX_VALUE) this.number = new Integer((int)longval);
- else this.number = new Double(longval);
+ if (!isInteger) this.number = JS.N(dval);
+ else this.number = JS.N(longval);
return NUMBER;
}
public void unread() throws IOException { unread((char)lastread); }
public void unread(char c) throws IOException {
reader.unread(c);
+ if(c == '\n') col = -1;
+ else col--;
if (accumulator != null) accumulator.setLength(accumulator.length() - 1);
}
public boolean match(char c) throws IOException { if (peek() == c) { reader.read(); return true; } else return false; }
lastread = reader.read();
if (accumulator != null) accumulator.append((char)lastread);
if (lastread != '\n' && lastread != '\r') col++;
- if (lastread == '\n') { parserLine = ++line; col = 0; }
+ if (lastread == '\n') {
+ // col is -1 if we just unread a newline, this is sort of ugly
+ if (col != -1) parserLine = ++line;
+ col = 0;
+ }
return lastread;
}
accumulator.append((char)lastread);
}
public String getString() throws IOException {
- String ret = accumulator.toString();
+ String ret = accumulator.toString().intern();
accumulator = null;
return ret;
}