int expectNumber() { Object t = peek(); if (!(t instanceof String) || !Pattern.matches("[0-9]+$", (String) t)) { throw new IllegalArgumentException("expected number at " + pos); } advance(); return Integer.parseInt((String) t); } boolean accept(Token tok) {
int expectNumber() { Object t = peek(); if (!(t instanceof String) || !Pattern.matches("[0-9]+$", (String) t)) { throw new IllegalArgumentException("expected number at " + pos); } advance(); return Integer.parseInt((String) t); } boolean accept(Token tok) {
void expect(Token tok) throws IllegalArgumentException { Object actual = peek(); if (actual != tok) { throw new IllegalArgumentException("expected " + tok + " at " + pos); } advance(); } boolean accept(Token tok) {
private static void node(Reader r, Tree t) throws IllegalArgumentException { Object actual = r.peek(); if (actual instanceof Token) { throw new IllegalArgumentException("expected name at " + r.pos); } r.advance(); Tree subtree = new Tree(); t.children.put((String) actual, subtree); if (r.accept(Token.LBRACE)) { list(r, subtree); r.expect(Token.RBRACE); } if (r.accept(Token.QLBRACE)) { subtree.range = parseRange(r); r.expect(Token.QRBRACE); } } static Range parseRange(Reader r) {
private static void node(Reader r, Tree t) throws IllegalArgumentException { Object actual = r.peek(); if (actual instanceof Token) { throw new IllegalArgumentException("expected name at " + r.pos); } r.advance(); Tree subtree = new Tree(); t.children.put((String) actual, subtree); if (r.accept(Token.LBRACE)) { list(r, subtree); r.expect(Token.RBRACE); } if (r.accept(Token.QLBRACE)) { subtree.range = parseRange(r); r.expect(Token.QRBRACE); } } static Range parseRange(Reader r) {
private static void node(Reader r, Tree t) throws IllegalArgumentException { Object actual = r.peek(); if (actual instanceof Token) { throw new IllegalArgumentException("expected name at " + r.pos); } r.advance(); Tree subtree = new Tree(); t.children.put((String) actual, subtree); if (r.accept(Token.LBRACE)) { list(r, subtree); r.expect(Token.RBRACE); } } private enum Token {COMMA, LBRACE, RBRACE, EOF}
void expect(Token tok) throws IllegalArgumentException { Object actual = peek(); if (actual != tok) { throw new IllegalArgumentException("expected " + tok + " at " + pos); } advance(); } int expectNumber() {
boolean accept(Token tok) { if (peek() == tok) { advance(); return true; } else { return false; } } }
void expect(Token tok) throws IllegalArgumentException { Object actual = peek(); if (actual != tok) { throw new IllegalArgumentException("expected " + tok + " at " + pos); } advance(); } int expectNumber() {
boolean accept(Token tok) { if (peek() == tok) { advance(); return true; } else { return false; } } }
boolean accept(Token tok) { if (peek() == tok) { advance(); return true; } else { return false; } } }