@Override @SuppressWarnings("empty-statement") public boolean matchMarker(ByteList marker, boolean indent, boolean withNewline) throws IOException { int matchPos = 0; if (indent) { for (int c = readCursor.at(matchPos); c != RubyYaccLexer.EOF && Character.isWhitespace(c) && c != '\n'; c = readCursor.at(++matchPos)); } for (int i = 0; i < marker.length(); i++) { if (readCursor.at(matchPos) != marker.get(i)) { return false; } matchPos++; } if (withNewline) { int c = readCursor.at(matchPos++); if (c == '\r') { // skip c = readCursor.at(matchPos); } if (c != '\n' && c != RubyYaccLexer.EOF) { return false; } } for (int i = 0; i < matchPos; i++) { readCursor.read(); } return true; }
@Override @SuppressWarnings("empty-statement") public boolean matchMarker(ByteList marker, boolean indent, boolean withNewline) throws IOException { int matchPos = 0; if (indent) { for (int c = readCursor.at(matchPos); c != RubyYaccLexer.EOF && Character.isWhitespace(c) && c != '\n'; c = readCursor.at(++matchPos)); } for (int i = 0; i < marker.length(); i++) { if (readCursor.at(matchPos) != marker.get(i)) { return false; } matchPos++; } if (withNewline) { int c = readCursor.at(matchPos++); if (c == '\r') { // skip c = readCursor.at(matchPos); } if (c != '\n' && c != RubyYaccLexer.EOF) { return false; } } for (int i = 0; i < matchPos; i++) { readCursor.read(); } return true; }
@Override public String getCurrentLine() { int lineOffset = 0; int c; while ((c = readCursor.at(lineOffset - 1)) != '\n' && c != RubyYaccLexer.EOF) { lineOffset--; } String ptr = makePointer(-(lineOffset + 1)); StringBuilder lineBuilder = new StringBuilder(); for (c = readCursor.at(lineOffset); c != '\n' && c != RubyYaccLexer.EOF; c = readCursor.at(++lineOffset)) { lineBuilder.append((char) c); } lineBuilder.append('\n').append(ptr); return lineBuilder.toString(); }
@Override public String getCurrentLine() { int lineOffset = 0; int c; while ((c = readCursor.at(lineOffset - 1)) != '\n' && c != RubyYaccLexer.EOF) { lineOffset--; } String ptr = makePointer(-(lineOffset + 1)); StringBuilder lineBuilder = new StringBuilder(); for (c = readCursor.at(lineOffset); c != '\n' && c != RubyYaccLexer.EOF; c = readCursor.at(++lineOffset)) { lineBuilder.append((char) c); } lineBuilder.append('\n').append(ptr); return lineBuilder.toString(); }
@Override public int read() { return readCursor.read(); }
@Override public int read() { return readCursor.read(); }
@Override public boolean peek(int c) throws IOException { return readCursor.at(0) == c; }
@Override public boolean peek(int c) throws IOException { return readCursor.at(0) == c; }
public int read() { int index = region.length() - 1; if (index < 0) { readCursor = parent; return parent.read(); } int c = 0xff & region.get(index); region.setRealSize(index); return forward(c); } public void unread(int c) {
private ByteList readUntil(char marker, boolean nullIfEnd) throws IOException { ByteList result = new ByteList(128); int c; while ((c = readCursor.read()) != marker && c != RubyYaccLexer.EOF) { result.append(c); } if (nullIfEnd && c == RubyYaccLexer.EOF) { return null; } return result; }
public int read() { int index = region.length() - 1; if (index < 0) { readCursor = parent; return parent.read(); } int c = 0xff & region.get(index); region.setRealSize(index); return forward(c); } public void unread(int c) {
@Override public boolean lastWasBeginOfLine() { int c = readCursor.at(-1); return c == '\n' || c == RubyYaccLexer.EOF; }
public void unread(int c) { if (index > 0 && region[index - 1] == c) { index--; backward(c); } else { readCursor = pushbackCursor; pushbackCursor.unread(c); } } public int at(int offset) {
public void unread(int c) { if (index > 0 && region[index - 1] == c) { index--; backward(c); } else { readCursor = pushbackCursor; pushbackCursor.unread(c); } } public int at(int offset) {
private void backward(int c) { offset--; if (c == '\n') { line--; if (readCursor.at(-1) == '\r') { unread('\r'); } } }
@Override public boolean lastWasBeginOfLine() { int c = readCursor.at(-1); return c == '\n' || c == RubyYaccLexer.EOF; }
private void backward(int c) { offset--; if (c == '\n') { line--; if (readCursor.at(-1) == '\r') { unread('\r'); } } }
private ByteList readUntil(char marker, boolean nullIfEnd) throws IOException { ByteList result = new ByteList(128); int c; while ((c = readCursor.read()) != marker && c != RubyYaccLexer.EOF) { result.append(c); } if (nullIfEnd && c == RubyYaccLexer.EOF) { return null; } return result; }