Search in sources :

Example 16 with RuleCall

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);
}
Also used : ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) EObject(org.eclipse.emf.ecore.EObject) Grammar(org.eclipse.xtext.Grammar) RuleCall(org.eclipse.xtext.RuleCall) Test(org.junit.Test)

Example 17 with 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());
}
Also used : EObject(org.eclipse.emf.ecore.EObject) RuleCall(org.eclipse.xtext.RuleCall)

Example 18 with RuleCall

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());
}
Also used : RuleCall(org.eclipse.xtext.RuleCall) Test(org.junit.Test)

Example 19 with RuleCall

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());
}
Also used : Assignment(org.eclipse.xtext.Assignment) RuleCall(org.eclipse.xtext.RuleCall) Test(org.junit.Test)

Example 20 with RuleCall

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();
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Group(org.eclipse.xtext.Group) UnorderedGroup(org.eclipse.xtext.UnorderedGroup) Grammar(org.eclipse.xtext.Grammar) RuleCall(org.eclipse.xtext.RuleCall) Test(org.junit.Test)

Aggregations

RuleCall (org.eclipse.xtext.RuleCall)95 ParserRule (org.eclipse.xtext.ParserRule)41 AbstractRule (org.eclipse.xtext.AbstractRule)36 EObject (org.eclipse.emf.ecore.EObject)33 Test (org.junit.Test)33 Grammar (org.eclipse.xtext.Grammar)28 AbstractElement (org.eclipse.xtext.AbstractElement)26 Assignment (org.eclipse.xtext.Assignment)22 TerminalRule (org.eclipse.xtext.TerminalRule)19 Action (org.eclipse.xtext.Action)17 CrossReference (org.eclipse.xtext.CrossReference)13 Group (org.eclipse.xtext.Group)13 TypeRef (org.eclipse.xtext.TypeRef)13 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)13 ArrayList (java.util.ArrayList)11 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)11 InternalEObject (org.eclipse.emf.ecore.InternalEObject)10 Keyword (org.eclipse.xtext.Keyword)10 EClass (org.eclipse.emf.ecore.EClass)9 EnumRule (org.eclipse.xtext.EnumRule)9