Search in sources :

Example 91 with RuleCall

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

the class XtextValidationTest method testRuleCallAllowed_07.

@Test
public void testRuleCallAllowed_07() throws Exception {
    String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Model: name=ID;\n" + "terminal Terminal: Model;";
    Grammar grammar = (Grammar) getModel(grammarAsText);
    TerminalRule rule = (TerminalRule) grammar.getRules().get(1);
    RuleCall ruleCall = (RuleCall) rule.getAlternatives();
    XtextValidator validator = get(XtextValidator.class);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(ruleCall, true, false);
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkUnassignedRuleCallAllowed(ruleCall);
    validator.checkTerminalFragmentCalledFromTerminalRule(ruleCall);
    messageAcceptor.validate();
}
Also used : Grammar(org.eclipse.xtext.Grammar) TerminalRule(org.eclipse.xtext.TerminalRule) RuleCall(org.eclipse.xtext.RuleCall) Test(org.junit.Test)

Example 92 with RuleCall

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

the class XtextValidationTest method testRuleCallAllowed_02.

@Test
public void testRuleCallAllowed_02() throws Exception {
    String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Model: name=ID;\n" + "terminal fragment FirstFragment: SecondFragment;\n" + "terminal fragment SecondFragment: 'a'..'z'+;";
    Grammar grammar = (Grammar) getModel(grammarAsText);
    TerminalRule rule = (TerminalRule) grammar.getRules().get(1);
    RuleCall ruleCall = (RuleCall) rule.getAlternatives();
    XtextValidator validator = get(XtextValidator.class);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkUnassignedRuleCallAllowed(ruleCall);
    validator.checkTerminalFragmentCalledFromTerminalRule(ruleCall);
    messageAcceptor.validate();
}
Also used : Grammar(org.eclipse.xtext.Grammar) TerminalRule(org.eclipse.xtext.TerminalRule) RuleCall(org.eclipse.xtext.RuleCall) Test(org.junit.Test)

Example 93 with RuleCall

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

the class XtextValidationTest method testRuleCallAllowed_06.

@Test
public void testRuleCallAllowed_06() throws Exception {
    String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Model: name=Terminal;\n" + "terminal Terminal: Enum;\n" + "enum Enum: A | B;";
    Grammar grammar = (Grammar) getModel(grammarAsText);
    TerminalRule rule = (TerminalRule) grammar.getRules().get(1);
    RuleCall ruleCall = (RuleCall) rule.getAlternatives();
    XtextValidator validator = get(XtextValidator.class);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(ruleCall, true, false);
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkUnassignedRuleCallAllowed(ruleCall);
    validator.checkTerminalFragmentCalledFromTerminalRule(ruleCall);
    messageAcceptor.validate();
}
Also used : Grammar(org.eclipse.xtext.Grammar) TerminalRule(org.eclipse.xtext.TerminalRule) RuleCall(org.eclipse.xtext.RuleCall) Test(org.junit.Test)

Example 94 with RuleCall

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

the class XtextValidationTest method testRuleCallAllowed_03.

@Test
public void testRuleCallAllowed_03() throws Exception {
    String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Model: name=ID;\n" + "terminal fragment Fragment: Terminal;\n" + "terminal Terminal: 'a'..'z'+;";
    Grammar grammar = (Grammar) getModel(grammarAsText);
    TerminalRule rule = (TerminalRule) grammar.getRules().get(1);
    RuleCall ruleCall = (RuleCall) rule.getAlternatives();
    XtextValidator validator = get(XtextValidator.class);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkUnassignedRuleCallAllowed(ruleCall);
    validator.checkTerminalFragmentCalledFromTerminalRule(ruleCall);
    messageAcceptor.validate();
}
Also used : Grammar(org.eclipse.xtext.Grammar) TerminalRule(org.eclipse.xtext.TerminalRule) RuleCall(org.eclipse.xtext.RuleCall) Test(org.junit.Test)

Example 95 with RuleCall

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

the class XtextSerializerTest method testFQNInSuper_02.

@Ignore("Serialization does not have the correct context information")
@Test
public void testFQNInSuper_02() {
    Grammar grammar = load(URI.createURI("classpath:/org/eclipse/xtext/grammarinheritance/InheritanceTestLanguage.xtext"));
    AbstractRule rule = GrammarUtil.findRuleForName(grammar, "FQN");
    Assert.assertNotNull(rule);
    Group group = (Group) rule.getAlternatives();
    RuleCall ruleCall = (RuleCall) group.getElements().get(0);
    TerminalRule id = (TerminalRule) ruleCall.getRule();
    Assert.assertSame(grammar, GrammarUtil.getGrammar(id));
    String string = get(ISerializer.class).serialize(rule.getAlternatives());
    Assert.assertEquals("ID (\".\" ID)*", string);
    // currently wrong result is
    Assert.assertEquals("super::ID (\".\" super::ID)*", string);
}
Also used : Group(org.eclipse.xtext.Group) Grammar(org.eclipse.xtext.Grammar) TerminalRule(org.eclipse.xtext.TerminalRule) AbstractRule(org.eclipse.xtext.AbstractRule) RuleCall(org.eclipse.xtext.RuleCall) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

RuleCall (org.eclipse.xtext.RuleCall)95 ParserRule (org.eclipse.xtext.ParserRule)41 AbstractRule (org.eclipse.xtext.AbstractRule)36 EObject (org.eclipse.emf.ecore.EObject)33 Test (org.junit.Test)33 Grammar (org.eclipse.xtext.Grammar)28 AbstractElement (org.eclipse.xtext.AbstractElement)26 Assignment (org.eclipse.xtext.Assignment)22 TerminalRule (org.eclipse.xtext.TerminalRule)19 Action (org.eclipse.xtext.Action)17 CrossReference (org.eclipse.xtext.CrossReference)13 Group (org.eclipse.xtext.Group)13 TypeRef (org.eclipse.xtext.TypeRef)13 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)13 ArrayList (java.util.ArrayList)11 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)11 InternalEObject (org.eclipse.emf.ecore.InternalEObject)10 Keyword (org.eclipse.xtext.Keyword)10 EClass (org.eclipse.emf.ecore.EClass)9 EnumRule (org.eclipse.xtext.EnumRule)9