use of org.eclipse.xtext.parser.IParseResult in project xtext-core by eclipse.
the class XtextResource method doLoad.
@Override
protected void doLoad(InputStream inputStream, Map<?, ?> options) throws IOException {
setEncodingFromOptions(options);
IParseResult result;
if (entryPoint == null) {
result = parser.parse(createReader(inputStream));
} else {
result = parser.parse(entryPoint, createReader(inputStream));
}
updateInternalState(this.parseResult, result);
}
use of org.eclipse.xtext.parser.IParseResult in project xtext-core by eclipse.
the class XtextResource method update.
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 = parser.reparse(oldParseResult, replaceRegion);
} else {
StringBuilder builder = new StringBuilder(oldParseResult.getRootNode().getText());
replaceRegion.applyTo(builder);
newParseResult = parser.parse(entryPoint, new StringReader(builder.toString()));
}
updateInternalState(oldParseResult, newParseResult);
} finally {
isUpdating = false;
}
}
use of org.eclipse.xtext.parser.IParseResult in project xtext-core by eclipse.
the class AbstractPackratParser method parse.
protected final IParseResult parse(INonTerminalConsumer consumer) {
if (activeMarker != null)
throw new IllegalStateException("cannot parse now. Active marker is already assigned.");
IMarker rootMarker = mark();
IRootConsumerListener listener = new RootConsumerListener();
try {
consumer.consumeAsRoot(listener);
IParseResult result = getParseResultFactory().createParseResult(activeMarker, input);
rootMarker.commit();
if (activeMarker != null)
throw new IllegalStateException("cannot finish parse: active marker is still present.");
return result;
} catch (Exception e) {
throw new WrappedException(e);
}
}
use of org.eclipse.xtext.parser.IParseResult in project xtext-core by eclipse.
the class Bug419429Test method replaceAndReparse.
protected void replaceAndReparse(String model, int offset, int length, String change, String expectedReparseRegion) throws Exception {
IParseResult parseResult = getParseResultAndExpect(model, UNKNOWN_EXPECTATION);
PartialParsingPointers parsingPointers = getPartialParser().calculatePartialParsingPointers(parseResult, offset, length);
String reparseRegion = getPartialParser().insertChangeIntoReplaceRegion(parsingPointers.getDefaultReplaceRootNode(), new ReplaceRegion(offset, length, change));
assertEquals(expectedReparseRegion, reparseRegion);
final Wrapper<Boolean> unloaded = Wrapper.wrap(Boolean.FALSE);
getPartialParser().setUnloader(new IReferableElementsUnloader() {
@Override
public void unloadRoot(EObject root) {
unloaded.set(Boolean.TRUE);
}
});
IParseResult partiallyReparse = reparse(parseResult, offset, length, change);
assertTrue("unloaded", unloaded.get());
String expectedReparseModel = model.substring(0, offset) + change + model.substring(offset + length);
assertEquals(expectedReparseModel, partiallyReparse.getRootNode().getText());
compareWithFullParse(model, offset, length, change);
}
use of org.eclipse.xtext.parser.IParseResult in project xtext-core by eclipse.
the class PartialParserTest method testInsertSlashInSecondNode.
@Test
public void testInsertSlashInSecondNode() throws Exception {
IParseResult parseResult = resource.getParser().reparse(this.parseResult, new ReplaceRegion(model.indexOf('6'), 0, "/"));
assertFalse(parseResult.hasSyntaxErrors());
assertEquals(0, parseResult.getRootNode().getTotalOffset());
assertSame(resource.getParseResult().getRootNode(), parseResult.getRootNode());
String newModel = "a.b.c.d: 123;\n" + "e.f.g.h: 45/6;";
EmfAssert.assertEObjectsEqual(getModel(newModel), resource.getParseResult().getRootASTElement());
}
Aggregations