Search in sources :

Example 36 with AbstractRule

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

the class OverriddenValueInspectorTest method testFragment_09.

@Test
public void testFragment_09() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
    _builder.newLine();
    _builder.append("generate metamodel \'foo.sample\'");
    _builder.newLine();
    _builder.append("EntryRule:");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("name=ID FragmentWithAction");
    _builder.newLine();
    _builder.append(";");
    _builder.newLine();
    _builder.append("fragment FragmentWithAction returns EntryRule:");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("name=ID {EntryRule.prev=current}");
    _builder.newLine();
    _builder.append(";");
    _builder.newLine();
    String grammarAsString = _builder.toString();
    final Grammar grammar = this.getGrammar(grammarAsString);
    AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "EntryRule");
    final ParserRule rule = ((ParserRule) _findRuleForName);
    this.validateRule(rule);
    Assert.assertEquals(this.warnings.toString(), 2, this.warnings.size());
    AbstractRule _findRuleForName_1 = GrammarUtil.findRuleForName(grammar, "FragmentWithAction");
    final ParserRule fragment = ((ParserRule) _findRuleForName_1);
    this.validateRule(fragment);
    Assert.assertEquals(this.warnings.toString(), 0, this.warnings.size());
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule) Test(org.junit.Test) AbstractXtextRuleInspectorTest(org.eclipse.xtext.xtext.AbstractXtextRuleInspectorTest)

Example 37 with AbstractRule

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

the class OverriddenValueInspectorTest method testRuleCall_01.

@Test
public void testRuleCall_01() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
    _builder.newLine();
    _builder.append("generate metamodel \'foo.sample\'");
    _builder.newLine();
    _builder.append("First returns Object: (Third|Second) cardinality=(\'+\'|\'*\')?;");
    _builder.newLine();
    _builder.append("Second returns Object: \'(\' First \')\';");
    _builder.newLine();
    _builder.append("Third returns Object: name=ID;");
    _builder.newLine();
    String grammarAsString = _builder.toString();
    final Grammar grammar = this.getGrammar(grammarAsString);
    AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "First");
    final ParserRule rule = ((ParserRule) _findRuleForName);
    this.validateRule(rule);
    Assert.assertEquals(this.warnings.toString(), 2, this.warnings.size());
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule) Test(org.junit.Test) AbstractXtextRuleInspectorTest(org.eclipse.xtext.xtext.AbstractXtextRuleInspectorTest)

Example 38 with AbstractRule

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

the class OverriddenValueInspectorTest method testFragment_03.

@Test
public void testFragment_03() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
    _builder.newLine();
    _builder.append("generate metamodel \'foo.sample\'");
    _builder.newLine();
    _builder.append("First : Named;");
    _builder.newLine();
    _builder.append("fragment Named: name=ID Named;");
    _builder.newLine();
    String grammarAsString = _builder.toString();
    final Grammar grammar = this.getGrammar(grammarAsString);
    AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "First");
    final ParserRule rule = ((ParserRule) _findRuleForName);
    this.validateRule(rule);
    final Function1<Triple<String, EObject, EStructuralFeature>, String> _function = (Triple<String, EObject, EStructuralFeature> it) -> {
        return it.getFirst();
    };
    Assert.assertEquals(ListExtensions.<Triple<String, EObject, EStructuralFeature>, String>map(this.warnings, _function).toString(), 0, this.warnings.size());
    AbstractRule _findRuleForName_1 = GrammarUtil.findRuleForName(grammar, "Named");
    final ParserRule fragment = ((ParserRule) _findRuleForName_1);
    this.validateRule(fragment);
    final Function1<Triple<String, EObject, EStructuralFeature>, String> _function_1 = (Triple<String, EObject, EStructuralFeature> it) -> {
        return it.getFirst();
    };
    Assert.assertEquals(ListExtensions.<Triple<String, EObject, EStructuralFeature>, String>map(this.warnings, _function_1).toString(), 2, this.warnings.size());
}
Also used : Triple(org.eclipse.xtext.util.Triple) ParserRule(org.eclipse.xtext.ParserRule) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule) Test(org.junit.Test) AbstractXtextRuleInspectorTest(org.eclipse.xtext.xtext.AbstractXtextRuleInspectorTest)

Example 39 with AbstractRule

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

the class OverriddenValueInspectorTest method testBug306281_09.

@Test
public void testBug306281_09() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
    _builder.newLine();
    _builder.append("generate metamodel \'foo.sample\'");
    _builder.newLine();
    _builder.append("Model : name=ID (({Binary.left=current} operator = [Model] | {Binary.left=current} operator = [Model])?\tname=ID);");
    String grammarAsString = _builder.toString();
    final Grammar grammar = this.getGrammar(grammarAsString);
    AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "Model");
    final ParserRule rule = ((ParserRule) _findRuleForName);
    this.validateRule(rule);
    Assert.assertEquals(this.warnings.toString(), 2, this.warnings.size());
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule) Test(org.junit.Test) AbstractXtextRuleInspectorTest(org.eclipse.xtext.xtext.AbstractXtextRuleInspectorTest)

Example 40 with AbstractRule

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

the class OverriddenValueInspectorTest method testNoMarkerForCalledRules_01.

@Test
public void testNoMarkerForCalledRules_01() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
    _builder.newLine();
    _builder.append("generate metamodel \'foo.sample\'");
    _builder.newLine();
    _builder.append("First returns Object: Second;");
    _builder.newLine();
    _builder.append("Second returns Object: name=ID name=ID;");
    _builder.newLine();
    String grammarAsString = _builder.toString();
    final Grammar grammar = this.getGrammar(grammarAsString);
    AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "First");
    ParserRule rule = ((ParserRule) _findRuleForName);
    this.validateRule(rule);
    Assert.assertEquals(this.warnings.toString(), 0, this.warnings.size());
    AbstractRule _findRuleForName_1 = GrammarUtil.findRuleForName(grammar, "Second");
    rule = ((ParserRule) _findRuleForName_1);
    this.validateRule(rule);
    Assert.assertEquals(this.warnings.toString(), 2, this.warnings.size());
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule) Test(org.junit.Test) AbstractXtextRuleInspectorTest(org.eclipse.xtext.xtext.AbstractXtextRuleInspectorTest)

Aggregations

AbstractRule (org.eclipse.xtext.AbstractRule)222 Test (org.junit.Test)128 Grammar (org.eclipse.xtext.Grammar)106 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)96 ParserRule (org.eclipse.xtext.ParserRule)94 EObject (org.eclipse.emf.ecore.EObject)59 AbstractXtextRuleInspectorTest (org.eclipse.xtext.xtext.AbstractXtextRuleInspectorTest)49 RuleCall (org.eclipse.xtext.RuleCall)36 AbstractElement (org.eclipse.xtext.AbstractElement)34 TerminalRule (org.eclipse.xtext.TerminalRule)20 XtextResource (org.eclipse.xtext.resource.XtextResource)17 EClassifier (org.eclipse.emf.ecore.EClassifier)14 EnumRule (org.eclipse.xtext.EnumRule)14 ArrayList (java.util.ArrayList)12 Assignment (org.eclipse.xtext.Assignment)12 Group (org.eclipse.xtext.Group)12 InternalEObject (org.eclipse.emf.ecore.InternalEObject)11 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)11 EClass (org.eclipse.emf.ecore.EClass)10 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)10