Search in sources :

Example 91 with Grammar

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

the class PartialParserTest method performTest.

public void performTest(String toBeDeleted) throws Exception {
    String grammarAsText = "grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" + "generate test 'myEcoreModel'\n" + "Root: value=Test;\n" + "Test: (" + toBeDeleted.trim() + " 'foo')*;";
    XtextResource resource = getResourceFromString(grammarAsText);
    Grammar g = (Grammar) resource.getContents().get(0);
    ParserRule rule = (ParserRule) g.getRules().get(1);
    assertEquals("*", rule.getAlternatives().getCardinality());
    resource.update(grammarAsText.indexOf(toBeDeleted), toBeDeleted.length(), "");
    // make sure we did a partial parse pass
    assertSame(rule, ((Grammar) resource.getContents().get(0)).getRules().get(1));
    assertEquals("*", rule.getAlternatives().getCardinality());
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) XtextResource(org.eclipse.xtext.resource.XtextResource) Grammar(org.eclipse.xtext.Grammar)

Example 92 with Grammar

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

the class RuleWithoutInstantiationInspectorTest method testFragment_02.

@Test
public void testFragment_02() throws Exception {
    String grammarAsString = "grammar org.foo with org.eclipse.xtext.common.Terminals\n" + "generate metamodel 'foo.sample'\n" + "Model: name=ID X;\n" + "fragment X*: 'x';";
    Grammar grammar = getGrammar(grammarAsString);
    ParserRule rule = (ParserRule) GrammarUtil.findRuleForName(grammar, "X");
    validateRule(rule);
    assertTrue(warnings.toString(), warnings.isEmpty());
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 93 with Grammar

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

the class RuleWithoutInstantiationInspectorTest method testFragment_01.

@Test
public void testFragment_01() throws Exception {
    String grammarAsString = "grammar org.foo with org.eclipse.xtext.common.Terminals\n" + "generate metamodel 'foo.sample'\n" + "Model: name=ID X;\n" + "fragment X : 'x';";
    Grammar grammar = getGrammar(grammarAsString);
    ParserRule rule = (ParserRule) GrammarUtil.findRuleForName(grammar, "X");
    validateRule(rule);
    assertTrue(warnings.toString(), warnings.isEmpty());
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 94 with Grammar

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

the class RuleWithoutInstantiationInspectorTest method testAssignment_01.

@Test
public void testAssignment_01() throws Exception {
    String grammarAsString = "grammar org.foo with org.eclipse.xtext.common.Terminals\n" + "generate metamodel 'foo.sample'\n" + "Model: x=X;\n" + "X : x='x';";
    Grammar grammar = getGrammar(grammarAsString);
    ParserRule rule = (ParserRule) GrammarUtil.findRuleForName(grammar, "X");
    validateRule(rule);
    assertTrue(warnings.toString(), warnings.isEmpty());
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 95 with Grammar

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

the class RuleWithoutInstantiationInspectorTest method testIgnoreFirstRule_01.

@Test
public void testIgnoreFirstRule_01() throws Exception {
    String grammarAsString = "grammar org.foo with org.eclipse.xtext.common.Terminals\n" + "generate metamodel 'foo.sample'\n" + "X : (x+='x')*;";
    Grammar grammar = getGrammar(grammarAsString);
    ParserRule rule = (ParserRule) GrammarUtil.findRuleForName(grammar, "X");
    validateRule(rule);
    assertTrue(warnings.toString(), warnings.isEmpty());
}
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