@Override <T> T run(Parser<T> parser, CharSequence source) { return new ScannerState(source).run(parser.followedBy(Parsers.EOF)); } },
@Override <T> T run(Parser<T> parser, CharSequence source) { ScannerState state = new ScannerState(source); state.enableTrace("root"); return state.run(parser.followedBy(Parsers.EOF)); } }
/** * Parses {@code source}. * * @param source the source string * @param moduleName the name of the module, this name appears in error message * @return the result * @deprecated Please use {@link #parse(CharSequence)} instead. */ @Deprecated public final T parse(CharSequence source, String moduleName) { return new ScannerState(moduleName, source, 0, new SourceLocator(source)) .run(followedBy(Parsers.EOF)); }
/** * Parses {@code source} and returns a {@link ParseTree} corresponding to the syntactical * structure of the input. Only {@link #label labeled} parser nodes are represented in the parse * tree. * * <p>If parsing failed, {@link ParserException#getParseTree()} can be inspected for the parse * tree at error location. * * @since 2.3 */ public final ParseTree parseTree(CharSequence source) { ScannerState state = new ScannerState(source); state.enableTrace("root"); state.run(this.followedBy(Parsers.EOF)); return state.buildParseTree(); }
@Override boolean apply(ParseContext ctxt) { if (!start.apply(ctxt)) return false; int betweenAt = ctxt.at; // try to match the end of the sequence beginning from the very end giving a chance to empty parser to be matched // (see https://github.com/abailly/jparsec/issues/25) ctxt.at = ctxt.source.length(); boolean r2 = end.apply(ctxt); int endAt = ctxt.at; while ( !r2 && ctxt.at >=betweenAt ) { ctxt.at--; endAt = ctxt.at; r2 = end.apply(ctxt); } if (!r2) return false; ParseContext betweenCtxt = new ScannerState(ctxt.module, ctxt.source, betweenAt, endAt, ctxt.locator, ctxt.result ); boolean rb = between.apply(betweenCtxt); if ( ! rb ) return false; ctxt.result = between.getReturn(betweenCtxt); return true; }
@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() {