use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class PartialParserTest method performTest.
public void performTest(String toBeDeleted) throws Exception {
String grammarAsText = "grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" + "generate test 'myEcoreModel'\n" + "Root: value=Test;\n" + "Test: (" + toBeDeleted.trim() + " 'foo')*;";
XtextResource resource = getResourceFromString(grammarAsText);
Grammar g = (Grammar) resource.getContents().get(0);
ParserRule rule = (ParserRule) g.getRules().get(1);
assertEquals("*", rule.getAlternatives().getCardinality());
resource.update(grammarAsText.indexOf(toBeDeleted), toBeDeleted.length(), "");
// make sure we did a partial parse pass
assertSame(rule, ((Grammar) resource.getContents().get(0)).getRules().get(1));
assertEquals("*", rule.getAlternatives().getCardinality());
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class RuleWithoutInstantiationInspectorTest method testFragment_02.
@Test
public void testFragment_02() throws Exception {
String grammarAsString = "grammar org.foo with org.eclipse.xtext.common.Terminals\n" + "generate metamodel 'foo.sample'\n" + "Model: name=ID X;\n" + "fragment X*: 'x';";
Grammar grammar = getGrammar(grammarAsString);
ParserRule rule = (ParserRule) GrammarUtil.findRuleForName(grammar, "X");
validateRule(rule);
assertTrue(warnings.toString(), warnings.isEmpty());
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class RuleWithoutInstantiationInspectorTest method testFragment_01.
@Test
public void testFragment_01() throws Exception {
String grammarAsString = "grammar org.foo with org.eclipse.xtext.common.Terminals\n" + "generate metamodel 'foo.sample'\n" + "Model: name=ID X;\n" + "fragment X : 'x';";
Grammar grammar = getGrammar(grammarAsString);
ParserRule rule = (ParserRule) GrammarUtil.findRuleForName(grammar, "X");
validateRule(rule);
assertTrue(warnings.toString(), warnings.isEmpty());
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class RuleWithoutInstantiationInspectorTest method testAssignment_01.
@Test
public void testAssignment_01() throws Exception {
String grammarAsString = "grammar org.foo with org.eclipse.xtext.common.Terminals\n" + "generate metamodel 'foo.sample'\n" + "Model: x=X;\n" + "X : x='x';";
Grammar grammar = getGrammar(grammarAsString);
ParserRule rule = (ParserRule) GrammarUtil.findRuleForName(grammar, "X");
validateRule(rule);
assertTrue(warnings.toString(), warnings.isEmpty());
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class RuleWithoutInstantiationInspectorTest method testIgnoreFirstRule_01.
@Test
public void testIgnoreFirstRule_01() throws Exception {
String grammarAsString = "grammar org.foo with org.eclipse.xtext.common.Terminals\n" + "generate metamodel 'foo.sample'\n" + "X : (x+='x')*;";
Grammar grammar = getGrammar(grammarAsString);
ParserRule rule = (ParserRule) GrammarUtil.findRuleForName(grammar, "X");
validateRule(rule);
assertTrue(warnings.toString(), warnings.isEmpty());
}
Aggregations