Search in sources :

Example 56 with ICompositeNode

use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.

the class PartialParserTest method testGrammarElementAssigned.

@Test
public void testGrammarElementAssigned() throws Exception {
    with(ReferenceGrammarTestLanguageStandaloneSetup.class);
    String model = "spielplatz 1 {kind (k 1)\n}";
    XtextResource resource = getResourceFromString(model);
    ICompositeNode rootNode = resource.getParseResult().getRootNode();
    checkGrammarAssigned(rootNode);
    IParseResult reparse = reparse(resource.getParseResult(), model.length() - 2, 0, "\n");
    rootNode = reparse.getRootNode();
    checkGrammarAssigned(rootNode);
}
Also used : ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 57 with ICompositeNode

use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.

the class PartialParserTest method testPartialParseConcreteRuleInnermostToken_02.

@Test
public void testPartialParseConcreteRuleInnermostToken_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 childrenLeaf = findLeafNodeByText(root, model, "children");
    ILeafNode ch1Leaf = findLeafNodeByText(root, model, "ch1");
    // change the model and undo the change
    resource.update(model.indexOf("ch1") + 1, 1, "x");
    resource.update(model.indexOf("ch1") + 1, 1, "h");
    assertSame(root, resource.getParseResult().getRootNode());
    assertSame(childrenLeaf, findLeafNodeByText(root, model, "children"));
    assertNotSame(ch1Leaf, findLeafNodeByText(root, model, "ch1"));
}
Also used : ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 58 with ICompositeNode

use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.

the class PartialParserTest method testPartialParseConcreteRuleFirstInnerToken_02.

@Test
public void testPartialParseConcreteRuleFirstInnerToken_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 childrenLeaf = findLeafNodeByText(root, model, "children");
    ILeafNode arrowLeaf = findLeafNodeByText(root, model, "->");
    // change the model and undo the change
    resource.update(model.indexOf("->"), 2, "-> ");
    resource.update(model.indexOf("->"), 3, "->");
    assertSame(root, resource.getParseResult().getRootNode());
    assertSame(childrenLeaf, findLeafNodeByText(root, model, "children"));
    assertNotSame(arrowLeaf, findLeafNodeByText(root, model, "->"));
}
Also used : ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 59 with ICompositeNode

use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.

the class PartialParserTest method testPartialParseConcreteRuleInnerToken.

@Test
public void testPartialParseConcreteRuleInnerToken() 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 cLeaf = findLeafNodeByText(root, model, "C");
    resource.update(model.indexOf("C"), 1, "C");
    resource.update(model.indexOf("C"), 1, "C");
    assertSame(root, resource.getParseResult().getRootNode());
    assertSame(childrenLeaf, findLeafNodeByText(root, model, "children"));
    assertNotSame(cLeaf, findLeafNodeByText(root, model, "ch1"));
}
Also used : ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 60 with ICompositeNode

use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.

the class XtextParserBugsTest method testFirstTokenIsIllegal_254841.

@Test
public void testFirstTokenIsIllegal_254841() throws Exception {
    with(FowlerDslTestLanguageStandaloneSetup.class);
    String model = "firstToken";
    ICompositeNode rootNode = getRootNodeAndExpect(model, 1);
    assertNotNull(rootNode);
}
Also used : ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) Test(org.junit.Test)

Aggregations

ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)263 Test (org.junit.Test)87 INode (org.eclipse.xtext.nodemodel.INode)79 EObject (org.eclipse.emf.ecore.EObject)70 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)57 XtextResource (org.eclipse.xtext.resource.XtextResource)41 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)24 ReplaceRegion (org.eclipse.xtext.util.ReplaceRegion)20 Resource (org.eclipse.emf.ecore.resource.Resource)19 Model (org.eclipse.xtext.valueconverter.bug250313.Model)15 IParseResult (org.eclipse.xtext.parser.IParseResult)14 ParserRule (org.eclipse.xtext.ParserRule)12 ITextRegion (org.eclipse.xtext.util.ITextRegion)12 RuleCall (org.eclipse.xtext.RuleCall)11 CrossReference (org.eclipse.xtext.CrossReference)10 ArrayList (java.util.ArrayList)8 List (java.util.List)8 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)8 AbstractRule (org.eclipse.xtext.AbstractRule)8 Keyword (org.eclipse.xtext.Keyword)8