use of org.eclipse.xtext.Grammar 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.Grammar 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.Grammar 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);
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class SyntacticSequencerPDAProviderNavigatorTest method getParserRule.
protected ISynAbsorberState getParserRule(String body, String name, String typeName) throws Exception {
Grammar grammar = (Grammar) getModel(HEADER + body);
// SyntacticSequencerPDA2SimpleDot.drawGrammar("pdf/" + getName(),
// grammar);
// SyntacticSequencerPDA2ExtendedDot.drawGrammar(createSequenceParserPDAProvider(),
// "pdf/" + getName(), grammar);
ISyntacticSequencerPDAProvider pdaProvider = get(ISyntacticSequencerPDAProvider.class);
SerializationContextMap<ISynAbsorberState> pdas = pdaProvider.getSyntacticSequencerPDAs(grammar);
for (SerializationContextMap.Entry<ISynAbsorberState> e : pdas.sortedCopy().values()) {
for (ISerializationContext context : e.getContexts()) {
if (context.getAssignedAction() != null)
continue;
ISynAbsorberState pda = e.getValue();
ParserRule rule = context.getParserRule();
EClass type = context.getType();
boolean nameMatches = rule == null || name == null || rule.getName().equals(name);
boolean typeMatches = type == null || typeName == null || typeName.equals(type.getName());
if (nameMatches && typeMatches)
return pda;
}
}
throw new IllegalStateException();
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class NodeModelUtilsTest method testFindActualSemanticObjectFor_06.
@Test
public void testFindActualSemanticObjectFor_06() 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.lastIndexOf(" "));
EObject object = NodeModelUtils.findActualSemanticObjectFor(leafNode);
assertTrue(object instanceof Assignment);
}
Aggregations