use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class XtextLinkerTest method testImplicitNamedParameterLinking_01.
@Test
public void testImplicitNamedParameterLinking_01() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar test.Lang with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.append("generate test \'http://test\'");
_builder.newLine();
_builder.append("Root<MyParam>: rule=Rule<MyParam>;");
_builder.newLine();
_builder.append("Rule<MyParam>: name=ID child=Root<MyParam>?;");
_builder.newLine();
final String grammarAsString = _builder.toString();
EObject _model = this.getModel(grammarAsString);
final Grammar grammar = ((Grammar) _model);
AbstractRule _head = IterableExtensions.<AbstractRule>head(grammar.getRules());
final ParserRule rootRule = ((ParserRule) _head);
AbstractRule _last = IterableExtensions.<AbstractRule>last(grammar.getRules());
final ParserRule lastRule = ((ParserRule) _last);
AbstractElement _alternatives = lastRule.getAlternatives();
AbstractElement _last_1 = IterableExtensions.<AbstractElement>last(((Group) _alternatives).getElements());
final Assignment lastAssignment = ((Assignment) _last_1);
AbstractElement _terminal = lastAssignment.getTerminal();
final RuleCall ruleCall = ((RuleCall) _terminal);
final NamedArgument argument = IterableExtensions.<NamedArgument>head(ruleCall.getArguments());
Assert.assertEquals(IterableExtensions.<Parameter>head(rootRule.getParameters()), argument.getParameter());
Condition _value = argument.getValue();
Assert.assertEquals(IterableExtensions.<Parameter>head(lastRule.getParameters()), ((ParameterReference) _value).getParameter());
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class XtextValidationTest method testCheckCrossReferenceTerminal_01.
@Test
public void testCheckCrossReferenceTerminal_01() throws Exception {
XtextValidator validator = get(XtextValidator.class);
CrossReference reference = XtextFactory.eINSTANCE.createCrossReference();
RuleCall call = XtextFactory.eINSTANCE.createRuleCall();
reference.setTerminal(call);
ParserRule rule = XtextFactory.eINSTANCE.createParserRule();
call.setRule(rule);
TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef();
rule.setType(typeRef);
typeRef.setClassifier(EcorePackage.Literals.ESTRING);
ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
validator.setMessageAcceptor(messageAcceptor);
validator.checkCrossReferenceTerminal(reference);
messageAcceptor.validate();
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class XtextValidationTest method testCheckRuleCallInUnorderedGroup_04.
@Test
public void testCheckRuleCallInUnorderedGroup_04() throws Exception {
XtextValidator validator = get(XtextValidator.class);
UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup();
RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall();
TerminalRule terminalRule = XtextFactory.eINSTANCE.createTerminalRule();
ruleCall.setRule(terminalRule);
unorderedGroup.getElements().add(ruleCall);
ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
validator.setMessageAcceptor(messageAcceptor);
validator.checkRuleCallInUnorderedGroup(ruleCall);
messageAcceptor.validate();
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class XtextValidationTest method testRuleCallAllowed_01.
@Test
public void testRuleCallAllowed_01() throws Exception {
String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Model: name=ID;\n" + "terminal MyTerminal: Fragment;\n" + "terminal fragment Fragment: 'a'..'z'+;";
Grammar grammar = (Grammar) getModel(grammarAsText);
TerminalRule rule = (TerminalRule) grammar.getRules().get(1);
RuleCall ruleCall = (RuleCall) rule.getAlternatives();
XtextValidator validator = get(XtextValidator.class);
ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
validator.setMessageAcceptor(messageAcceptor);
validator.checkUnassignedRuleCallAllowed(ruleCall);
validator.checkTerminalFragmentCalledFromTerminalRule(ruleCall);
messageAcceptor.validate();
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class XtextValidationTest method testRuleCallAllowed_04.
@Test
public void testRuleCallAllowed_04() throws Exception {
String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Model: name=Terminal;\n" + "terminal Terminal: 'a'..'z'+;";
Grammar grammar = (Grammar) getModel(grammarAsText);
ParserRule rule = (ParserRule) grammar.getRules().get(0);
RuleCall ruleCall = (RuleCall) ((Assignment) rule.getAlternatives()).getTerminal();
XtextValidator validator = get(XtextValidator.class);
ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
validator.setMessageAcceptor(messageAcceptor);
validator.checkUnassignedRuleCallAllowed(ruleCall);
validator.checkTerminalFragmentCalledFromTerminalRule(ruleCall);
messageAcceptor.validate();
}
Aggregations