• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Parboiled类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: main

import org.parboiled.Parboiled; //导入依赖的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.Parboiled; //导入依赖的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.Parboiled; //导入依赖的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: main

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

    String peg = "";

    try (
            BufferedReader reader = Files.newBufferedReader(Paths.get(arg[0]))
    ) {
        String line = "";
        while ((line = reader.readLine())!=null) {

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


    AstToJava astToJava = new AstToJava(arg[1]);
    String java = astToJava.toJava(parser.parse(peg));

    try (
            BufferedWriter writer = Files.newBufferedWriter(Paths.get(arg[1]+".java"))
    ) {
        writer.write(java);
    }
}
 
开发者ID:simonwibberley,项目名称:GramExp,代码行数:26,代码来源:AstToJava.java


示例5: testToJava

import org.parboiled.Parboiled; //导入依赖的package包/类
@Test
public void testToJava() throws Exception {
    PegParser parser  = Parboiled.createParser(PegParser.class);

    String peg = "";

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

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

    String clsName = "GramExp";


    AstToJava astToJava = new AstToJava(clsName);
    String java = astToJava.toJava(parser.parse(peg));

    assertEquals(expected, java);
}
 
开发者ID:simonwibberley,项目名称:GramExp,代码行数:25,代码来源:AstTojavaTest.java


示例6: parseXPath

import org.parboiled.Parboiled; //导入依赖的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.Parboiled; //导入依赖的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


示例8: inlineTemplate

import org.parboiled.Parboiled; //导入依赖的package包/类
@Test(dataProvider = "inlineTemplateData")
public void inlineTemplate(String input, List<String> expected)
{
	InlineTemplateParser parser = Parboiled
			.createParser(InlineTemplateParser.class);

	RecoveringParseRunner<String> runner = new RecoveringParseRunner<String>(
			parser.inlineTemplate());

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

	List<String> actual = new ArrayList<String>();

	for (String s : result.valueStack)
	{
		actual.add(0, s);
	}

	assertThat(actual, equalTo(expected));
}
 
开发者ID:furti,项目名称:spring-web-extended,代码行数:21,代码来源:InlineTemplateParserTest.java


示例9: main

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

    while (true) {
        System.out.print("Enter an a^n b^n c^n expression (single RETURN to exit)!\n");
        String input = new Scanner(System.in).nextLine();
        if (StringUtils.isEmpty(input)) break;

        ParsingResult<?> result = new ReportingParseRunner(parser.S()).run(input);

        if (!result.parseErrors.isEmpty())
            System.out.println(ErrorUtils.printParseError(result.parseErrors.get(0)));
        else
            System.out.println(printNodeTree(result) + '\n');
    }
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:17,代码来源:Main.java


示例10: empty

import org.parboiled.Parboiled; //导入依赖的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


示例11: testJavaError1

import org.parboiled.Parboiled; //导入依赖的package包/类
@Test
public void testJavaError1() {
    String sourceWithErrors = "package org.parboiled.examples;\n" +
            "public class JavaTestSource {\n" +
            "    @SuppressWarnings({\"UnnecessaryLocalVariable\", \"UnusedDeclaration\"})\n" +
            "    public String method(int param) {\n" +
            "        String name = toString(;\n" +
            "        return name;\n" +
            "    }\n" +
            "}";

    JavaParser parser = Parboiled.createParser(JavaParser.class);
    Rule rule = parser.CompilationUnit();
    ParsingResult result = new ReportingParseRunner(rule).run(sourceWithErrors);
    assertEquals(result.parseErrors.size(), 1);
    assertEquals(printParseErrors(result), "" +
            "Invalid input ';', expected Spacing, Expression or ')' (line 5, pos 32):\n" +
            "        String name = toString(;\n" +
            "                               ^\n");
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:21,代码来源:ReportingParseRunnerTest.java


示例12: twoDimensionalMeasured

import org.parboiled.Parboiled; //导入依赖的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


示例13: threeDimensional

import org.parboiled.Parboiled; //导入依赖的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


示例14: twoDimensionalWithSrid

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


示例15: main

import org.parboiled.Parboiled; //导入依赖的package包/类
public static void main(final String... args)
{
    final JsonParser parser
        = Parboiled.createParser(JsonParser.class);

    final Scanner scanner = new Scanner(System.in);
    ParsingResult<?> result;
    String line;

    while (true) {
        System.out.print("Enter a value to test (empty to quit): ");
        line = scanner.nextLine();
        if (line.isEmpty())
            break;
        result = new ReportingParseRunner(parser.jsonText())
            .run(line);
        if (result.hasErrors()) {
            System.out.println("Invalid input!");
            System.out.println(ErrorUtils.printParseErrors(result));
        } else {
            System.out.println(ParseTreeUtils.printNodeTree(result));
        }
    }
}
 
开发者ID:parboiled1,项目名称:parboiled-examples,代码行数:25,代码来源:JsonParser.java


示例16: parseMultiple

import org.parboiled.Parboiled; //导入依赖的package包/类
@Test
public void parseMultiple() {
    WKTParser parser = Parboiled.createParser(WKTParser.class);
    // 1
    ParsingResult<Geometry> result = new ReportingParseRunner(parser.WKT()).run("POINT (1 2)");
    Geometry geometry = result.resultValue;
    assertEquals("POINT (1.0 2.0)", geometry.toString());
    // 2
    result = new ReportingParseRunner(parser.WKT()).run("POINT M (1 2 4.5)");
    geometry = result.resultValue;
    assertEquals("POINT M (1.0 2.0 4.5)", geometry.toString());
    // 3
    result = new ReportingParseRunner(parser.WKT()).run("POINT (-122.014487 46.982752)");
    geometry = result.resultValue;
    assertEquals("POINT (-122.014487 46.982752)", geometry.toString());
}
 
开发者ID:jericks,项目名称:parboiled-wkt,代码行数:17,代码来源:PointTest.java


示例17: testFail2

import org.parboiled.Parboiled; //导入依赖的package包/类
@Test
public void testFail2() {
    AbcParser parser = Parboiled.createParser(AbcParser.class);
    testWithRecovery(parser.S(), "aabcc")
            .hasErrors("" +
                    "Invalid input 'c', expected 'b' (line 1, pos 4):\n" +
                    "aabcc\n" +
                    "   ^\n")
            .hasParseTree("" +
                    "[S]E 'aabbcc'\n" +
                    "  [OneOrMore] 'aa'\n" +
                    "    ['a'] 'a'\n" +
                    "    ['a'] 'a'\n" +
                    "  [B]E 'bbcc'\n" +
                    "    ['b'] 'b'\n" +
                    "    [Optional]E 'bc'\n" +
                    "      [B]E 'bc'\n" +
                    "        ['b']E 'b'\n" +
                    "        [Optional]\n" +
                    "        ['c'] 'c'\n" +
                    "    ['c'] 'c'\n"
            );
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:24,代码来源:AbcTest.java


示例18: main

import org.parboiled.Parboiled; //导入依赖的package包/类
public static void main(final String... args)
{
    final DoubleQuotedString parser
        = Parboiled.createParser(DoubleQuotedString.class);

    final Scanner scanner = new Scanner(System.in);
    ParsingResult<?> result;
    String line;

    while (true) {
        System.out.print("Enter a value to test (empty to quit): ");
        line = scanner.nextLine();
        if (line.isEmpty())
            break;
        result = new TracingParseRunner(parser.doubleQuotedString())
            .run(line);
        if (result.hasErrors()) {
            System.out.println("Invalid input!");
            System.out.println(ErrorUtils.printParseErrors(result));
        } else {
            System.out.println(ParseTreeUtils.printNodeTree(result));
        }
    }
}
 
开发者ID:parboiled1,项目名称:parboiled-examples,代码行数:25,代码来源:DoubleQuotedString.java


示例19: twoDimensionalMeasured

import org.parboiled.Parboiled; //导入依赖的package包/类
@Test
public void twoDimensionalMeasured() {
    WKTParser parser = Parboiled.createParser(WKTParser.class);
    ParsingResult<Geometry> result = new ReportingParseRunner(parser.WKT())
            .run("MULTILINESTRING M ((0 0 0,1 1 0,1 2 1),(2 3 1,3 2 1,5 4 1))");
    Geometry geometry = result.resultValue;
    assertNotNull(geometry);
    assertTrue(geometry instanceof MultiLineString);
    MultiLineString mls = (MultiLineString) geometry;
    assertEquals(Dimension.TwoMeasured, mls.getDimension());
    assertEquals(2, mls.getLineStrings().size());
    // 0
    LineString line = mls.getLineStrings().get(0);
    assertEquals(3, line.getCoordinates().size());
    assertEquals(Coordinate.create2DM(0, 0, 0), line.getCoordinates().get(0));
    assertEquals(Coordinate.create2DM(1, 1, 0), line.getCoordinates().get(1));
    assertEquals(Coordinate.create2DM(1, 2, 1), line.getCoordinates().get(2));
    // 1
    line = mls.getLineStrings().get(1);
    assertEquals(3, line.getCoordinates().size());
    assertEquals(Coordinate.create2DM(2, 3, 1), line.getCoordinates().get(0));
    assertEquals(Coordinate.create2DM(3, 2, 1), line.getCoordinates().get(1));
    assertEquals(Coordinate.create2DM(5, 4, 1), line.getCoordinates().get(2));
    // WKT
    assertEquals("MULTILINESTRING M ((0.0 0.0 0.0, 1.0 1.0 0.0, 1.0 2.0 1.0), (2.0 3.0 1.0, 3.0 2.0 1.0, 5.0 4.0 1.0))", mls.toString());
}
 
开发者ID:jericks,项目名称:parboiled-wkt,代码行数:27,代码来源:MultiLineStringTest.java


示例20: threeDimensional

import org.parboiled.Parboiled; //导入依赖的package包/类
@Test
public void threeDimensional() {
    WKTParser parser = Parboiled.createParser(WKTParser.class);
    ParsingResult<Geometry> result = new ReportingParseRunner(parser.WKT())
            .run("MULTILINESTRING Z ((0 0 0,1 1 0,1 2 1),(2 3 1,3 2 1,5 4 1))");
    Geometry geometry = result.resultValue;
    assertNotNull(geometry);
    assertTrue(geometry instanceof MultiLineString);
    MultiLineString mls = (MultiLineString) geometry;
    assertEquals(Dimension.Three, mls.getDimension());
    assertEquals(2, mls.getLineStrings().size());
    // 0
    LineString line = mls.getLineStrings().get(0);
    assertEquals(3, line.getCoordinates().size());
    assertEquals(Coordinate.create3D(0, 0, 0), line.getCoordinates().get(0));
    assertEquals(Coordinate.create3D(1, 1, 0), line.getCoordinates().get(1));
    assertEquals(Coordinate.create3D(1, 2, 1), line.getCoordinates().get(2));
    // 1
    line = mls.getLineStrings().get(1);
    assertEquals(3, line.getCoordinates().size());
    assertEquals(Coordinate.create3D(2, 3, 1), line.getCoordinates().get(0));
    assertEquals(Coordinate.create3D(3, 2, 1), line.getCoordinates().get(1));
    assertEquals(Coordinate.create3D(5, 4, 1), line.getCoordinates().get(2));
    // WKT
    assertEquals("MULTILINESTRING Z ((0.0 0.0 0.0, 1.0 1.0 0.0, 1.0 2.0 1.0), (2.0 3.0 1.0, 3.0 2.0 1.0, 5.0 4.0 1.0))", mls.toString());
}
 
开发者ID:jericks,项目名称:parboiled-wkt,代码行数:27,代码来源:MultiLineStringTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EhCacheManager类代码示例发布时间:2022-05-21
下一篇:
Java CastExpr类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap