/** * Read next character from this source * * @return next character to viewed by the source */ @Override public int read() throws IOException { int c; if (bufLength >= 0) { c = buf[bufLength--]; } else { c = wrappedRead(); if (c == -1) return RubyYaccLexer.EOF; } advance(c); if (c == '\n') line++; return c; }
/** * Convenience method to hide exception. If we do hit an exception * we will pretend we EOF'd. * * @return the current char or EOF (at EOF or on error) */ private int wrappedRead() throws IOException { int c = in.read(); // If \r\n then just pass along \n (windows). if (c == '\r') { c = carriageReturn(c); } captureFeature(c); return c; }
/** * Pushes char back onto this source. Note, this also * allows us to push whatever is passes back into the source. * * @param to be put back onto the source */ @Override public void unread(int c) { if (c == RubyYaccLexer.EOF) return; retreat(); if (c == '\n') line--; buf[++bufLength] = (char) c; growBuf(); }
/** * Is the next character equal to 'to' * @param to character to compare against * @return true if the same * @throws IOException */ @Override public boolean peek(int to) throws IOException { // keep value of twoAgo around so we can restore after we unread int captureTwoAgo = twoAgo; int c = read(); unread(c); twoAgo = captureTwoAgo; return c == to; }
@Override public boolean matchMarker(ByteList match, boolean indent, boolean checkNewline) throws IOException { int length = match.length(); ByteList buffer = new ByteList(length + 1); if (indent) { indentLoop(buffer); } if (!matches(match, buffer, length)) return false; return finishMarker(checkNewline, buffer); }
private boolean finishMarker(boolean checkNewline, ByteList buffer) throws IOException { if (!checkNewline) { return true; } int c = read(); if (c == RubyYaccLexer.EOF || c == '\n') { return true; } buffer.append(c); unreadMany(buffer); return false; }
/** * Create a source. * * @param name the name of the source (e.g a filename: foo.rb) * @param content the data of the source * @return the new source */ public static LexerSource getSource(String name, InputStream content, List<String> list, ParserConfiguration configuration) { return new InputStreamLexerSource(name, content, list, configuration.getLineNumber(), configuration.hasExtraPositionInformation()); }
/** * Is the next character equal to 'to' * @param to character to compare against * @return true if the same * @throws IOException */ @Override public boolean peek(int to) throws IOException { // keep value of twoAgo around so we can restore after we unread int captureTwoAgo = twoAgo; int c = read(); unread(c); twoAgo = captureTwoAgo; return c == to; }
@Override public boolean matchMarker(ByteList match, boolean indent, boolean checkNewline) throws IOException { int length = match.length(); ByteList buffer = new ByteList(length + 1); if (indent) { indentLoop(buffer); } if (!matches(match, buffer, length)) return false; return finishMarker(checkNewline, buffer); }
private boolean finishMarker(boolean checkNewline, ByteList buffer) throws IOException { if (!checkNewline) { return true; } int c = read(); if (c == RubyYaccLexer.EOF || c == '\n') { return true; } buffer.append(c); unreadMany(buffer); return false; }
/** * Create a source. * * @param name the name of the source (e.g a filename: foo.rb) * @param content the data of the source * @return the new source */ public static LexerSource getSource(String name, InputStream content, List<String> list, ParserConfiguration configuration) { return new InputStreamLexerSource(name, content, list, configuration.getLineNumber(), configuration.hasExtraPositionInformation()); }
private boolean matches(ByteList match, ByteList buffer, int length) throws IOException { int c; for (int i = 0; i < length; i++) { c = read(); buffer.append(c); if (match.charAt(i) != c) { unreadMany(buffer); return false; } } return true; }
/** * Pushes char back onto this source. Note, this also * allows us to push whatever is passes back into the source. * * @param to be put back onto the source */ @Override public void unread(int c) { if (c == RubyYaccLexer.EOF) return; retreat(); if (c == '\n') line--; buf[++bufLength] = (char) c; growBuf(); }
/** * Convenience method to hide exception. If we do hit an exception * we will pretend we EOF'd. * * @return the current char or EOF (at EOF or on error) */ private int wrappedRead() throws IOException { int c = in.read(); // If \r\n then just pass along \n (windows). if (c == '\r') { c = carriageReturn(c); } captureFeature(c); return c; }
/** * Read next character from this source * * @return next character to viewed by the source */ @Override public int read() throws IOException { int c; if (bufLength >= 0) { c = buf[bufLength--]; } else { c = wrappedRead(); if (c == -1) return RubyYaccLexer.EOF; } advance(c); if (c == '\n') line++; return c; }