public RootNode parseInternal(char[] source) { ParsingResult<Node> result = parseToParsingResult(source); if (result.hasErrors()) { throw new RuntimeException("Internal error during markdown parsing:\n--- ParseErrors ---\n" + printParseErrors(result)/* + "\n--- ParseTree ---\n" + printNodeTree(result)*/ ); } return (RootNode) result.resultValue; }
protected ParsingResult<V> createParsingResult(boolean matched, MatcherContext<V> rootContext) { return new ParsingResult<V>(matched, rootContext.getNode(), getValueStack(), getParseErrors(), rootContext.getInputBuffer()); } }
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); }
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)); } }
public boolean isValid() { return !parsingResult.hasErrors(); }
private Optional<OpelNode> getParsedExpression() { if (parsingResult.hasErrors()) { return Optional.empty(); } return Optional.of(parsingResult.resultValue); }
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); }
public ExpressionValidationResult validate(String expression) { ParsingResult<OpelNode> parsingResult = getParsingResult(expression); if (parsingResult.hasErrors()) { return ExpressionValidationResult.invalid(parsingResult.parseErrors); } else { return ExpressionValidationResult.valid(); } }
if (result.hasErrors() || !result.matched) { System.out.println("\nParse Errors:\n" + ErrorUtils.printParseErrors(result));
@Override public MongoDBQueryDescriptor parseNativeQuery(String nativeQuery) { NativeQueryParser localParser = NATIVE_QUERY_PARSER.newInstance(); ParsingResult<MongoDBQueryDescriptorBuilder> parseResult = new RecoveringParseRunner<MongoDBQueryDescriptorBuilder>( localParser.Query() ) .run( nativeQuery ); if ( parseResult.hasErrors() ) { throw new IllegalArgumentException( "Unsupported native query: " + ErrorUtils.printParseErrors( parseResult.parseErrors ) ); } return parseResult.resultValue.build(); }
public CompletableFuture<?> eval(String expression) { ParsingResult<OpelNode> parsingResult = getParsingResult(expression); if (parsingResult.hasErrors()) { throw new OpelException("Error parsing expression: '" + expression + "'" + additionalErrorMsg(parsingResult)); } return parsingResult.resultValue.getValue(embeddedEvalContext); }
@Override public MongoDBQueryDescriptor parseNativeQuery(String nativeQuery) { NativeQueryParser localParser = NATIVE_QUERY_PARSER.newInstance(); ParsingResult<MongoDBQueryDescriptorBuilder> parseResult = new RecoveringParseRunner<MongoDBQueryDescriptorBuilder>( localParser.Query() ) .run( nativeQuery ); if ( parseResult.hasErrors() ) { throw new IllegalArgumentException( "Unsupported native query: " + ErrorUtils.printParseErrors( parseResult.parseErrors ) ); } return parseResult.resultValue.build(); }
@Test public void blockWithEndError() throws Exception { ParsingResult<BlockNode> result = parse(underTest.NodeRule(), "{% block test %}{% endblock testa %}"); assertThat(result.matched, is(true)); assertThat(result.hasErrors(), is(true)); } }
public static AbstractNode parse(String input) { ChartDescriptorParboiledParser parser = Parboiled.createParser(ChartDescriptorParboiledParser.class); ParsingResult<Object> result; boolean trace = false; if (trace) result = new TracingParseRunner<Object>(parser.descriptors()).run(input); else result = new ReportingParseRunner<Object>(parser.descriptors()).run(input); if (result.hasErrors()) { System.out.println("ChartDescriptorParser.parse(" + result.parseErrors + ")"); } System.out.println("ChartDescriptorParboiledParser.parse(" + ParseTreeUtils.printNodeTree(result) + ")"); return (AbstractNode) result.resultValue; }
/** * 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; } }
.or(environment.getResourceEnvironment().getDefaultInputCharset()); ParsingResult<Node> result = runner.run(readAllText(resourceMetadata.load(), charset)); if (result.hasErrors()) { throw new ParseException(toMessage(result.parseErrors)); } else if (!result.matched) {
.or(environment.getResourceEnvironment().getDefaultInputCharset()); ParsingResult<Node> result = runner.run(readAllText(resourceMetadata.load(), charset)); if (result.hasErrors()) { throw new ParseException(toMessage(result.parseErrors)); } else if (!result.matched) {