Java Code Examples for org.eclipse.xtext.nodemodel.util.NodeModelUtils#getEntryParserRule()

The following examples show how to use org.eclipse.xtext.nodemodel.util.NodeModelUtils#getEntryParserRule() . 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: XtextResource.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public void update(int offset, int replacedTextLength, String newText) {
	if (!isLoaded()) {
		throw new IllegalStateException("You can't update an unloaded resource.");
	}
	try {
		isUpdating = true;
		IParseResult oldParseResult = parseResult;
		ReplaceRegion replaceRegion = new ReplaceRegion(new TextRegion(offset, replacedTextLength), newText);
		IParseResult newParseResult;
		ParserRule oldEntryPoint = NodeModelUtils.getEntryParserRule(oldParseResult.getRootNode());
		if (entryPoint == null || entryPoint == oldEntryPoint) {
			newParseResult = getParser().reparse(oldParseResult, replaceRegion);
		} else {
			StringBuilder builder = new StringBuilder(oldParseResult.getRootNode().getText());
			replaceRegion.applyTo(builder);
			newParseResult = getParser().parse(entryPoint, new StringReader(builder.toString()));
		}
		updateInternalState(oldParseResult, newParseResult);
	} finally {
		isUpdating = false;
	}
}
 
Example 2
Source File: PartialParsingHelper.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected IParseResult fullyReparse(IParser parser, IParseResult previousParseResult, ReplaceRegion replaceRegion) {
	unloadSemanticObject(previousParseResult.getRootASTElement());
	ICompositeNode node = previousParseResult.getRootNode();
	ParserRule parserRule = NodeModelUtils.getEntryParserRule(node);
	String reparseRegion = insertChangeIntoReplaceRegion(previousParseResult.getRootNode(), replaceRegion);
	return parser.parse(parserRule, new StringReader(reparseRegion));
}
 
Example 3
Source File: SetEntryPointOnXtextResourceTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test2() throws Exception {
	with(ActionTestLanguage3StandaloneSetup.class);
	ParserRule rule = get(ActionTestLanguage3GrammarAccess.class).getProductionRule1Rule();
	String model = "X \"Y\" 42";
	XtextResource resource = createResource();
	resource.setEntryPoint(rule);
	resource.load(new StringInputStream(model), Collections.emptyMap());
	Assert.assertTrue(resource.getErrors().isEmpty());
	ParserRule entryRule = NodeModelUtils.getEntryParserRule(resource.getParseResult().getRootNode());
	Assert.assertEquals(rule, entryRule);
}
 
Example 4
Source File: SetEntryPointOnXtextResourceTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test3() throws Exception {
	with(ActionTestLanguage3StandaloneSetup.class);
	ParserRule rule = get(ActionTestLanguage3GrammarAccess.class).getProductionRule2Rule();
	String model = "\"Y\" X42";
	XtextResource resource = createResource();
	resource.setEntryPoint(rule);
	resource.load(new StringInputStream(model), Collections.emptyMap());
	Assert.assertTrue(resource.getErrors().isEmpty());
	ParserRule entryRule = NodeModelUtils.getEntryParserRule(resource.getParseResult().getRootNode());
	Assert.assertEquals(rule, entryRule);
}
 
Example 5
Source File: XtextResource.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public ParserRule getEntryPoint() {
	if (entryPoint == null && parseResult != null) {
		entryPoint = NodeModelUtils.getEntryParserRule(parseResult.getRootNode());
	}
	return entryPoint;
}