@Override boolean apply(ParseContext ctxt) { for (Parser<?> p : parsers) { if (!p.apply(ctxt)) return false; } return true; } @Override public String toString() {
/** Runs {@code parser} with error recording suppressed. */ final boolean withErrorSuppressed(Parser<?> parser) { boolean oldValue = errorSuppressed; errorSuppressed = true; boolean ok = parser.apply(this); errorSuppressed = oldValue; return ok; }
final boolean repeat(Parser<?> parser, int n) { for (int i = 0; i < n; i++) { if (!parser.apply(this)) return false; } return true; }
/** Runs {@code parser} with error recording suppressed. */ final boolean applyAsDelimiter(Parser<?> parser) { ErrorType oldValue = overrideErrorType; overrideErrorType = ErrorType.DELIMITING; int oldStep = step; boolean ok = parser.apply(this); if (ok) step = oldStep; overrideErrorType = oldValue; return ok; }
@Override boolean apply(ParseContext ctxt) { int at = ctxt.at; int step = ctxt.step; boolean r = Parser.this.apply(ctxt); if (r) ctxt.step = step + 1; else ctxt.setAt(step, at); return r; } @Override public String toString() {
@Override boolean apply(ParseContext ctxt) { int step = ctxt.step; int at = ctxt.at; boolean ok = Parser.this.apply(ctxt); if (ok) ctxt.setAt(step, at); return ok; } @Override public String toString() {
private boolean repeatAtMost(int times, ParseContext ctxt) { for (int i = 0; i < times; i++) { int physical = ctxt.at; int logical = ctxt.step; if (!parser.apply(ctxt)) { ctxt.setAt(logical, physical); return true; } } return true; } }
@Override boolean apply(ParseContext ctxt) { return deref().apply(ctxt); } private Parser<T> deref() {
@Override boolean apply(ParseContext ctxt) { return Parser.this.apply(ctxt) && runNext(ctxt); } @Override public String toString() {
final <T> boolean repeat( Parser<? extends T> parser, int n, Collection<T> collection) { for (int i = 0; i < n; i++) { if (!parser.apply(this)) return false; collection.add(parser.getReturn(this)); } return true; }
private boolean applyMany(ParseContext ctxt) { int physical = ctxt.at; int logical = ctxt.step; for (;;logical = ctxt.step) { if (!parser.apply(ctxt)) { ctxt.setAt(logical, physical); return true; } int at2 = ctxt.at; if (physical == at2) return true; physical = at2; } } }
private boolean runNext(ParseContext state) { T from = Parser.this.getReturn(state); return map.apply(from).apply(state); } };
@Override boolean apply(final ParseContext ctxt) { final boolean r = Parser.this.apply(ctxt); if (r) { ctxt.result = map.apply(Parser.this.getReturn(ctxt)); } return r; } @Override public String toString() {
@Override boolean apply(ParseContext ctxt) { final Object ret = ctxt.result; final int step = ctxt.step; final int at = ctxt.at; if (ctxt.withErrorSuppressed(Parser.this)) { Parser<? extends R> parser = consequence.apply(Parser.this.getReturn(ctxt)); return parser.apply(ctxt); } ctxt.set(step, at, ret); return alternative.apply(ctxt); } @Override public String toString() {
@Override boolean apply(ParseContext ctxt) { int begin = ctxt.getIndex(); if (!Parser.this.apply(ctxt)) { return false; } ctxt.result = ctxt.source.subSequence(begin, ctxt.getIndex()).toString(); return true; } @Override public String toString() {
@Override boolean apply(ParseContext ctxt) { final Object result = ctxt.result; final int at = ctxt.at; final int step = ctxt.step; final int errorIndex = ctxt.errorIndex(); if (Parser.this.apply(ctxt)) return true; if (ctxt.errorIndex() != errorIndex) return false; ctxt.set(step, at, result); return fallback.apply(ctxt); } @Override public String toString() {
@Override boolean apply(ParseContext ctxt) { ArrayList<T> list = Lists.arrayList(array.length); for (Parser<? extends T> parser : array) { if (!parser.apply(ctxt)) return false; list.add(parser.getReturn(ctxt)); } ctxt.result = list; return true; }
@Override boolean apply(ParseContext ctxt) { int begin = ctxt.getIndex(); if (!Parser.this.apply(ctxt)) { return false; } String source = ctxt.source.subSequence(begin, ctxt.getIndex()).toString(); @SuppressWarnings("unchecked") WithSource<T> withSource = new WithSource<T>((T) ctxt.result, source); ctxt.result = withSource; return true; } @Override public String toString() {
@Override boolean apply(ParseContext ctxt) { int from = ctxt.at; if (!outer.apply(ctxt)) return false; ScannerState innerState = new ScannerState( ctxt.module, ctxt.characters(), from, ctxt.at, ctxt.locator, ctxt.result); ctxt.getTrace().startFresh(innerState); innerState.getTrace().setStateAs(ctxt.getTrace()); return ctxt.applyNested(inner, innerState); } @Override public String toString() {