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

Java RecoveringParseRunner类代码示例

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

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



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

示例1: parseXPath

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


示例2: parse

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


示例3: inlineTemplate

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


示例4: main

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


示例5: test

import org.parboiled.parserunners.RecoveringParseRunner; //导入依赖的package包/类
@Test
public void test() {
    IndentDedentParser parser = Parboiled.createParser(IndentDedentParser.class);
    Rule rule = parser.File();
    String source = "" +
            "a file containing\n" +
            "  some\n" +
            "     indents\n" +
            "     some lines\n" +
            "     that do not indent\n" +
            "  they might dedent\n" +
            "  stay there\n" +
            "          go back big time\n" +
            " and return";
    ParsingResult result = new RecoveringParseRunner(rule).run(source);
    assertEquals(parser.indents, 3);
    assertEquals(parser.dedents, 2);
    assertEquals(parser.currentIndent, 1);
    assertEquals(result.inputBuffer.getPosition(source.length() - 1).line, 9);
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:21,代码来源:IndentDedentTest.java


示例6: main

import org.parboiled.parserunners.RecoveringParseRunner; //导入依赖的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-examples,代码行数:19,代码来源:Main.java


示例7: testAst

import org.parboiled.parserunners.RecoveringParseRunner; //导入依赖的package包/类
public static void testAst(String filePath) throws Exception {
    FantomParser parser = Parboiled.createParser(FantomParser.class, (FanParserTask) null);

    DataInputStream dis = new DataInputStream(new FileInputStream(filePath));
    byte[] buffer = new byte[dis.available()];
    dis.readFully(buffer);
    dis.close();//TODO: finally
    String testInput = new String(buffer);

    ParsingResult<AstNode> result = new RecoveringParseRunner<AstNode>(parser.compilationUnit()).run(testInput);

    if (result.hasErrors()) {
        System.err.println(ErrorUtils.printParseErrors(result));
        System.err.println("Parse Tree:\n" + ParseTreeUtils.printNodeTree(result) + '\n');
    }

    AstNode nd = result.parseTreeRoot.getValue();
    FantomParserAstActions.linkNodes(result.valueStack);
    String inc = "";
    AstNode.printNodeTree(nd, inc, result.inputBuffer);
    //System.out.println("Abstract Syntax Tree:\n" +
    //            GraphUtils.printTree(result.parseTreeRoot.getValue(), new ToStringFormatter<AstNode>()) + '\n');
    //System.err.println("Parse Tree:\n" + ParseTreeUtils.printNodeTree(result) + '\n');
}
 
开发者ID:tcolar,项目名称:fantomidemodule,代码行数:25,代码来源:FantomParserTest.java


示例8: checkExpr

import org.parboiled.parserunners.RecoveringParseRunner; //导入依赖的package包/类
/**
 * Parse the expression into a type and check it against expected values
 *
 * @param expr
 * @param typeSig
 * @param isNullable
 * @param isStatic
 * @throws Exception
 */
private AstNode checkExpr(String expr, String typeSig, boolean isNullable, boolean isStatic) throws Exception {
    FanParserTask task = new FanParserTask(null);
    FantomParser parser = Parboiled.createParser(FantomParser.class, task);
    ParsingResult<AstNode> result = new RecoveringParseRunner<AstNode>(parser.testExpr()).run(expr);
    JOTTester.checkIf("Checking for parsing errors: " + expr, !result.hasErrors(), StringUtils.join(result.parseErrors, "\n"));
    AstNode node = result.parseTreeRoot.getValue();
    FantomParserAstActions.linkNodes(result.valueStack);

    addUsingsToNode(node, testUsings);
    addTypeSlotsToNode(node, task, testSlots);
    task.parseVars(node, null);
    //System.out.println("Node for "+expr+" : ");
    if(!task.getDiagnostics().isEmpty())
    {
        FanLexAstUtils.dumpTree(node, 0);
    }
    JOTTester.checkIf("Checking for Semantic errors: " + expr, task.getDiagnostics().isEmpty(), StringUtils.join(task.getDiagnostics(), "\n"));
    FanResolvedType t = node.getType();
    check(expr, t, typeSig, isNullable, isStatic);
    return node;
}
 
开发者ID:tcolar,项目名称:fantomidemodule,代码行数:31,代码来源:FantomTypesTest.java


示例9: parse

import org.parboiled.parserunners.RecoveringParseRunner; //导入依赖的package包/类
@Override
public void parse(Snapshot snapshot, Task task, SourceModificationEvent sme) throws ParseException {
    logger.fine("Parsing...");
    this.snapshot = snapshot;
    RecoveringParseRunner runner = new RecoveringParseRunner(parboiled.cfgProps());
    parboiled.reset();
    parbResult = runner.run(snapshot.getText().toString());
    logParsingResult();
}
 
开发者ID:AlexFalappa,项目名称:nb-springboot,代码行数:10,代码来源:CfgPropsParser.java


示例10: main

import org.parboiled.parserunners.RecoveringParseRunner; //导入依赖的package包/类
@SuppressWarnings({"unchecked"})
public static <V, P extends CalculatorParser<V>> void main(Class<P> parserClass) {
    CalculatorParser<V> parser = Parboiled.createParser(parserClass);

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

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

        if (result.hasErrors()) {
            System.out.println("\nParse Errors:\n" + printParseErrors(result));
        }

        Object value = result.parseTreeRoot.getValue();
        if (value != null) {
            String str = value.toString();
            int ix = str.indexOf('|');
            if (ix >= 0) str = str.substring(ix + 2); // extract value part of AST node toString()
            System.out.println(input + " = " + str + '\n');
        }
        if (value instanceof GraphNode) {
            System.out.println("\nAbstract Syntax Tree:\n" +
                    printTree((GraphNode) value, new ToStringFormatter(null)) + '\n');
        } else {
            System.out.println("\nParse Tree:\n" + printNodeTree(result) + '\n');
        }
    }
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:31,代码来源:CalculatorParser.java


示例11: test

import org.parboiled.parserunners.RecoveringParseRunner; //导入依赖的package包/类
@Test
public void test() throws Exception {
    int failures = 0;
    for (TextInfo textInfo : getTextInfos()) {
        ParsingResult result = new RecoveringParseRunner(parser.Query()).run(textInfo.text);

        boolean passed = result.hasErrors() == (textInfo.result == Result.FAIL);
        if (!passed) {
            failures++;
            //System.err.println(textInfo.text + " --> " + textInfo.result + "\n\n");
        }
    }
    Assert.assertEquals(failures, 12); // currently 12 tests require semantic validation and therefore fail
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:15,代码来源:SparqlTest.java


示例12: test

import org.parboiled.parserunners.RecoveringParseRunner; //导入依赖的package包/类
@Test
public void test() {
    TimeParser parser = Parboiled.createParser(TimeParser.class);
    assertEquals(new RecoveringParseRunner(parser.Time()).run("12:00").parseTreeRoot.getValue(), "12 h, 0 min, 0 s");
    assertEquals(new RecoveringParseRunner(parser.Time()).run("9:01").parseTreeRoot.getValue(), "9 h, 1 min, 0 s");
    assertEquals(new RecoveringParseRunner(parser.Time()).run("02:34:56").parseTreeRoot.getValue(),
            "2 h, 34 min, 56 s");
    assertEquals(new RecoveringParseRunner(parser.Time()).run("1").parseTreeRoot.getValue(), "1 h, 0 min, 0 s");
    assertEquals(new RecoveringParseRunner(parser.Time()).run("12").parseTreeRoot.getValue(), "12 h, 0 min, 0 s");
    assertEquals(new RecoveringParseRunner(parser.Time()).run("123").parseTreeRoot.getValue(), "1 h, 23 min, 0 s");
    assertEquals(new RecoveringParseRunner(parser.Time()).run("1234").parseTreeRoot.getValue(), "12 h, 34 min, 0 s");
    assertTrue(new RecoveringParseRunner(parser.Time()).run("12345").hasErrors());
    assertEquals(new RecoveringParseRunner(parser.Time()).run("123456").parseTreeRoot.getValue(), "12 h, 34 min, 56 s");
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:15,代码来源:TimeTest.java


示例13: main

import org.parboiled.parserunners.RecoveringParseRunner; //导入依赖的package包/类
@SuppressWarnings({"unchecked"})
public static <V, P extends CalculatorParser<V>> void main(Class<P> parserClass) {
    CalculatorParser<V> parser = Parboiled.createParser(parserClass);

    while (true) {
        System.out.print("Enter a calculators expression (single RETURN to exit)!\n");
        String input = new Scanner(System.in).nextLine();
        if (Strings.isNullOrEmpty(input))
            break;

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

        if (result.hasErrors()) {
            System.out.println("\nParse Errors:\n" + printParseErrors(result));
        }

        Object value = result.parseTreeRoot.getValue();
        if (value != null) {
            String str = value.toString();
            int ix = str.indexOf('|');
            if (ix >= 0) str = str.substring(ix + 2); // extract value part of AST node toString()
            System.out.println(input + " = " + str + '\n');
        }
        if (value instanceof GraphNode) {
            System.out.println("\nAbstract Syntax Tree:\n" +
                    printTree((GraphNode) value, new ToStringFormatter(null)) + '\n');
        } else {
            System.out.println("\nParse Tree:\n" + printNodeTree(result) + '\n');
        }
    }
}
 
开发者ID:parboiled1,项目名称:parboiled-examples,代码行数:32,代码来源:CalculatorParser.java


示例14: getParseTree

import org.parboiled.parserunners.RecoveringParseRunner; //导入依赖的package包/类
/**
 * Parse the {@link Reader} and get the parsing tree by its root
 * {@link AbcNode}.
 * 
 * @param abcString
 */
protected AbcNode getParseTree(String abcString) {
	long startTime = System.currentTimeMillis();
	AbcGrammar grammar = AbcGrammar.getInstance();
	// AbcGrammar parser = Parboiled.createParser(AbcGrammar.class);
	ParsingResult<?> result = RecoveringParseRunner.run(grammar.AbcFile(),
			abcString);
	if (DEBUG) {
		System.out.println("Parse : "+(System.currentTimeMillis() - startTime) + "ms");
	}
	if (result.hasErrors()) {
		System.err.println("Parse errors: "
				+ result.parseErrors.size());
		/*Iterator it = result.parseErrors.iterator();
		while (it.hasNext()) {
			ParseError pe = (ParseError) it.next();
			System.err.println("- " + pe.getErrorMessage()
					+ "("+pe.getStartIndex()+"->"+pe.getEndIndex()+")");
		}*/
	}

	AbcNode abcRoot = new AbcNode(result.parseTreeRoot, result.inputBuffer,
			result.parseErrors, new AbcInputBuffer(abcString.toCharArray()));
	if (result.hasErrors() || DEBUG)
		debugTree(abcRoot);
	return abcRoot;
}
 
开发者ID:Sciss,项目名称:abc4j,代码行数:33,代码来源:AbcParserAbstract.java


示例15: parse

import org.parboiled.parserunners.RecoveringParseRunner; //导入依赖的package包/类
public ParsingResult<AstNode> parse(FantomParser parser, Rule rule, String input) {
    long start = new Date().getTime();
    ParsingResult<AstNode> result = new RecoveringParseRunner<AstNode>(rule).run(input);
    long time = new Date().getTime() - start;
    //System.err.println("Parsing in " + (new Date().getTime() - start) + "ms");
    if (time > 100) {
        System.err.println("Long parsing : " + (new Date().getTime() - start) + "ms, for:\n" + input);
    }
    //System.out.println(ParseTreeUtils.printNodeTree(result));
    return result;
}
 
开发者ID:tcolar,项目名称:fantomidemodule,代码行数:12,代码来源:FantomCSLTest.java


示例16: testFile

import org.parboiled.parserunners.RecoveringParseRunner; //导入依赖的package包/类
public static void testFile(String filePath, boolean lexerOnly) throws Exception {
    // parser caches stuuf, so using a new one each time to avoid OOM
    FantomParser parser = Parboiled.createParser(FantomParser.class, (FanParserTask) null);

    try {
        DataInputStream dis = new DataInputStream(new FileInputStream(filePath));
        byte[] buffer = new byte[dis.available()];
        dis.readFully(buffer);
        dis.close();//TODO: finally
        String testInput = new String(buffer);

        long start = new Date().getTime();
        ParsingResult<AstNode> result = new RecoveringParseRunner<AstNode>((lexerOnly ? parser.lexer() : parser.compilationUnit())).run(testInput);

        long length = new Date().getTime() - start;
        if (result.hasErrors()) {
            System.err.println(ErrorUtils.printParseErrors(result));
            //System.err.println("Parse Tree:\n" + ParseTreeUtils.printNodeTree(result) + '\n');
        }
        /*
         * if (length > 5000) { System.out.println("Slow parsing for " +
         * filePath + " in " + length + "ms"); System.err.println("Parse
         * Tree:\n" + ParseTreeUtils.printNodeTree(result) + '\n'); } else
         */
        {
            System.out.println("Parsed " + (lexerOnly ? "(lex only)" : "") + filePath + " in " + length + "ms");
        }

        JOTTester.checkIf("Parsing " + (lexerOnly ? "(lex only)" : "") + filePath, !result.hasErrors());
        JOTTester.checkIf("Parsing time " + (lexerOnly ? "(lex only)" : "") + filePath, length < 2000, "Took: " + length);
    } catch (Exception e) {
        JOTTester.checkIf("Exception while parsing " + (lexerOnly ? "(lex only)" : "") + filePath, false);
        e.printStackTrace();
        //throw (e);
    }
}
 
开发者ID:tcolar,项目名称:fantomidemodule,代码行数:37,代码来源:FantomParserTest.java


示例17: simpleJavaTest

import org.parboiled.parserunners.RecoveringParseRunner; //导入依赖的package包/类
@Test
public void simpleJavaTest() {
    String testSource = FileUtils.readAllTextFromResource("SimpleJavaTest.test");
    JavaParser parser = Parboiled.createParser(JavaParser.class);
    Rule compilationUnit = parser.CompilationUnit();

    assertEquals(ParserStatistics.generateFor(compilationUnit).toString(), "" +
            "Parser statistics for rule 'CompilationUnit':\n" +
            "    Total rules       : 682\n" +
            "        Actions       : 0\n" +
            "        Any           : 1\n" +
            "        CharIgnoreCase: 1\n" +
            "        Char          : 83\n" +
            "        Custom        : 2\n" +
            "        CharRange     : 7\n" +
            "        AnyOf         : 16\n" +
            "        Empty         : 0\n" +
            "        FirstOf       : 65\n" +
            "        FirstOfStrings: 4\n" +
            "        Nothing       : 0\n" +
            "        OneOrMore     : 7\n" +
            "        Optional      : 40\n" +
            "        Sequence      : 310\n" +
            "        String        : 82\n" +
            "        Test          : 0\n" +
            "        TestNot       : 13\n" +
            "        ZeroOrMore    : 51\n" +
            "\n" +
            "    Action Classes    : 0\n" +
            "    ProxyMatchers     : 14\n" +
            "    VarFramingMatchers: 0\n" +
            "MemoMismatchesMatchers: 7\n");

    ParsingResult<Object> parsingResult = new RecoveringParseRunner<Object>(compilationUnit).run(testSource);
    if (parsingResult.hasErrors()) {
        fail("\n--- ParseErrors ---\n" +
                StringUtils.join(parsingResult.parseErrors, "---\n") +
                "\n--- ParseTree ---\n" +
                printNodeTree(parsingResult, Filters.SKIP_EMPTY_OPTS_AND_ZOMS, Predicates.<Node<Object>>alwaysTrue())
        );
    }
    assertEquals(
            printTree(parsingResult.parseTreeRoot, new ToStringFormatter<Node<Object>>(),
                    Filters.SKIP_EMPTY_OPTS_AND_ZOMS, Predicates.<Node<Object>>alwaysTrue()),
            FileUtils.readAllTextFromResource("SimpleJavaTestParseTree.test")
    );
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:48,代码来源:JavaTest.java


示例18: testWithRecovery

import org.parboiled.parserunners.RecoveringParseRunner; //导入依赖的package包/类
public TestResult<V> testWithRecovery(Rule rule, String input) {
    return new TestResult<V>(new RecoveringParseRunner<V>(rule).run(input));
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:4,代码来源:ParboiledTest.java


示例19: test

import org.parboiled.parserunners.RecoveringParseRunner; //导入依赖的package包/类
@Test
public void test() {
    Parser parser = Parboiled.createParser(Parser.class);
    assertFalse(new RecoveringParseRunner(parser.Clause()).run("a").hasErrors());
    assertTrue(new RecoveringParseRunner(parser.Clause()).run("b").hasErrors());
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:7,代码来源:CurrentCharTest.java


示例20: parseLinkFilter

import org.parboiled.parserunners.RecoveringParseRunner; //导入依赖的package包/类
public static LinkFilter parseLinkFilter(String input) {

		PropertyUtils.addBeanIntrospector(new FluentPropertyBeanIntrospector());
		LinkFilterDslParser parser = Parboiled.createParser(LinkFilterDslParser.class);

		ParsingResult<LinkFilter> result = new RecoveringParseRunner<LinkFilter>(parser.Root()).run(input);

		if (result.hasErrors()) {
			throw new MandrelParseException("\nParse Errors:\n" + ErrorUtils.printParseErrors(result));
		}

		return result.parseTreeRoot.getValue();
	}
 
开发者ID:Treydone,项目名称:mandrel,代码行数:14,代码来源:DslParser.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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