public int op;
public int twoBack;
+ public int line = 0;
+ public int col = 0;
+ public String sourceName = "unknown";
public Number number;
public String string;
else if (c=='o') { if (s.charAt(0)=='d') return DO; }
break;
case 3: switch (s.charAt(0)) {
+ case 'a': if (s.charAt(2)=='d' && s.charAt(1)=='n') return AND; break;
case 'f': if (s.charAt(2)=='r' && s.charAt(1)=='o') return FOR; break;
case 'i': if (s.charAt(2)=='t' && s.charAt(1)=='n') return RESERVED; break;
case 'n': if (s.charAt(2)=='w' && s.charAt(1)=='e') throw new IOException("the new keyword is not permitted in XWT scripts");
longval = Long.parseLong(numString, base);
dval = (double)longval;
} else {
- // FIXME: we're not handling hex/octal fractions... does that matter?
dval = Double.parseDouble(numString);
longval = (long) dval;
if (longval == dval) isInteger = true;
case 'r': c = '\r'; break;
case 't': c = '\t'; break;
case 'v': c = '\u000B'; break;
- default: throw new IOException("\\u and \\0 escapes not currently supported -- use XML entities");
+ case '\\': c = '\\'; break;
+ case 'u': {
+ int v = 0;
+ for(int i=0; i<4; i++) {
+ int ci = in.read();
+ if (!((ci >= '0' && ci <= '9') || (ci >= 'a' && ci <= 'f') || (ci >= 'A' && ci <= 'F')))
+ throw new IOException("illegal character '" + ((char)c) + "' in \\u unicode escape sequence");
+ v = (v << 8) | Integer.parseInt(ci + "", 16);
+ }
+ c = (char)v;
+ break;
+ }
+ default:
+ // just use the character that was escaped
+ break;
}
}
if (stringBuf != null) stringBuf.append((char) c);
do {
if (op != EOL) twoBack = op;
op = _getToken();
- } while (op == EOL); // FIXME
+ if (op == EOL) { line++; col = 0; }
+ } while (op == EOL);
return op;
}
int c;
do { if ((c = in.read()) == '\n') break; } while (isWhiteSpace(c) || c == '\n');
if (c == -1) return -1;
- if (c == '\\' && in.peek() == 'u') throw new IOException("\\u and \\0 escapes not currently supported -- use XML entities");
- if (Character.isJavaIdentifierStart((char)c)) return getIdentifier(c);
+ if (c == '\\' || Character.isJavaIdentifierStart((char)c)) return getIdentifier(c);
if (isDigit(c) || (c == '.' && isDigit(in.peek()))) return getNumber(c);
if (c == '"' || c == '\'') return getString(c);
switch (c) {
}
if (c == -1) throw new IOException("msg.unterminated.comment");
return getToken(); // `goto retry'
- default: throw new IOException("illegal character: " + c);
+ default: throw new IOException("illegal character: " + ((char)c));
}
}
- private static class SmartReader {
+ private class SmartReader {
PushbackReader reader = null;
int lastread = -1;
public SmartReader(Reader r) { reader = new PushbackReader(r); }
- public void unread() throws IOException {
- reader.unread(lastread);
+ public void unread() throws IOException { unread((char)lastread); }
+ public void unread(char c) throws IOException {
+ reader.unread(c);
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; }
public int read() throws IOException {
lastread = reader.read();
if (accumulator != null) accumulator.append((char)lastread);
+ if (lastread != '\n' && lastread != '\r') col++;
return lastread;
}
- // FIXME: could be much more efficient
+ // FEATURE: could be much more efficient
StringBuffer accumulator = null;
public void startString() {
accumulator = new StringBuffer();