use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class NodeModelUtilsTest method testFindActualSemanticObjectFor_05.
@Test
public void testFindActualSemanticObjectFor_05() throws Exception {
String grammarString = "grammar foo.Bar with org.eclipse.xtext.common.Terminals generate foo 'bar' Model:name=ID;";
Grammar grammar = (Grammar) getModel(grammarString);
ILeafNode leafNode = NodeModelUtils.findLeafNodeAtOffset(NodeModelUtils.getNode(grammar), grammarString.indexOf("ID"));
EObject object = NodeModelUtils.findActualSemanticObjectFor(leafNode);
assertTrue(object instanceof RuleCall);
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class AbstractPartialParsingPointerTest method checkParseRegionPointers.
protected void checkParseRegionPointers(PartialParsingPointers parsingPointers, String expectedRegion, String expectedGrammarElementClassName, String expectedEntryRuleName) {
assertEquals(expectedRegion, getReparseRegion(parsingPointers));
EObject grammarElement = parsingPointers.getDefaultReplaceRootNode().getGrammarElement();
String grammarElementName = grammarElement.eClass().getName();
assertEquals(expectedGrammarElementClassName, grammarElementName);
EObject ruleOrRuleCall = parsingPointers.findEntryRuleOrRuleCall(parsingPointers.getDefaultReplaceRootNode());
if (ruleOrRuleCall instanceof RuleCall) {
ruleOrRuleCall = ((RuleCall) ruleOrRuleCall).getRule();
}
assertEquals(expectedEntryRuleName, ((AbstractRule) ruleOrRuleCall).getName());
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class GrammarParserTest method testRuleCall.
@Test
public void testRuleCall() throws Exception {
RuleCall ruleCall = (RuleCall) getModel("STRING");
assertNotNull(ruleCall);
assertEquals("STRING", ruleCall.getRule().getName());
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class GrammarParserTest method testAssignment.
@Test
public void testAssignment() throws Exception {
Assignment assignment = (Assignment) getModel("name=ID");
assertNotNull(assignment);
assertEquals("ID", ((RuleCall) assignment.getTerminal()).getRule().getName());
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class XtextValidationTest method testRuleCallAllowed_10.
@Test
public void testRuleCallAllowed_10() throws Exception {
String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Model: name=ID Fragment;\n" + "fragment Fragment: value=STRING;";
Grammar grammar = (Grammar) getModel(grammarAsText);
ParserRule rule = (ParserRule) grammar.getRules().get(0);
RuleCall ruleCall = (RuleCall) ((Group) rule.getAlternatives()).getElements().get(1);
XtextValidator validator = get(XtextValidator.class);
ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
validator.setMessageAcceptor(messageAcceptor);
validator.checkUnassignedRuleCallAllowed(ruleCall);
messageAcceptor.validate();
}
Aggregations