use of org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState in project xtext-core by eclipse.
the class AbstractSyntacticSequencer method navigateToAbsorber.
protected ISynAbsorberState navigateToAbsorber(ISynFollowerOwner fromState, INode fromNode, INode toNode, RuleCallStack stack) {
if (fromState instanceof ISynAbsorberState)
return (ISynAbsorberState) fromState;
if (fromState instanceof ISynNavigable) {
ISynNavigable fromEmitter = (ISynNavigable) fromState;
// RCStack back = stack.clone();
if (fromEmitter.hasEmitters()) {
List<ISynState> path = fromEmitter.getShortestStackpruningPathToAbsorber(stack);
accept(fromNode, path, stack);
}
return fromEmitter.getTarget();
}
throw new IllegalStateException();
}
use of org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState in project xtext-core by eclipse.
the class SyntacticSequencerPDAProviderNavigatorTest method testAmbiguousMany.
@Test
public void testAmbiguousMany() throws Exception {
ISynAbsorberState start = getParserRule("Rule: a1=ID 'kw1' 'kw2'+ a2=ID;");
ISynTransition trans = findTransition(start, "a1=ID", "a2=ID");
assertFalse(trans.involvesUnassignedTokenRuleCalls());
assertTrue(trans.isSyntacticallyAmbiguous());
// assertEquals(2, trans.getDistanceWithStackToAbsorber(newStack()));
assertEquals("['kw1', 'kw2'+]", trans.getShortestPathToAbsorber(newStack()).toString());
}
use of org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState in project xtext-core by eclipse.
the class SyntacticSequencerPDAProviderNavigatorTest method testAmbiguousManyOptional.
@Test
public void testAmbiguousManyOptional() throws Exception {
ISynAbsorberState start = getParserRule("Rule: a1=ID 'kw1' 'kw2'* a2=ID;");
ISynTransition trans = findTransition(start, "a1=ID", "a2=ID");
assertFalse(trans.involvesUnassignedTokenRuleCalls());
assertTrue(trans.isSyntacticallyAmbiguous());
// assertEquals(1, trans.getDistanceWithStackToAbsorber(newStack()));
assertEquals("['kw1']", trans.getShortestPathToAbsorber(newStack()).toString());
}
use of org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState in project xtext-core by eclipse.
the class SyntacticSequencerPDAProviderTest method getParserRule.
// public void drawGrammar(String path, Grammar grammar) {
// try {
// IContextPDAProvider contexts = get(IContextPDAProvider.class);
// IContextTypePDAProvider types = get(IContextTypePDAProvider.class);
// SyntacticSequencerPDA2ExtendedDot seq2dot = get(SyntacticSequencerPDA2ExtendedDot.class);
// for (EObject ctx : contexts.getAllContexts(grammar))
// for (EClass type : types.getTypesForContext(grammar, ctx))
// seq2dot.draw(new Pair<EObject, EClass>(ctx, type),
// path + "-" + new Context2NameFunction().toFunction(grammar).apply(ctx) + "_"
// + (type == null ? "null" : type.getName()) + "-PDA.pdf",
// "-T pdf");
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
protected String getParserRule(String body) throws Exception {
Grammar grammar = (Grammar) getModel(HEADER + body);
// StackTraceElement ele = Thread.currentThread().getStackTrace()[2];
// drawGrammar("pdf/" + ele.getMethodName(), grammar);
ISyntacticSequencerPDAProvider pdaProvider = get(ISyntacticSequencerPDAProvider.class);
SerializationContextMap<ISynAbsorberState> pdas = pdaProvider.getSyntacticSequencerPDAs(grammar);
List<String> result = Lists.newArrayList();
for (Entry<ISynAbsorberState> e : pdas.sortedCopy().values()) {
result.add(Joiner.on(", ").join(e.getContexts()) + ":");
result.addAll(pda2lines2(e.getValue()));
}
return Joiner.on("\n").join(result);
}
Aggregations