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


Java RecoveringParseRunner类代码示例

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


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


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