use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.
the class ParseErrorHandlingTest method testTrailingRecoverableError.
@Test
public void testTrailingRecoverableError() throws Exception {
with(TreeTestLanguageStandaloneSetup.class);
String model = "parent ('Teststring') { \n" + " child ('Teststring'){};\n" + " child ('Teststring'){};\n" + "};\n" + "};\n" + "\n";
Resource res = getResourceFromStringAndExpect(model, 1);
assertEquals(res.getErrors().size(), 1, res.getErrors().size());
Diagnostic diag = res.getErrors().get(0);
assertNotNull(diag);
assertEquals(5, diag.getLine());
Model parsedModel = (Model) res.getContents().get(0);
assertNotNull(parsedModel);
ICompositeNode composite = NodeModelUtils.getNode(parsedModel);
assertNotNull(composite);
List<ILeafNode> leafs = Lists.newArrayList(composite.getLeafNodes());
ILeafNode lastWs = leafs.get(leafs.size() - 1);
assertTrue(lastWs.isHidden());
assertNull(lastWs.getSyntaxErrorMessage());
ILeafNode lastNode = leafs.get(leafs.size() - 2);
assertFalse(lastNode.isHidden());
assertNotNull(lastNode);
assertEquals("};", lastNode.getText());
assertNotNull(lastNode.getSyntaxErrorMessage());
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.
the class ParseErrorHandlingTest method testLexerError_02.
@Test
public void testLexerError_02() throws Exception {
with(ReferenceGrammarTestLanguageStandaloneSetup.class);
String model = "spielplatz 100 '}";
EObject object = getModelAndExpect(model, 1);
ICompositeNode node = NodeModelUtils.getNode(object).getRootNode();
assertEquals(1, Iterables.size(allSyntaxErrors(node)));
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.
the class OffsetInformationTest method testCheckParsing.
@Test
public void testCheckParsing() throws Exception {
String string = "spielplatz 34 'holla' {\n" + " kind (Horst 3)\n" + " erwachsener (Julia 45)\n" + " erwachsener (Herrmann 50)\n" + " erwachsener (Herrmann 50)\n" + " erwachsener (Herrmann 50)\n" + " erwachsener (Herrmann 50)\n" + " erwachsener (Herrmann 50)\n" + "}";
XtextResource resource = getResource(new StringInputStream(string));
ICompositeNode rootNode = resource.getParseResult().getRootNode();
for (int i = 0; i < string.length() / 2; i++) {
String substring = string.substring(i, string.length() - i);
resource.update(i, substring.length(), substring);
ICompositeNode model = resource.getParseResult().getRootNode();
new InvariantChecker().checkInvariant(model);
assertSameStructure(rootNode, model);
}
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.
the class PartialParserTest method testPartialParseConcreteRuleFirstToken_02.
@Test
public void testPartialParseConcreteRuleFirstToken_02() throws Exception {
with(PartialParserTestLanguageStandaloneSetup.class);
String model = "container c1 {\n" + " children {\n" + " -> C ( ch1 )\n" + " }" + "}";
XtextResource resource = getResourceFromString(model);
assertTrue(resource.getErrors().isEmpty());
ICompositeNode root = resource.getParseResult().getRootNode();
ILeafNode children = findLeafNodeByText(root, model, "children");
// change the model and undo the change
resource.update(model.indexOf("n {") + 2, 1, " {");
resource.update(model.indexOf("n {") + 2, 2, "{");
assertSame(root, resource.getParseResult().getRootNode());
assertNotSame(children, findLeafNodeByText(root, model, "children"));
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.
the class PartialParserTest method testPartialParseConcreteRuleFirstInnerToken_01.
@Test
public void testPartialParseConcreteRuleFirstInnerToken_01() throws Exception {
with(PartialParserTestLanguageStandaloneSetup.class);
String model = "container c1 {\n" + " children {\n" + " -> C ( ch1 )\n" + " }" + "}";
XtextResource resource = getResourceFromString(model);
assertTrue(resource.getErrors().isEmpty());
ICompositeNode root = resource.getParseResult().getRootNode();
ILeafNode childrenLeaf = findLeafNodeByText(root, model, "children");
ILeafNode arrowLeaf = findLeafNodeByText(root, model, "->");
resource.update(model.indexOf("->"), 2, "->");
resource.update(model.indexOf("->"), 2, "->");
assertSame(root, resource.getParseResult().getRootNode());
assertSame(childrenLeaf, findLeafNodeByText(root, model, "children"));
assertSame(arrowLeaf, findLeafNodeByText(root, model, "->"));
}
Aggregations