Search in sources :

Example 46 with TerminalRule

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

the class XtextValidationTest method testRuleCallAllowed_01.

@Test
public void testRuleCallAllowed_01() throws Exception {
    String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Model: name=ID;\n" + "terminal MyTerminal: Fragment;\n" + "terminal fragment Fragment: '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 47 with TerminalRule

use of org.eclipse.xtext.TerminalRule 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 48 with TerminalRule

use of org.eclipse.xtext.TerminalRule 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 49 with TerminalRule

use of org.eclipse.xtext.TerminalRule 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 50 with TerminalRule

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

Aggregations

TerminalRule (org.eclipse.xtext.TerminalRule)51 ParserRule (org.eclipse.xtext.ParserRule)21 AbstractRule (org.eclipse.xtext.AbstractRule)20 RuleCall (org.eclipse.xtext.RuleCall)19 EnumRule (org.eclipse.xtext.EnumRule)17 Grammar (org.eclipse.xtext.Grammar)17 Test (org.junit.Test)16 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)12 AbstractElement (org.eclipse.xtext.AbstractElement)10 EObject (org.eclipse.emf.ecore.EObject)6 Action (org.eclipse.xtext.Action)6 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)5 Assignment (org.eclipse.xtext.Assignment)5 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 EClass (org.eclipse.emf.ecore.EClass)4 Alternatives (org.eclipse.xtext.Alternatives)4 Group (org.eclipse.xtext.Group)4 Keyword (org.eclipse.xtext.Keyword)4