Example #1
0
  public Object read(Lexer in, int ch, int count) throws java.io.IOException, SyntaxException {
    if (!(in instanceof LispReader)) return super.read(in, ch, count);
    int endChar = ch == '<' ? '>' : -2;
    LispReader reader = (LispReader) in;
    int startPos = in.tokenBufferLength;
    InPort port = in.getPort();
    ReadTable rtable = ReadTable.getCurrent();
    char saveReadState = '\0';
    in.tokenBufferAppend(ch);
    int c = ch;
    int prev;
    if (port instanceof InPort) {
      saveReadState = ((InPort) port).readState;
      ((InPort) port).readState = (char) ch;
    }
    try {
      boolean got_open_square = false;
      for (; ; ) {
        int next;

        prev = c;

        if (port.pos < port.limit && prev != '\n') c = port.buffer[port.pos++];
        else c = port.read();
        if (c == '\\') {
          in.tokenBufferAppend(LispReader.TOKEN_ESCAPE_CHAR);
          reader.seenEscapes = true;
        } else if (c == endChar && !got_open_square) {
          reader.readToken('>', rtable);
          break;
        } else {
          int kind;
          if ((!got_open_square && c == '[' && true == (got_open_square = true))
              || (got_open_square && c == ']' && false == (got_open_square = false))
              || ((kind = rtable.lookup(c).getKind()) == ReadTable.CONSTITUENT
                  || kind == ReadTable.NON_TERMINATING_MACRO)) {
            in.tokenBufferAppend(c);
            continue;
          } else {
            in.unread(c);
            break;
          }
        }
      }
      return reader.handleToken(startPos, rtable);
    } finally {
      in.tokenBufferLength = startPos;
      if (port instanceof InPort) ((InPort) port).readState = saveReadState;
    }
  }
Example #2
0
 public int read(char[] buf, int offset, int length) throws java.io.IOException {
   return port.read(buf, offset, length);
 }
Example #3
0
 public int read() throws java.io.IOException {
   return port.read();
 }
Example #4
0
 /**
  * Check if the next character matches a given character.
  *
  * @param ch The character to match against.
  * @return if the character read matches On a match, the position is advanced following that
  *     character.
  */
 public boolean checkNext(char ch) throws java.io.IOException {
   int r = port.read();
   if (r == ch) return true;
   if (r >= 0) port.unread_quick();
   return false;
 }