Search in sources :

Example 96 with ParserRule

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

the class TreeTestLanguageSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == TreeTestLanguagePackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case TreeTestLanguagePackage.MODEL:
                sequence_Model(context, (Model) semanticObject);
                return;
            case TreeTestLanguagePackage.NODE:
                sequence_Node(context, (Node) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) Node(org.eclipse.xtext.testlanguages.treeTestLanguage.Node) Model(org.eclipse.xtext.testlanguages.treeTestLanguage.Model) Parameter(org.eclipse.xtext.Parameter) EPackage(org.eclipse.emf.ecore.EPackage)

Example 97 with ParserRule

use of org.eclipse.xtext.ParserRule 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 98 with ParserRule

use of org.eclipse.xtext.ParserRule 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)

Example 99 with ParserRule

use of org.eclipse.xtext.ParserRule 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 100 with ParserRule

use of org.eclipse.xtext.ParserRule 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)

Aggregations

ParserRule (org.eclipse.xtext.ParserRule)380 Test (org.junit.Test)172 Grammar (org.eclipse.xtext.Grammar)151 Action (org.eclipse.xtext.Action)144 Parameter (org.eclipse.xtext.Parameter)137 EPackage (org.eclipse.emf.ecore.EPackage)126 AbstractRule (org.eclipse.xtext.AbstractRule)94 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)74 AbstractXtextRuleInspectorTest (org.eclipse.xtext.xtext.AbstractXtextRuleInspectorTest)49 RuleCall (org.eclipse.xtext.RuleCall)41 EObject (org.eclipse.emf.ecore.EObject)27 EnumRule (org.eclipse.xtext.EnumRule)21 TerminalRule (org.eclipse.xtext.TerminalRule)21 AbstractElement (org.eclipse.xtext.AbstractElement)18 Assignment (org.eclipse.xtext.Assignment)15 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)12 EClass (org.eclipse.emf.ecore.EClass)11 Group (org.eclipse.xtext.Group)11 NamedArgument (org.eclipse.xtext.NamedArgument)11 TypeRef (org.eclipse.xtext.TypeRef)11