当前位置: 首页>>代码示例>>Java>>正文


Java ParsingResult类代码示例

本文整理汇总了Java中org.parboiled.support.ParsingResult的典型用法代码示例。如果您正苦于以下问题:Java ParsingResult类的具体用法?Java ParsingResult怎么用?Java ParsingResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ParsingResult类属于org.parboiled.support包,在下文中一共展示了ParsingResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.parboiled.support.ParsingResult; //导入依赖的package包/类
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));
  }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:RunParser.java

示例2: setUp

import org.parboiled.support.ParsingResult; //导入依赖的package包/类
public void setUp() {
    String input = getFile("src/test/resources/test.query");
    System.out.println(input);
    DELPParser parser = Parboiled.createParser(DELPParser.class);

    parser.setResolver(IRIResolver.create());

    ParsingResult<OBEPQuery> result = new ReportingParseRunner(parser.Query()).run(input);

    if (result.hasErrors()) {
        System.out.println("Errors have been found!");
        for (ParseError arg : result.parseErrors) {
            System.out.println(input.substring(0, arg.getStartIndex()) + "|->" + input.substring(arg.getStartIndex(), arg.getEndIndex()) + "<-|" + input.substring(arg.getEndIndex(), input.length() - 1));
        }
    }

    OBEPQueryImpl q = (OBEPQueryImpl) result.resultValue;
    for (EventDecl event : q.getEventCalculusDecls()) {
        EventCalculusDecl ecd = (EventCalculusDecl) event;
        System.out.println(ecd);
    }
}
 
开发者ID:IBCNServices,项目名称:OBEP,代码行数:23,代码来源:OBEPEngineTest.java

示例3: setUp

import org.parboiled.support.ParsingResult; //导入依赖的package包/类
public void setUp() {
    testEngine = new OBEPTestEngine();

    cep = new EventProcessorImpl();
    cep.init(testEngine);
    String input = getFile("src/test/resources/test2.query");
    DELPParser parser = Parboiled.createParser(DELPParser.class);

    parser.setResolver(IRIResolver.create());

    ParsingResult<OBEPQuery> result = new ReportingParseRunner(parser.Query()).run(input);

    if (result.hasErrors()) {
        System.out.println("Errors have been found!");
        for (ParseError arg : result.parseErrors) {
            System.out.println(input.substring(0, arg.getStartIndex()) + "|->" + input.substring(arg.getStartIndex(), arg.getEndIndex()) + "<-|" + input.substring(arg.getEndIndex(), input.length() - 1));
        }
    }

    OBEPQuery q = result.resultValue;
    cep.registerQuery(q);
}
 
开发者ID:IBCNServices,项目名称:OBEP,代码行数:23,代码来源:EventProcessingTest.java

示例4: parseMatch

import org.parboiled.support.ParsingResult; //导入依赖的package包/类
protected void parseMatch(String input) {
    ParsingResult<?> result = reportingRunner.run(input);
    if (result.matched) {
        System.out.println(ParseTreeUtils.printNodeTree(result));
        final Properties pp = parser.getParsedProps();
        if (!pp.isEmpty()) {
            listPropsOrdered(pp);
        }
    } else {
        result = tracingRunner.run(input);
        System.out.println("\n\nParser did not match input:");
        for (ParseError pe : result.parseErrors) {
            System.out.format("\t%s%n", ErrorUtils.printParseError(pe));
        }
    }
    assertTrue(result.matched);
    assertFalse(result.hasErrors());
}
 
开发者ID:AlexFalappa,项目名称:nb-springboot,代码行数:19,代码来源:TestBase.java

示例5: main

import org.parboiled.support.ParsingResult; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    PegParser parser = Parboiled.createParser(PegParser.class);

    ReportingParseRunner runner = new ReportingParseRunner(parser.Grammar());

    String input = "";

    try (
            BufferedReader reader = Files.newBufferedReader(Paths.get("src/main/resources/peg.peg"))
    ) {
        String line = "";
        while ((line = reader.readLine())!=null) {

            input += line + "\n";
        }
    }

    ParsingResult<?> result = runner.run(input);

    if (!result.parseErrors.isEmpty())
        System.out.println(ErrorUtils.printParseError(result.parseErrors.get(0)));
    else {
        System.out.println(printNodeTree(result) + '\n');

    }
}
 
开发者ID:simonwibberley,项目名称:GramExp,代码行数:27,代码来源:PegParser.java

示例6: parseXPath

import org.parboiled.support.ParsingResult; //导入依赖的package包/类
/**
 * Parses an XPath Expression and generates an AST
 *
 * @param xpath The XPath to parse
 * @param out Either a print stream for receiving a debug print of the NodeTree generated by the parser, or null otherwise
 * @param err Either a print stream for receiving errors that occurred during parsing or null otherwise
 *
 * @return An {@link Expr} which is the root of the generated AST
 */
public static Expr parseXPath(final String xpath, final PrintStream out, final PrintStream err) {
    final XPathParser parser = Parboiled.createParser(XPathParser.class, Boolean.TRUE);
    final ParseRunner<ASTNode> parseRunner = new RecoveringParseRunner<ASTNode>(parser.withEOI(parser.XPath()));
    final ParsingResult<ASTNode> result = parseRunner.run(xpath + Chars.EOI);

    if(out != null) {
        final String parseTreePrintOut = ParseTreeUtils.printNodeTree(result);
        out.print(parseTreePrintOut);
    }

    if(err != null) {
        final String errors = printParseErrors(result);
        err.print(errors);
    }

    return (Expr)result.parseTreeRoot.getValue();
}
 
开发者ID:exquery,项目名称:xpath2-parser,代码行数:27,代码来源:XPathUtil.java

示例7: parse

import org.parboiled.support.ParsingResult; //导入依赖的package包/类
private ASTNode parse(final String xpath, final Rule rule) {
    final ParseRunner<ASTNode> parseRunner = new RecoveringParseRunner(parser.withEOI(rule));
    final ParsingResult<ASTNode> result = parseRunner.run(xpath + Chars.EOI);

    if(DEBUG) {
        final String parseTreePrintOut = ParseTreeUtils.printNodeTree(result);
        System.out.println(parseTreePrintOut);
    }

    if(result.hasErrors()) {
        final String errors = printParseErrors(result);
        fail(errors);
    }

    return result.parseTreeRoot.getValue();
}
 
开发者ID:exquery,项目名称:xpath2-parser,代码行数:17,代码来源:XPathParserTest.java

示例8: checkErrors

import org.parboiled.support.ParsingResult; //导入依赖的package包/类
private static <T> void checkErrors(ParsingResult<T> result) {
		if (result.hasErrors()) {
			java.util.List<ParseError> errors=result.parseErrors;
			StringBuilder sb=new StringBuilder();
			for (ParseError error: errors) {
				InputBuffer ib=error.getInputBuffer();
				int start=error.getStartIndex();
				int end=error.getEndIndex();
				sb.append("Parse error at "+ib.getPosition(error.getStartIndex())+": "+ib.extract(start, end)+" ERR: "+ error.getErrorMessage()+ "IB:"+ib.extractLine(1));
//				sb.append("Parse error at "+ib.getPosition(0)+": "+ib.extract(start, end)+" ERR: "+ error.getErrorMessage());
//				sb.append(result.parseTreeRoot);
			}
			throw new Error(sb.toString());
		}
		
	}
 
开发者ID:mikera,项目名称:magic,代码行数:17,代码来源:Reader.java

示例9: parse

import org.parboiled.support.ParsingResult; //导入依赖的package包/类
public static Ndfa<Character> parse(String text) {
    if (text == null) {
        return NfaUtils.<Character>createEmptyLanguageNfa();
    }

    if (text.equals("")) {
        return NfaUtils.<Character>createEmptyStringNfa();
    }

    final RegexpParser parser = Parboiled.createParser(RegexpParser.class);
    final ParsingResult<?> result = new ReportingParseRunner(parser.regexp()).run(text);

    if (!result.matched || result.parseTreeRoot.getEndIndex() < text.length()) {
        throw new IllegalArgumentException("Could not parse: " + text);
    }

    return NfaUtils.minimize(RegexpNodeTreeParser.getNfaBase(result.parseTreeRoot, text));
}
 
开发者ID:Blahord,项目名称:FastRegexp,代码行数:19,代码来源:RegexpParser.java

示例10: expressionRule

import org.parboiled.support.ParsingResult; //导入依赖的package包/类
@Test
public void expressionRule() throws Exception {
    DefaultJtwigParserConfiguration config = new DefaultJtwigParserConfiguration();
    ParserContext context = ParserContext.instance(
            ResourceReference.inline("Hello"),
            config,
            config.getAddonParserProviders(),
            config.getUnaryOperators(),
            config.getBinaryOperators(),
            config.getTestExpressionParsers()
    );

    MapSelectionExpressionParser parser = context.parser(MapSelectionExpressionParser.class);

    TracingParseRunner<Expression> runner = new TracingParseRunner<>(parser.ExpressionRule());
    ParsingResult<Expression> result = runner.run("list[position.size]");
    Expression resultValue = result.resultValue;

    System.out.println(resultValue);
}
 
开发者ID:jtwig,项目名称:jtwig-core,代码行数:21,代码来源:MapSelectionExpressionParserTest.java

示例11: main

import org.parboiled.support.ParsingResult; //导入依赖的package包/类
public static void main(String[] args) {
    TimeParser parser = Parboiled.createParser(TimeParser.class);
    
    while (true) {
        System.out.print("Enter a time expression (hh:mm(:ss)?, hh(mm(ss)?)? or h(mm)?, single RETURN to exit)!\n");
        String input = new Scanner(System.in).nextLine();
        if (StringUtils.isEmpty(input)) break;

        ParsingResult<?> result = new RecoveringParseRunner(parser.Time()).run(input);

        System.out.println(input + " = " + result.parseTreeRoot.getValue() + '\n');
        System.out.println(printNodeTree(result) + '\n');

        if (!result.matched) {
            System.out.println(StringUtils.join(result.parseErrors, "---\n"));
        }
    }
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:19,代码来源:Main.java

示例12: empty

import org.parboiled.support.ParsingResult; //导入依赖的package包/类
@Test
public void empty() {
    WKTParser parser = Parboiled.createParser(WKTParser.class);
    ParsingResult<Geometry> result = new ReportingParseRunner(parser.WKT()).run("POINT EMPTY");
    Geometry geometry = result.resultValue;
    assertNotNull(geometry);
    assertTrue(geometry instanceof Point);
    Point point = (Point) geometry;
    assertEquals(Dimension.Two, point.getDimension());
    assertTrue(point.isEmpty());
    assertTrue(point.getCoordinate().isEmpty());
    assertTrue(point.getCoordinate().getDimension() == Dimension.Two);
    assertTrue(Double.isNaN(point.getCoordinate().getX()));
    assertTrue(Double.isNaN(point.getCoordinate().getY()));
    assertTrue(Double.isNaN(point.getCoordinate().getM()));
    assertTrue(Double.isNaN(point.getCoordinate().getZ()));
    assertNull(point.getSrid());
    assertEquals(0, point.getNumberOfCoordinates());
    assertEquals("POINT EMPTY", point.toString());
}
 
开发者ID:jericks,项目名称:parboiled-wkt,代码行数:21,代码来源:PointTest.java

示例13: parse

import org.parboiled.support.ParsingResult; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected <T> T parse(Rule rule, String input) {
    ParsingResult<?> result;
    if (trace) {
        result = new TracingParseRunner<Object>(rule).run(input);
    } else {
        result = new ReportingParseRunner(rule).run(input);
    }

    if (!result.parseErrors.isEmpty()) {
        for (ParseError parseError : result.parseErrors) {
            System.out.println(ErrorUtils.printParseError(parseError));
        }
    } else if (trace) {
        System.out.println(printNodeTree(result) + '\n');
    }

    return (T) result.valueStack.pop();
}
 
开发者ID:Arnauld,项目名称:gutenberg,代码行数:20,代码来源:AbstractPegdownTest.java

示例14: twoDimensionalMeasured

import org.parboiled.support.ParsingResult; //导入依赖的package包/类
@Test
public void twoDimensionalMeasured() {
    WKTParser parser = Parboiled.createParser(WKTParser.class);
    ParsingResult<Geometry> result = new ReportingParseRunner(parser.WKT()).run("POINT M (1 2 3)");
    Geometry geometry = result.resultValue;
    assertNotNull(geometry);
    assertTrue(geometry instanceof Point);
    Point point = (Point) geometry;
    assertEquals(Dimension.TwoMeasured, point.getDimension());
    assertFalse(point.getCoordinate().isEmpty());
    assertTrue(point.getCoordinate().getDimension() == Dimension.TwoMeasured);
    assertEquals(1, point.getCoordinate().getX(), 0.001);
    assertEquals(2, point.getCoordinate().getY(), 0.001);
    assertEquals(3, point.getCoordinate().getM(), 0.001);
    assertTrue(Double.isNaN(point.getCoordinate().getZ()));
    assertNull(point.getSrid());
    assertEquals("POINT M (1.0 2.0 3.0)", point.toString());
}
 
开发者ID:jericks,项目名称:parboiled-wkt,代码行数:19,代码来源:PointTest.java

示例15: threeDimensional

import org.parboiled.support.ParsingResult; //导入依赖的package包/类
@Test
public void threeDimensional() {
    WKTParser parser = Parboiled.createParser(WKTParser.class);
    ParsingResult<Geometry> result = new ReportingParseRunner(parser.WKT()).run("POINT Z (1 2 3)");
    Geometry geometry = result.resultValue;
    assertNotNull(geometry);
    assertTrue(geometry instanceof Point);
    Point point = (Point) geometry;
    assertEquals(Dimension.Three, point.getDimension());
    assertFalse(point.getCoordinate().isEmpty());
    assertTrue(point.getCoordinate().getDimension() == Dimension.Three);
    assertEquals(1, point.getCoordinate().getX(), 0.001);
    assertEquals(2, point.getCoordinate().getY(), 0.001);
    assertEquals(3, point.getCoordinate().getZ(), 0.001);
    assertTrue(Double.isNaN(point.getCoordinate().getM()));
    assertNull(point.getSrid());
    assertEquals("POINT Z (1.0 2.0 3.0)", point.toString());
}
 
开发者ID:jericks,项目名称:parboiled-wkt,代码行数:19,代码来源:PointTest.java


注:本文中的org.parboiled.support.ParsingResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。