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 ParseRunner<Node> get(Rule rule) { return new ReportingParseRunner<Node>(rule); } };
private RateGenerator parseRateGeneratorExpression(Object def) { // handle String as expression and all other types as primitives if (def instanceof String) { ParsingResult<RateGenerator> result = parseRunner.run((String) def); return result.valueStack.pop(); } else if (def instanceof Long) { return new ConstantRateGenerator((long) def); } else if (def instanceof Integer) { return new ConstantRateGenerator(((Number) def).longValue()); } else { throw new RuntimeException("Object type not supported: " + def.getClass().getName()); } } }
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 ParseRunner<String> createParserRunner(XParser parser) { Rule root = parser.schema(); if (logger.isDebugEnabled()) { return new TracingParseRunner<String>(root); } else { return new ReportingParseRunner<String>(root); } }
private RateGenerator parseRateGeneratorExpression(Object def) { // handle String as expression and all other types as primitives if (def instanceof String) { ParsingResult<RateGenerator> result = parseRunner.run((String) def); return result.valueStack.pop(); } else if (def instanceof Long) { return new ConstantRateGenerator((long) def); } else if (def instanceof Integer) { return new ConstantRateGenerator(((Number) def).longValue()); } else { throw new RuntimeException("Object type not supported: " + def.getClass().getName()); } } }
protected ParsingResult<V> runBasicMatch(InputBuffer inputBuffer) { ParseRunner<V> basicRunner = new BasicParseRunner<V>(getRootMatcher()) .withParseErrors(getParseErrors()) .withValueStack(getValueStack()); return basicRunner.run(inputBuffer); }
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)); } }
private void buildModel() { this.proxyValues = new HashMap<>(); this.parser = Parboiled.createParser(ValueExpressionParser.class, proxyValues); this.parseRunner = new ReportingParseRunner<>(parser.value()); if (values != null) { createProxies(); parseValues(); } }
private Value<?> parseSimpleValue(String parentName, Object def) { // handle String as expression and all other types as primitives if (def instanceof String) { parser.setParentName(stripOffLastReference(parentName)); ParsingResult<Value<?>> result = parseRunner.run((String) def); return result.valueStack.pop(); } else { return ConstantValue.of(def); } }
public TestResult<V> test(Rule rule, String input) { return new TestResult<V>(new ReportingParseRunner<V>(rule).run(input)); }
private void buildModel() { this.proxyValues = new HashMap<>(); this.parser = Parboiled.createParser(RateGeneratorExpressionParser.class, proxyValues); this.parseRunner = new ReportingParseRunner<>(parser.rateGenerator()); if (rates != null) { createProxies(); parseRateGenerators(); } }
private Value<?> parseSimpleValue(String parentName, Object def) { // handle String as expression and all other types as primitives if (def instanceof String) { parser.setParentName(stripOffLastReference(parentName)); ParsingResult<Value<?>> result = parseRunner.run((String) def); return result.valueStack.pop(); } else { return ConstantValue.of(def); } }
public TestResult<V> test(Rule rule, InputBuffer inputBuffer) { return new TestResult<V>(new ReportingParseRunner<V>(rule).run(inputBuffer)); }
private void buildModel() { this.proxyValues = new HashMap<>(); this.parser = Parboiled.createParser(ValueExpressionParser.class, proxyValues); this.parseRunner = new ReportingParseRunner<>(parser.value()); if (values != null) { createProxies(); parseValues(); } }
private ParsingResult<OpelNode> getParsingResult(String expression) { return new ReportingParseRunner<OpelNode>(parser.get().ParsingUnit()).run(expression); } }
private void buildModel() { this.proxyValues = new HashMap<>(); this.parser = Parboiled.createParser(RateGeneratorExpressionParser.class, proxyValues); this.parseRunner = new ReportingParseRunner<>(parser.rateGenerator()); if (rates != null) { createProxies(); parseRateGenerators(); } }
public Optional<MDNReport> parse(String mdnReport) { Parser parser = Parboiled.createParser(MDNReportParser.Parser.class); ParsingResult<Object> result = new ReportingParseRunner<>(parser.dispositionNotificationContent()).run(mdnReport); if (result.matched) { return Optional.of((MDNReport)result.resultValue); } return Optional.empty(); }
/** * 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; }