Search in sources :

Example 86 with Grammar

use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.

the class CrossContainmentTest method testCrossContainment_01.

@Test
public void testCrossContainment_01() {
    XtextResourceSet resourceSet = get(XtextResourceSet.class);
    resourceSet.setClasspathURIContext(getClass());
    Resource resource = resourceSet.createResource(URI.createFileURI("container.xmi"));
    Resource childResource = resourceSet.createResource(URI.createFileURI("child.xmi"));
    CrossResourceContainerManyChildren container = PartialParsingTestUtilFactory.eINSTANCE.createCrossResourceContainerManyChildren();
    resource.getContents().add(container);
    Grammar grammar = XtextFactory.eINSTANCE.createGrammar();
    childResource.getContents().add(grammar);
    assertNull(grammar.eContainer());
    container.getChildren().add(grammar);
    assertSame(container, grammar.eContainer());
    assertSame(childResource, grammar.eResource());
    assertSame(resource, container.eResource());
}
Also used : CrossResourceContainerManyChildren(org.eclipse.xtext.parser.partialParsingTestUtil.CrossResourceContainerManyChildren) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Resource(org.eclipse.emf.ecore.resource.Resource) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 87 with Grammar

use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.

the class CrossContainmentTest method testCrossContainment_02.

@Test
public void testCrossContainment_02() {
    XtextResourceSet resourceSet = get(XtextResourceSet.class);
    resourceSet.setClasspathURIContext(getClass());
    Resource resource = resourceSet.createResource(URI.createFileURI("container.xmi"));
    Resource childResource = resourceSet.createResource(URI.createFileURI("child.xmi"));
    CrossResourceContainerOneChild container = PartialParsingTestUtilFactory.eINSTANCE.createCrossResourceContainerOneChild();
    resource.getContents().add(container);
    Grammar grammar = XtextFactory.eINSTANCE.createGrammar();
    childResource.getContents().add(grammar);
    assertNull(grammar.eContainer());
    container.setChild(grammar);
    assertSame(container, grammar.eContainer());
    assertSame(childResource, grammar.eResource());
    assertSame(resource, container.eResource());
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Resource(org.eclipse.emf.ecore.resource.Resource) CrossResourceContainerOneChild(org.eclipse.xtext.parser.partialParsingTestUtil.CrossResourceContainerOneChild) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 88 with Grammar

use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.

the class Bug290919Test method testBug2900919.

@Test
public void testBug2900919() throws Exception {
    String grammarAsString = "grammar org.xtext.example.MyDsl with org.eclipse.xtext.common.Terminals\n" + "generate myDsl \"http://www.xtext.org/example/MyDsl\"\n" + "\n" + "TModel :\n" + "    element=TElement\n" + ";\n" + "\n" + "TElement :\n" + "    TSimpleElement | TSimpleElement2\n" + ";\n" + "\n" + "TSimpleElement:\n" + "(annotations+=TAnnotation)*\n" + "'simpleElement' name=ID\n" + ";\n" + "\n" + "TSimpleElement2:\n" + "(annotations+=TAnnotation)*\n" + "'simpleElement2' name=ID ;\n" + "\n" + "\n" + "TAnnotation:\n" + "    TDescriptionAnnotation | TUuidAnnotation\n" + ";\n" + "\n" + "TDescriptionAnnotation:\n" + "    value = STRING \n" + ";\n" + "\n" + "TUuidAnnotation:\n" + "    value = INT\n" + ";";
    Grammar grammar = (Grammar) getModel(grammarAsString);
    GrammarWithoutLeftRecursionInspector inspector = new GrammarWithoutLeftRecursionInspector(this);
    inspector.inspect(grammar);
}
Also used : Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 89 with Grammar

use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.

the class KeywordInspectorTest method testBug285146_02.

@Test
public void testBug285146_02() throws Exception {
    String grammarAsString = "grammar org.xtext.example.MyDsl7 with org.eclipse.xtext.common.Terminals\n" + "generate myDsl \"http://www.xtext.org/example/MyDsl\"\n" + "Type : 'type' '#' name=ID;\n" + "terminal POUND: '#'?;";
    Grammar grammar = getGrammar(grammarAsString);
    ParserRule rule = (ParserRule) GrammarUtil.findRuleForName(grammar, "Type");
    validateRule(rule);
    assertEquals(errors.toString(), 0, errors.size());
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 90 with Grammar

use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.

the class KeywordInspectorTest method testBug285146_04.

@Test
public void testBug285146_04() throws Exception {
    String grammarAsString = "grammar org.xtext.example.MyDsl7 with org.eclipse.xtext.common.Terminals\n" + "generate myDsl \"http://www.xtext.org/example/MyDsl\"\n" + "Type : 'type' '#' name=ID;\n" + "terminal POUND: '#' '#';";
    Grammar grammar = getGrammar(grammarAsString);
    ParserRule rule = (ParserRule) GrammarUtil.findRuleForName(grammar, "Type");
    validateRule(rule);
    assertEquals(errors.toString(), 0, errors.size());
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Aggregations

Grammar (org.eclipse.xtext.Grammar)356 Test (org.junit.Test)273 ParserRule (org.eclipse.xtext.ParserRule)151 AbstractRule (org.eclipse.xtext.AbstractRule)106 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)101 EObject (org.eclipse.emf.ecore.EObject)70 AbstractXtextRuleInspectorTest (org.eclipse.xtext.xtext.AbstractXtextRuleInspectorTest)49 XtextResource (org.eclipse.xtext.resource.XtextResource)33 RuleCall (org.eclipse.xtext.RuleCall)28 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)23 TypeReference (org.eclipse.xtext.xtext.generator.model.TypeReference)23 AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)21 Assignment (org.eclipse.xtext.Assignment)21 EPackage (org.eclipse.emf.ecore.EPackage)20 AbstractElement (org.eclipse.xtext.AbstractElement)17 TerminalRule (org.eclipse.xtext.TerminalRule)17 Resource (org.eclipse.emf.ecore.resource.Resource)16 EClassifier (org.eclipse.emf.ecore.EClassifier)13 InternalEObject (org.eclipse.emf.ecore.InternalEObject)13 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)12