use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class XtextLinkerTest method testExplicitRuleCallsAreTracked.
@Test
public void testExplicitRuleCallsAreTracked() 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("Rule: name=super::ID name=ID;");
_builder.newLine();
_builder.append("terminal ID: super;");
_builder.newLine();
_builder.append("terminal _super: \'s\';");
_builder.newLine();
final String grammarAsString = _builder.toString();
final XtextResource resource = this.getResourceFromString(grammarAsString);
EObject _get = resource.getContents().get(0);
Grammar grammar = ((Grammar) _get);
final AbstractRule firstRule = IterableExtensions.<AbstractRule>head(grammar.getRules());
final RuleCall firstRuleCall = IteratorExtensions.<RuleCall>head(Iterators.<RuleCall>filter(firstRule.eAllContents(), RuleCall.class));
Assert.assertTrue(firstRuleCall.isExplicitlyCalled());
final RuleCall secondRuleCall = IteratorExtensions.<RuleCall>last(Iterators.<RuleCall>filter(firstRule.eAllContents(), RuleCall.class));
Assert.assertFalse(secondRuleCall.isExplicitlyCalled());
final RuleCall thirdRuleCall = IteratorExtensions.<RuleCall>head(Iterators.<RuleCall>filter(grammar.getRules().get(1).eAllContents(), RuleCall.class));
Assert.assertTrue(thirdRuleCall.isExplicitlyCalled());
resource.update(grammarAsString.indexOf("_super"), 1, " ");
Assert.assertEquals(resource, firstRuleCall.eResource());
Assert.assertEquals(resource, secondRuleCall.eResource());
Assert.assertEquals(resource, thirdRuleCall.eResource());
resource.getContents();
Assert.assertFalse(thirdRuleCall.isExplicitlyCalled());
Assert.assertEquals(IterableExtensions.<AbstractRule>last(grammar.getRules()), thirdRuleCall.getRule());
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class XtextLinkerTest method testNamedParameterLinking.
@Test
public void testNamedParameterLinking() 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<MyArg>: rule=Rule<MyArg>;");
_builder.newLine();
_builder.append("Rule<MyParam>: name=ID child=Root<MyArg=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 XtextLinkerTest method testQualifiedRuleCall_02.
@Test
public void testQualifiedRuleCall_02() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar test with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.append("generate test \'http://test\'");
_builder.newLine();
_builder.append("Rule: name=ID;");
_builder.newLine();
_builder.append("terminal STRING: super;");
_builder.newLine();
final String grammarAsString = _builder.toString();
final XtextResource resource = this.getResourceFromString(grammarAsString);
EObject _get = resource.getContents().get(0);
Grammar grammar = ((Grammar) _get);
AbstractRule _get_1 = grammar.getRules().get(1);
final TerminalRule string = ((TerminalRule) _get_1);
AbstractElement _alternatives = string.getAlternatives();
final RuleCall callToSuper = ((RuleCall) _alternatives);
Assert.assertEquals(GrammarUtil.findRuleForName(IterableExtensions.<Grammar>head(grammar.getUsedGrammars()), "STRING"), callToSuper.getRule());
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class ContextPDAProviderTest method getParserRule.
protected String getParserRule(String body) throws Exception {
Grammar grammar = (Grammar) getModel(HEADER + body);
List<String> result = Lists.newArrayList();
PdaListFormatter<ISerState, RuleCall> formatter = new PdaListFormatter<ISerState, RuleCall>();
formatter.setStateFormatter(new ToStr());
formatter.setStackitemFormatter(new GrammarElementTitleSwitch().showAssignments().hideCardinality());
formatter.sortFollowers();
IContextPDAProvider pdaProvider = get(IContextPDAProvider.class);
SerializationContextMap<Pda<ISerState, RuleCall>> pdas = pdaProvider.getContextPDAs(grammar);
for (Entry<Pda<ISerState, RuleCall>> ctx : pdas.sortedCopy().values()) {
result.add(Joiner.on(", ").join(ctx.getContexts()) + ":");
Pda<ISerState, RuleCall> pda = ctx.getValue();
result.add(" " + formatter.format(pda).replace("\n", "\n "));
// StackTraceElement ele = Thread.currentThread().getStackTrace()[2];
// String name = getClass().getSimpleName() + "_" + ele.getMethodName() + "_" + ctx.getSecond() + ".pdf";
// new PdaToDot<ISerState, RuleCall>().draw(pda, "dot/" + name, "-T pdf");
}
return Joiner.on("\n").join(result);
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class ContextTypePDAProviderTest method getParserRule.
protected String getParserRule(String body) throws Exception {
Grammar grammar = (Grammar) getModel(HEADER + body);
// drawGrammar("pdf/" + getName(), grammar);
List<String> result = Lists.newArrayList();
PdaListFormatter<ISerState, RuleCall> formatter = new PdaListFormatter<ISerState, RuleCall>();
formatter.setStateFormatter(new ToStr());
formatter.setStackitemFormatter(new GrammarElementTitleSwitch().showAssignments().hideCardinality());
formatter.sortFollowers();
IContextTypePDAProvider typePDAProvider = get(IContextTypePDAProvider.class);
SerializationContextMap<Pda<ISerState, RuleCall>> pdas = typePDAProvider.getContextTypePDAs(grammar);
for (Entry<Pda<ISerState, RuleCall>> ctx : pdas.sortedCopy().values()) {
result.add(Joiner.on(", ").join(ctx.getContexts()) + ":");
result.add(" " + formatter.format(ctx.getValue()).replace("\n", "\n "));
}
return Joiner.on("\n").join(result);
}
Aggregations