use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class GrammarFlatteningTest method test_07.
@Test
public void test_07() 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>)?;");
_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);
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class GrammarFlatteningTest method test_06.
@Test
public void test_06() 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>)?;");
_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("norm1_Rule:");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("name=RULE_ID child=ruleRule?;");
_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);
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class GrammarFlatteningTest method test_01.
@Test
public void test_01() 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());
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);
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class GrammarFlatteningTest method test_10.
@Test
public void test_10() 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("ParserRuleParameters: {ParserRuleParameters} ");
_builder.newLine();
_builder.append(" ");
_builder.append("( \'#1\' scenario=Scenario1<true>");
_builder.newLine();
_builder.append(" ");
_builder.append("|\t\'#2\' scenario=Scenario1<Param=false>");
_builder.newLine();
_builder.append(" ");
_builder.append("| \'#3\' scenario=Scenario2<true>");
_builder.newLine();
_builder.append(" ");
_builder.append("| \'#4\' scenario=Scenario2<false>");
_builder.newLine();
_builder.append(" ");
_builder.append("| =>(\'#5\' scenario=Scenario2<true>)");
_builder.newLine();
_builder.append(" ");
_builder.append("| =>(\'#6\' scenario=Scenario2<false>)");
_builder.newLine();
_builder.append(" ");
_builder.append("| \'#7\' scenario=Scenario3<true>");
_builder.newLine();
_builder.append(" ");
_builder.append("| \'#8\' scenario=Scenario3<false>");
_builder.newLine();
_builder.append(" ");
_builder.append("| \'#9\' (scenario=Scenario4<true> | scenario=Scenario2<true> \'keyword\'?)");
_builder.newLine();
_builder.append(" ");
_builder.append("| \'#10\' (scenario=Scenario4<true> | scenario=Scenario2<false> \'keyword\'?)");
_builder.newLine();
_builder.append(" ");
_builder.append("| \'#11\' (scenario=Scenario4<false> | scenario=Scenario2<true> \'keyword\'?)");
_builder.newLine();
_builder.append(" ");
_builder.append("| \'#12\' (scenario=Scenario4<false> | scenario=Scenario2<false> \'keyword\'?)");
_builder.newLine();
_builder.append(" ");
_builder.append(")");
_builder.newLine();
_builder.append(";");
_builder.newLine();
_builder.newLine();
_builder.append("Scenario1<Param> returns Scenario:");
_builder.newLine();
_builder.append("\t");
_builder.append("<Param> first=ID");
_builder.newLine();
_builder.append(" ");
_builder.append("| <!Param> second=ID");
_builder.newLine();
_builder.append(";");
_builder.newLine();
_builder.newLine();
_builder.append("Scenario2<AllowKeyword> returns Scenario:");
_builder.newLine();
_builder.append("\t");
_builder.append("first=IdOrKeyword<AllowKeyword>");
_builder.newLine();
_builder.append(";");
_builder.newLine();
_builder.newLine();
_builder.append("Scenario3<AllowKeyword> returns Scenario:");
_builder.newLine();
_builder.append("\t");
_builder.append("=>first=IdOrKeyword<AllowKeyword>");
_builder.newLine();
_builder.append("\t");
_builder.append("| second=\'keyword\'");
_builder.newLine();
_builder.append(";");
_builder.newLine();
_builder.newLine();
_builder.append("Scenario4<AllowKeyword> returns Scenario:");
_builder.newLine();
_builder.append("\t");
_builder.append("=>second=IdOrKeyword<AllowKeyword> \'keyword\'");
_builder.newLine();
_builder.append(";");
_builder.newLine();
_builder.newLine();
_builder.append("IdOrKeyword<Keyword>:");
_builder.newLine();
_builder.append("\t");
_builder.append("<Keyword> \'keyword\'");
_builder.newLine();
_builder.append("\t");
_builder.append("| ID");
_builder.newLine();
_builder.append(";");
_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("ruleParserRuleParameters:");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("{ParserRuleParameters} (\"#1\" scenario=norm1_Scenario1 | \"#2\" scenario=ruleScenario1 | \"#3\" scenario=norm1_Scenario2 |");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("\"#4\" scenario=ruleScenario2 | => (\"#5\" scenario=norm1_Scenario2) | => (\"#6\" scenario=ruleScenario2) | \"#7\"");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("scenario=norm1_Scenario3 | \"#8\" scenario=ruleScenario3 | \"#9\" (scenario=norm1_Scenario4 | scenario=norm1_Scenario2");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("\"keyword\"?) | \"#10\" (scenario=norm1_Scenario4 | scenario=ruleScenario2 \"keyword\"?) | \"#11\" (scenario=ruleScenario4 |");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("scenario=norm1_Scenario2 \"keyword\"?) | \"#12\" (scenario=ruleScenario4 | scenario=ruleScenario2 \"keyword\"?));");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("ruleScenario1:");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("second=RULE_ID;");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("norm1_Scenario1:");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("first=RULE_ID;");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("ruleScenario2:");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("first=ruleIdOrKeyword;");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("norm1_Scenario2:");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("first=norm1_IdOrKeyword;");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("ruleScenario3:");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("=> first=ruleIdOrKeyword | second=\"keyword\";");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("norm1_Scenario3:");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("=> first=norm1_IdOrKeyword | second=\"keyword\";");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("ruleScenario4:");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("=> second=ruleIdOrKeyword \"keyword\";");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("norm1_Scenario4:");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("=> second=norm1_IdOrKeyword \"keyword\";");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("ruleIdOrKeyword:");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("RULE_ID;");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("norm1_IdOrKeyword:");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("\"keyword\" | 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);
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class GrammarFlatteningTest method test_03.
@Test
public void test_03() 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, B>: <A> name=ID | <!B> name=ID | name=STRING;");
_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 | name=RULE_STRING;");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("norm1_Rule:");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("name=RULE_ID | name=RULE_ID | name=RULE_STRING;");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("norm2_Rule:");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("name=RULE_STRING;");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("norm3_Rule:");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("name=RULE_ID | name=RULE_STRING;");
_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);
}
Aggregations