Search in sources :

Example 36 with Grammar

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

the class OverriddenValueInspectorTest method testUnassignedRule_03.

@Test
public void testUnassignedRule_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 : Second (name=ID)?;");
    _builder.newLine();
    _builder.append("Second: id=INT (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 37 with Grammar

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

the class OverriddenValueInspectorTest method testAlternative_03.

@Test
public void testAlternative_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 : (Second | multiName+=ID | id=INT) multiName+=ID id=INT;");
    _builder.newLine();
    _builder.append("Second: \'keyword\' name=ID id=INT;");
    _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(), 3, 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 Grammar

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

the class OverriddenValueInspectorTest method testBug306281_05.

@Test
public void testBug306281_05() 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 = \'-\' | {Binary.left=current} operator = \'+\') name=ID);");
    _builder.newLine();
    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.assertTrue(this.warnings.toString(), this.warnings.isEmpty());
}
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 39 with Grammar

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

the class OverriddenValueInspectorTest method testBug306281_04.

@Test
public void testBug306281_04() 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 = \'-\' | {Binary.left=current} operator = \'+\')? name=ID);");
    _builder.newLine();
    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 Grammar

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

the class OverriddenValueInspectorTest method testUnassignedRule_04.

@Test
public void testUnassignedRule_04() 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 : Second (name=ID)? id=INT;");
    _builder.newLine();
    _builder.append("Second: id=INT (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(), 4, 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

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