public ParseRunner<Node> get(Rule rule) { return new ReportingParseRunner<Node>(rule); } };
private Unit parseUnit(String templateText) throws Exception { ParsingResult<Object> result = new ReportingParseRunner<>(parser.Unit()).run(templateText); if (result.hasErrors()) { String errors = ErrorUtils.printParseErrors(result.parseErrors); throw new Exception(errors); } return (Unit) Iterables.getOnlyElement(result.valueStack); }
ParsingResult<Node> parseToParsingResult(char[] source) { parsingStartTimeStamp = System.currentTimeMillis(); return parseRunnerProvider.get(Root()).run(source); }
protected ParsingResult<V> runBasicMatch(InputBuffer inputBuffer) { ParseRunner<V> basicRunner = new BasicParseRunner<V>(getRootMatcher()) .withParseErrors(getParseErrors()) .withValueStack(getValueStack()); return basicRunner.run(inputBuffer); }
private void performReportingRun() { resetValueStack(); ParseRunner<V> reportingRunner = new ErrorReportingParseRunner<V>(rootMatcherWithoutPTB, errorIndex, getInnerHandler()) .withParseErrors(getParseErrors()) .withValueStack(getValueStack()); ParsingResult<V> result = reportingRunner.run(buffer); Preconditions.checkState(!result.matched); // we failed before so we should really be failing again currentError = (InvalidInputError) getParseErrors().get(getParseErrors().size() - 1); }
private boolean performLocatingRun(InputBuffer inputBuffer) { resetValueStack(); ParseRunner<V> locatingRunner = new ErrorLocatingParseRunner<V>(rootMatcherWithoutPTB, getInnerHandler()) .withParseErrors(getParseErrors()) .withValueStack(getValueStack()); lastParsingResult = locatingRunner.run(inputBuffer); errorIndex = lastParsingResult.matched ? -1 : getParseErrors().remove(getParseErrors().size() - 1).getStartIndex(); return lastParsingResult.matched; }
protected ParsingResult<V> runReportingMatch(InputBuffer inputBuffer, int errorIndex) { ParseRunner<V> reportingRunner = new ErrorReportingParseRunner<V>(getRootMatcher(), errorIndex) .withParseErrors(getParseErrors()) .withValueStack(getValueStack()); return reportingRunner.run(inputBuffer); } }
protected ParsingResult<V> runLocatingMatch(InputBuffer inputBuffer) { ParseRunner<V> locatingRunner = new ErrorLocatingParseRunner<V>(getRootMatcher()) .withValueStack(getValueStack()); return locatingRunner.run(inputBuffer); }
protected <T> ParsingResult<T> parse(Rule rule, String input) { ParseRunner<T> handler = new BasicParseRunner<T>(rule); return handler.run(input); } }
private void performFinalRun() { resetValueStack(); Handler handler = new Handler(); MatcherContext<V> rootContext = createRootContext(buffer, handler, false); boolean matched = handler.match(rootContext); lastParsingResult = createParsingResult(matched, rootContext); }
public int compare(RuleReport a, RuleReport b) { return doubleCompare(a.getNanoTime() / (double) a.getInvocations(), b.getNanoTime() / (double) b.getInvocations()); } });
public int compare(RuleReport a, RuleReport b) { return intCompare(a.getRemismatches(), b.getRemismatches()); } });
public int compare(RuleReport a, RuleReport b) { return intCompare(a.getInvocations(), b.getInvocations()); } });
public int compare(RuleReport a, RuleReport b) { return longCompare(a.getNanoTime(), b.getNanoTime()); } });
public int compare(RuleReport a, RuleReport b) { return intCompare(a.getMatches(), b.getMatches()); } });
public int compare(RuleReport a, RuleReport b) { return doubleCompare(a.getRemismatchSubs(), b.getRemismatchSubs()); } });
public int compare(RuleReport a, RuleReport b) { return doubleCompare(a.getReinvocationSubs(), b.getReinvocationSubs()); } });
public int compare(RuleReport a, RuleReport b) { return intCompare(a.getReinvocations(), b.getReinvocations()); } });
public int compare(RuleReport a, RuleReport b) { return intCompare(a.getRematches(), b.getRematches()); } });
public static void main(String... args) { Parser templateParser = Parboiled.createParser(Parser.class); ParsingResult<Object> result = new ReportingParseRunner<>(templateParser.Unit()).run(input2); ImmutableList<Object> copy = ImmutableList.copyOf(result.valueStack.iterator()); if (!copy.isEmpty()) { Unit unit = (Unit) copy.get(0); Unit balance = Balancing.balance(unit); System.out.println(balance); } if (result.hasErrors()) { System.err.println(ErrorUtils.printParseErrors(result.parseErrors)); } // System.out.println(ParseTreeUtils.printNodeTree(result)); } }