Example #1
0
  private void parseNextTokens() throws IOException {
    int startOffset = scanner.currentParseOffset();
    buffer.setLength(0);
    outer_loop:
    while (!scanner.eof() && tokens.isEmpty()) {
      char c = scanner.read();
      switch (c) {
        case '=':
          bufferToTokens(startOffset, true);
          tokens.add(new Token(c, scanner.currentParseOffset() - 1, TokenType.EQUALS));
          return;
        case ' ': /* whitespace */
        case '\t':
          bufferToTokens(startOffset, true);
          if (skipWhitespace) {
            while (!scanner.eof()) {
              c = scanner.peek();
              if (c != ' ' && c != '\t') {
                continue outer_loop;
              }
              scanner.read();
            }
            return;
          }
          startOffset = scanner.currentParseOffset() - 1;
          buffer.append(c);
          outer:
          while (!scanner.eof()) {
            c = scanner.peek();
            switch (c) {
              case ' ':
              case '\t':
                buffer.append(scanner.read());
                break;
              default:
                break outer;
            }
          }
          tokens.add(new Token(buffer, startOffset, TokenType.WHITESPACE));
          return;
        case '(':
          bufferToTokens(startOffset, true);
          tokens.add(new Token(c, scanner.currentParseOffset() - 1, TokenType.PARENS_OPEN));
          return;
        case ')':
          bufferToTokens(startOffset, true);
          tokens.add(new Token(c, scanner.currentParseOffset() - 1, TokenType.PARENS_CLOSE));
          return;
      }

      buffer.append(c);
      if (bufferToTokens(startOffset, false)) {
        return;
      }
    }
    bufferToTokens(startOffset, true);
  }
Example #2
0
 @Override
 public boolean eof() {
   try {
     return currentToken() == null && scanner.eof();
   } catch (IOException e) {
     throw new ParseException(e.getMessage(), scanner.currentParseOffset(), e);
   }
 }
Example #3
0
  private Token currentToken() {

    if (tokens.isEmpty()) {
      try {
        if (scanner.eof()) {
          return null;
        }
        parseNextTokens();
      } catch (IOException e) {
        throw new ParseException(e.getMessage(), scanner.currentParseOffset(), e);
      }

      if (tokens.isEmpty()) {
        return null;
      }
    }
    return tokens.get(0);
  }