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


Java ReportingParseRunner.run方法代码示例

本文整理汇总了Java中org.parboiled.parserunners.ReportingParseRunner.run方法的典型用法代码示例。如果您正苦于以下问题:Java ReportingParseRunner.run方法的具体用法?Java ReportingParseRunner.run怎么用?Java ReportingParseRunner.run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.parboiled.parserunners.ReportingParseRunner的用法示例。


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

示例1: main

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

示例2: parse

import org.parboiled.parserunners.ReportingParseRunner; //导入方法依赖的package包/类
private static ValueStack<Object> parse(String query, Rule ruleTree) {
    ReportingParseRunner<Object> runner = new ReportingParseRunner<>(ruleTree);
    ParsingResult<Object> result = runner.run(query);

    if (!result.matched || result.hasErrors()) {
        throw new IllegalArgumentException("Invalid query: " + printParseErrors(result));
    }

    return result.valueStack;
}
 
开发者ID:edmocosta,项目名称:queryfy,代码行数:11,代码来源:Evaluator.java

示例3: parse

import org.parboiled.parserunners.ReportingParseRunner; //导入方法依赖的package包/类
public static ValueStack<Object> parse(String expression, Rule ruleTree) {
    ReportingParseRunner<Object> runner = new ReportingParseRunner<>(ruleTree);
    ParsingResult<Object> result = runner.run(expression);

    if (!result.matched || result.hasErrors()) {
        throw new IllegalArgumentException("Invalid query: " + printParseErrors(result));
    }

    return result.valueStack;
}
 
开发者ID:edmocosta,项目名称:queryfy,代码行数:11,代码来源:ExpressionParserUtils.java

示例4: twoBounds

import org.parboiled.parserunners.ReportingParseRunner; //导入方法依赖的package包/类
@Test
public void twoBounds() {
    DomainParserGrammar.DomainGrammar parser = Parboiled.createParser(DomainParserGrammar.DomainGrammar.class);
    ReportingParseRunner<?> runner = new ReportingParseRunner(parser.Domain());
    ParsingResult<?> result = runner.run("R(1.0:2.0),R(1.0:5.0)");

    if (result.hasErrors()) {
        for (ParseError e : result.parseErrors) {
            Assert.fail();
        }
    }
}
 
开发者ID:collinprice,项目名称:thesis-cilib,代码行数:13,代码来源:DomainParserGrammarTest.java

示例5: sequence

import org.parboiled.parserunners.ReportingParseRunner; //导入方法依赖的package包/类
@Test
public void sequence() {
    DomainParserGrammar.DomainGrammar parser = Parboiled.createParser(DomainParserGrammar.DomainGrammar.class);
    ReportingParseRunner<?> runner = new ReportingParseRunner(parser.Domain());
    ParsingResult<?> result = runner.run("R(-1.0:2.0),R(1.0:2.0)");

    ValueStack<Real> s = (ValueStack<Real>) result.valueStack;

    Assert.assertThat(s.size(), equalTo(2));
    Assert.assertThat(s.peek().getBounds().getLowerBound(), equalTo(1.0));
    s.pop();
    Assert.assertThat(s.peek().getBounds().getLowerBound(), equalTo(-1.0));
}
 
开发者ID:collinprice,项目名称:thesis-cilib,代码行数:14,代码来源:DomainParserGrammarTest.java

示例6: boundless

import org.parboiled.parserunners.ReportingParseRunner; //导入方法依赖的package包/类
@Test
public void boundless() {
    DomainParserGrammar.DomainGrammar parser = Parboiled.createParser(DomainParserGrammar.DomainGrammar.class);
    ReportingParseRunner<?> runner = new ReportingParseRunner(parser.Domain());
    ParsingResult<?> result = runner.run("Z");

    ValueStack<?> s = result.valueStack;

    Assert.assertThat(s.size(), equalTo(1));
}
 
开发者ID:collinprice,项目名称:thesis-cilib,代码行数:11,代码来源:DomainParserGrammarTest.java

示例7: parse

import org.parboiled.parserunners.ReportingParseRunner; //导入方法依赖的package包/类
public String parse(String input) {
    try {

        ReportingParseRunner runner = new ReportingParseRunner <>((Rule)entryPointMethod.invoke(parser));

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


        if (!result.parseErrors.isEmpty()) {
            throw new GrammarException(ErrorUtils.printParseError(result.parseErrors.get(0)));
        } else {
            return ParseTreeUtils.printNodeTree(result) + '\n';
        }

    } catch (IllegalAccessException | InvocationTargetException e) {

        throw new GrammarException(e);
    }

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

示例8: parse

import org.parboiled.parserunners.ReportingParseRunner; //导入方法依赖的package包/类
/**
     * Parse the provided domain string and return the constructed representation.
     * @param <E> The structured type.
     * @param domain The string to parse.
     * @return A {@code TypeList} is returned by default, but if the type is defined
     *         to consist of {@code Numeric} types, a {@code Vector} instance is returned.
     */
    public synchronized static <E extends StructuredType<? extends Type>> E parse(String domain) {
    	
        final ReportingParseRunner<String> expander = new ReportingParseRunner<String>(EXPANDING_PARSER.Expansion());
        final ParsingResult<String> d = expander.run(domain.replaceAll(" ", ""));
        
        if (d.hasErrors()) {
            StringBuilder strBuilder = new StringBuilder();
            for (ParseError e : d.parseErrors) {
                strBuilder.append(e.getInputBuffer().extract(e.getStartIndex(), e.getEndIndex()));
            }
            throw new RuntimeException("Error in expanding domain: " + domain + " near: " + strBuilder.toString());
        }
        
//        System.out.println(d.valueStack.size());
//        System.out.println("Creating vector");
        Vector.Builder builder = Vector.newBuilder();
        for (int i = 0; i < d.valueStack.size(); i++) {
			builder.add(Real.valueOf(0));
		}
        Vector myVector = builder.build();
//        System.out.println("Created vector of size: " + myVector.size());
        
        return (E) myVector;
//        .add(Real.valueOf(1.0)).add(Real.valueOf(2.0)).add(Real.valueOf(3.0));
//        tmpVector = builder.build();
        
//        System.out.println(d.valueStack.peek());
//        final String expanded = Joiner.on(",").join(d.valueStack);
//        final ReportingParseRunner<?> runner = new ReportingParseRunner(DOMAIN_PARSER.Domain());
//        
//        System.out.println("Before Fail");
//        System.out.println(expanded);
//        final ParsingResult<Type> result = (ParsingResult<Type>) runner.run(expanded);
//        System.out.println("in parser");
//        if (result.hasErrors()) {
//            StringBuilder strBuilder = new StringBuilder();
//            for (ParseError e : result.parseErrors) {
//                strBuilder.append(e.getInputBuffer().extract(e.getStartIndex(), e.getEndIndex()));
//            }
//            throw new RuntimeException("Error in parsing domain: " + expanded +
//                    ". Ensure that the domain is a valid domain string and contains no whitespace.\nError occurred near: " + strBuilder.toString());
//        }
//        System.out.println(result.valueStack.size());
//        System.out.println(result.valueStack.peek());
//        System.out.println(result.valueStack.peek(1));
//        System.out.println("in parser");
//        System.out.println(result.valueStack);
//        List<Type> l = Lists.newArrayList(result.valueStack);
//        System.out.println("in parser");
//        if (isVector(l)) {
//        	System.out.println("is vector");
//            @SuppressWarnings("unchecked")
//            E vector = (E) toVector(l);
//            return vector;
//        }
//
//        return (E) toTypeList(l);
    }
 
开发者ID:collinprice,项目名称:thesis-cilib,代码行数:66,代码来源:DomainParser.java

示例9: parse

import org.parboiled.parserunners.ReportingParseRunner; //导入方法依赖的package包/类
public GrammarNode parse(String input) {

        ReportingParseRunner runner = new ReportingParseRunner(Grammar());

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

        GrammarNode grammarNode = (GrammarNode) result.resultValue;

        if(grammarNode == null){
            throw new ParseException(ErrorUtils.printParseError(result.parseErrors.get(0)));
        }

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


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