org.eclipse.xtext.parser.ParseException Java Examples

The following examples show how to use org.eclipse.xtext.parser.ParseException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Bug297909Test.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testReconcileDocument() throws Exception {
	Injector injector = doGetSetup().createInjectorAndDoEMFRegistration();
	XtextDocument document = injector.getInstance(XtextDocument.class);
	document.setValidationJob(new Job("Job") {
		@Override
		protected IStatus run(IProgressMonitor monitor) {
			return Status.OK_STATUS;
		}
	});
	XtextResource resource = injector.getInstance(XtextResource.class);
	XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
	resourceSet.getResources().add(resource);
	resource.load(new StringInputStream(""), Collections.singletonMap(XtextResource.OPTION_ENCODING, Charset.defaultCharset().name()));
	document.setInput(resource);
	document.set("abstract rules firstRule");
	XtextDocumentReconcileStrategy strategy = injector.getInstance(XtextDocumentReconcileStrategy.class);
	strategy.setDocument(document);
	strategy.setResource(resource);
	try {
		strategy.reconcile(new ReconcilerReplaceRegion(0, document.getLength(), document.get()));
		fail("Expected ParseException");
	} catch(ParseException expected) {
		assertTrue(expected.getMessage().contains("Make sure the EPackage has been registered"));
	}
}
 
Example #2
Source File: AbstractAntlrParser.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
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);
	}
}
 
Example #3
Source File: TokenSequencePreservingPartialParsingHelper.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example #4
Source File: Bug297909Test.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testExceptionOnContentAssist() throws Exception {
	try {
		newBuilder().append("abstract rules firstRule ").assertCount(0);
		fail("Expected ParseException");
	} catch(ParseException expected) {
		assertTrue(expected.getMessage().contains("Make sure the EPackage has been registered"));
	}
}
 
Example #5
Source File: ParseErrorHandlingTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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);
	}
}