ParsingResult<Node> parseToParsingResult(char[] source) { parsingStartTimeStamp = System.currentTimeMillis(); return parseRunnerProvider.get(Root()).run(source); }
protected <T> ParsingResult<T> parse(Rule rule, String input) { ParseRunner<T> handler = new BasicParseRunner<T>(rule); return handler.run(input); } }
protected ParsingResult<V> runLocatingMatch(InputBuffer inputBuffer) { ParseRunner<V> locatingRunner = new ErrorLocatingParseRunner<V>(getRootMatcher()) .withValueStack(getValueStack()); return locatingRunner.run(inputBuffer); }
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; }
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); }
@Override protected ParsingResult<BaseTemplate> runReportingMatch( final InputBuffer inputBuffer, final int errorIndex) { ParseRunner<BaseTemplate> reportingRunner = new SafeErrorReportingParseRunner( getRootMatcher(), errorIndex) .withParseErrors(getParseErrors()) .withValueStack(getValueStack()); return reportingRunner.run(inputBuffer); } }
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> runBasicMatch(InputBuffer inputBuffer) { ParseRunner<V> basicRunner = new BasicParseRunner<V>(getRootMatcher()) .withParseErrors(getParseErrors()) .withValueStack(getValueStack()); return basicRunner.run(inputBuffer); }
/** * Turns the CSS provided into a {@link Stylesheet} object, will throw a {@link * CSSParseException} in case of syntax errors * * @return * @throws IOException */ public static Stylesheet parse(String css) throws CSSParseException { CssParser parser = getInstance(); ParseRunner<Stylesheet> runner = new ReportingParseRunner<Stylesheet>(parser.StyleSheet()); ParsingResult<Stylesheet> result = runner.run(css); if (result.hasErrors()) { throw new CSSParseException(result.parseErrors); } Stylesheet ss = result.parseTreeRoot.getValue(); return ss; }
protected XSchema xparse (NamedInput namedInput) { String input = namedInput.getInput(); // Input buffer DefaultInputBuffer inputBuffer = new DefaultInputBuffer(input.toCharArray()); // Creates the action support XAction action = new XAction(); // Creates the parser XParser parser = Parboiled.createParser(XParser.class, action); // Creates the parser runner ParseRunner<String> runner = createParserRunner(parser); // Runs the parser ParsingResult<String> result = runner.run(inputBuffer); // Checks the result if (result.hasErrors()) { MultiLocalizable list = new MultiLocalizable(Collections2.transform(result.parseErrors, new Function<ParseError, Localizable>() { @Override public Localizable apply(ParseError error) { return localize (error); } })); throw new SidoParseException(namedInput.getName(), list); } // OK else { // Gets the X schema XSchema xSchema = action.getSchema(); // OK return xSchema; } }
public Template parse(final String input) throws IOException { try { ParseRunner<BaseTemplate> runner = new SafeReportingParseRunner(template()); ParsingResult<BaseTemplate> result = runner.run(input); if (result.hasErrors()) { ParseError error = result.parseErrors.get(0); String msg = ErrorFormatter.printParseError(filename, error, noffset, stacktraceList); throw new HandlebarsException(msg); } TemplateList sequence = (TemplateList) result.resultValue; removeBlanks(sequence); if (sequence.size() == 1) { return sequence.iterator().next(); } return sequence; } catch (ParserRuntimeException ex) { Throwable cause = ex.getCause(); if (cause instanceof HandlebarsException) { throw (HandlebarsException) cause; } HandlebarsException hex = new HandlebarsException(ex.getMessage()); hex.initCause(ex.getCause() == null ? ex : ex.getCause()); throw hex; } }
.withParseErrors(getParseErrors()) .withValueStack(getValueStack()); lastParsingResult = basicRunner.run(inputBuffer);