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


Java ParsingResult.hasErrors方法代码示例

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


在下文中一共展示了ParsingResult.hasErrors方法的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: 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

示例5: 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

示例6: main

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

示例7: main

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

示例8: parseUnit

import org.parboiled.support.ParsingResult; //导入方法依赖的package包/类
private Unit parseUnit(String templateText) throws Exception {
  ParsingResult<Object> result = new ReportingParseRunner<>(parser.Unit()).run(templateText);

  if (result.hasErrors()) {
    String errors = ErrorUtils.printParseErrors(result.parseErrors);
    throw new Exception(errors);
  }

  return (Unit) Iterables.getOnlyElement(result.valueStack);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:Processor.java

示例9: parse

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

示例10: parse

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

示例11: parse

import org.parboiled.support.ParsingResult; //导入方法依赖的package包/类
@Override
public Node parse(Environment environment, ResourceReference resource) {
    ResourceService resourceService = environment.getResourceEnvironment().getResourceService();
    BasicParseRunner<Node> runner = new BasicParseRunner<Node>(
            ParserContext.instance(resource, configuration,
                    configuration.getAddonParserProviders(),
                    configuration.getUnaryOperators(),
                    configuration.getBinaryOperators(),
                    configuration.getTestExpressionParsers())
                    .parser(DocumentParser.class)
                    .NodeRule()
    );

    try {
        ResourceMetadata resourceMetadata = resourceService.loadMetadata(resource);
        Charset charset = resourceMetadata.getCharset()
                .or(environment.getResourceEnvironment().getDefaultInputCharset());
        ParsingResult<Node> result = runner.run(readAllText(resourceMetadata.load(), charset));
        if (result.hasErrors()) {
            throw new ParseException(toMessage(result.parseErrors));
        } else if (!result.matched) {
            throw new ParseException("Invalid template format");
        } else {
            return result.valueStack.pop();
        }
    } catch (ParserRuntimeException e) {
        if ((e.getCause() != null) && (e.getCause() instanceof ParseException)) {
            ParseException cause = (ParseException) e.getCause();
            throw new ParseException(String.format("%s\n%s", cause.getMessage(), exceptionMessageExtractor.extract(e)), cause.getCause());
        } else {
            throw new ParseException(e);
        }
    }
}
 
开发者ID:jtwig,项目名称:jtwig-core,代码行数:35,代码来源:ParboiledJtwigParser.java

示例12: twoBounds

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

示例13: main

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

示例14: test

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

示例15: main

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


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