final boolean applyNested(Parser<?> parser, ParseContext nestedState) { // nested is either the token-level parser, or the inner scanner of a subpattern. try { if (parser.apply(nestedState)) { set(nestedState.step, at, nestedState.result); return true; } // index on token level is the "at" on character level set(step, nestedState.getIndex(), null); // always copy error because there could be false alarms in the character level. // For example, a "or" parser nested in a "many" failed in one of its branches. copyErrorFrom(nestedState); return false; } finally { trace.setStateAs(nestedState.trace); } }
@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() {