Java 类org.eclipse.xtext.parser.ParseException 实例源码

项目:xtext-core    文件:AbstractAntlrParser.java   
protected IParseResult doParse(String ruleName, CharStream in, NodeModelBuilder nodeModelBuilder, int initialLookAhead) {
    TokenSource tokenSource = createLexer(in);
    XtextTokenStream tokenStream = createTokenStream(tokenSource);
    tokenStream.initCurrentLookAhead(initialLookAhead);
    setInitialHiddenTokens(tokenStream);
    AbstractInternalAntlrParser parser = createParser(tokenStream);
    parser.setTokenTypeMap(getTokenDefProvider().getTokenDefMap());
    parser.setSyntaxErrorProvider(getSyntaxErrorProvider());
    parser.setNodeModelBuilder(nodeModelBuilder);
    parser.setSemanticModelBuilder(getElementFactory());
    IUnorderedGroupHelper helper = getUnorderedGroupHelper().get();
    parser.setUnorderedGroupHelper(helper);
    helper.initializeWith(parser);
    try {
        if(ruleName != null)
            return parser.parse(ruleName);
        return parser.parse();
    } catch (Exception re) {
        throw new ParseException(re.getMessage(),re);
    }
}
项目:xtext-extras    文件:TokenSequencePreservingPartialParsingHelper.java   
protected IParseResult doParseRegion(IParser parser, PartialParsingPointers parsingPointers,
        ICompositeNode replaceMe, String reparseRegion) {
    EObject entryRuleOrRuleCall = parsingPointers.findEntryRuleOrRuleCall(replaceMe);
    IParseResult newParseResult = null;
    try {
        if (entryRuleOrRuleCall instanceof RuleCall)
            newParseResult = parser.parse((RuleCall)entryRuleOrRuleCall, new StringReader(reparseRegion), replaceMe.getLookAhead());
        else
            newParseResult = parser.parse((ParserRule)entryRuleOrRuleCall, new StringReader(reparseRegion));
    } catch (ParseException exc) {
    }
    return newParseResult;
}
项目:xtext-core    文件:ParseErrorHandlingTest.java   
@Test public void testExpectNoSuchMethodException() throws Exception {
    IParser parser = get(IParser.class);
    ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
    parserRule.setName("ruleDoesNotExist");
    try {
        parser.parse(parserRule, new StringReader("empty"));
        fail("Expected WrappedException");
    } catch(ParseException e) {
        assertTrue(e.getCause() instanceof WrappedException);
        WrappedException cause = (WrappedException) e.getCause();
        assertTrue(cause.getCause() instanceof NoSuchMethodException);
    }
}