Search in sources :

Example 26 with Grammar

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

the class GrammarFlatteningTest method test_12.

@Test
public void test_12() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar com.foo.bar with org.eclipse.xtext.common.Terminals");
    _builder.newLine();
    _builder.append("generate myPack \'http://myURI\'");
    _builder.newLine();
    _builder.append("Rule: =>(name+=ID*);");
    _builder.newLine();
    Grammar flattened = this.getModel(_builder.toString(), true);
    String serialized = this.getSerializer().serialize(flattened);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("grammar com.foo.bar hidden(RULE_WS, RULE_ML_COMMENT, RULE_SL_COMMENT)");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("ruleRule:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("=> (name+=RULE_ID*);");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal RULE_ID:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("\"^\"? (\"a\"..\"z\" | \"A\"..\"Z\" | \"_\") (\"a\"..\"z\" | \"A\"..\"Z\" | \"_\" | \"0\"..\"9\")*;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal RULE_INT:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("\"0\"..\"9\"+;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal RULE_STRING:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("\"\\\"\" (\"\\\\\" . | !(\"\\\\\" | \"\\\"\"))* \"\\\"\" | \"\\\'\" (\"\\\\\" . | !(\"\\\\\" | \"\\\'\"))* \"\\\'\";");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal RULE_ML_COMMENT:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("\"/*\"->\"*/\";");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal RULE_SL_COMMENT:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("\"//\" !(\"\\n\" | \"\\r\")* (\"\\r\"? \"\\n\")?;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal RULE_WS:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("\" \" | \"\\t\" | \"\\r\" | \"\\n\"+;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal RULE_ANY_OTHER:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append(".;");
    Assert.assertEquals(_builder_1.toString(), serialized);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 27 with Grammar

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

the class GrammarFlatteningTest method test_02.

@Test
public void test_02() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar com.foo.bar with org.eclipse.xtext.common.Terminals");
    _builder.newLine();
    _builder.append("generate myPack \'http://myURI\'");
    _builder.newLine();
    _builder.append("Rule: name=ID;");
    _builder.newLine();
    _builder.append("terminal ID: super;");
    _builder.newLine();
    Grammar flattened = this.getModel(_builder.toString());
    String serialized = this.getSerializer().serialize(flattened);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("grammar com.foo.bar hidden(RULE_WS, RULE_ML_COMMENT, RULE_SL_COMMENT)");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("ruleRule:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("name=RULE_ID;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal RULE_ID:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("SUPER_ID;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal fragment SUPER_ID:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("\"^\"? (\"a\"..\"z\" | \"A\"..\"Z\" | \"_\") (\"a\"..\"z\" | \"A\"..\"Z\" | \"_\" | \"0\"..\"9\")*;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal RULE_INT:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("\"0\"..\"9\"+;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal RULE_STRING:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("\"\\\"\" (\"\\\\\" . | !(\"\\\\\" | \"\\\"\"))* \"\\\"\" | \"\\\'\" (\"\\\\\" . | !(\"\\\\\" | \"\\\'\"))* \"\\\'\";");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal RULE_ML_COMMENT:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("\"/*\"->\"*/\";");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal RULE_SL_COMMENT:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("\"//\" !(\"\\n\" | \"\\r\")* (\"\\r\"? \"\\n\")?;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal RULE_WS:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("\" \" | \"\\t\" | \"\\r\" | \"\\n\"+;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal RULE_ANY_OTHER:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append(".;");
    Assert.assertEquals(_builder_1.toString(), serialized);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 28 with Grammar

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

the class GrammarFlatteningTest method test_09.

@Test
public void test_09() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar com.foo.bar with org.eclipse.xtext.common.Terminals");
    _builder.newLine();
    _builder.append("generate myPack \'http://myURI\'");
    _builder.newLine();
    _builder.append("Rule<A>: name=ID ->(<A> =>child=Rule<!A> | <!A> =>\'keyword\')?;");
    _builder.newLine();
    Grammar flattened = this.getModel(_builder.toString(), true);
    String serialized = this.getSerializer().serialize(flattened);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("grammar com.foo.bar hidden(RULE_WS, RULE_ML_COMMENT, RULE_SL_COMMENT)");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("ruleRule:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("name=RULE_ID => (\"keyword\")?;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal RULE_ID:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("\"^\"? (\"a\"..\"z\" | \"A\"..\"Z\" | \"_\") (\"a\"..\"z\" | \"A\"..\"Z\" | \"_\" | \"0\"..\"9\")*;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal RULE_INT:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("\"0\"..\"9\"+;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal RULE_STRING:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("\"\\\"\" (\"\\\\\" . | !(\"\\\\\" | \"\\\"\"))* \"\\\"\" | \"\\\'\" (\"\\\\\" . | !(\"\\\\\" | \"\\\'\"))* \"\\\'\";");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal RULE_ML_COMMENT:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("\"/*\"->\"*/\";");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal RULE_SL_COMMENT:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("\"//\" !(\"\\n\" | \"\\r\")* (\"\\r\"? \"\\n\")?;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal RULE_WS:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("\" \" | \"\\t\" | \"\\r\" | \"\\n\"+;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("terminal RULE_ANY_OTHER:");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append(".;");
    Assert.assertEquals(_builder_1.toString(), serialized);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 29 with Grammar

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

the class OverriddenValueInspectorTest method testUnorderedGroup_06.

@Test
public void testUnorderedGroup_06() 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 : a = ID b = STRING & a = 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 30 with Grammar

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

the class OverriddenValueInspectorTest method testBug306281_08.

@Test
public void testBug306281_08() 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]) right=ID)+ 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)

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