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);
}
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);
}
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);
}
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());
}
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());
}
Aggregations