use of org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynTransition in project xtext-core by eclipse.
the class SyntacticSequencerPDAProviderNavigatorTest method testAmbiguousRecursion.
@Test
public void testAmbiguousRecursion() throws Exception {
StringBuilder grammar = new StringBuilder();
grammar.append("Addition returns Expr: Prim ({Add.left=current} '+' right=Prim)*;\n");
grammar.append("Prim returns Expr: {Val} name=ID | '(' Addition ')';\n");
ISynAbsorberState start = getParserRule(grammar.toString(), "Prim", "Val");
ISynTransition trans1 = findTransition(start, "start", "name=ID");
assertFalse(trans1.involvesUnassignedTokenRuleCalls());
assertTrue(trans1.isSyntacticallyAmbiguous());
// assertEquals(1, trans1.getDistanceWithStackToAbsorber(newStack()));
assertEquals("[{Val}]", trans1.getShortestPathToAbsorber(newStack()).toString());
RuleCallStack stack2 = newStack();
ISynTransition trans2 = findTransition(start, "name=ID", "stop");
assertFalse(trans2.involvesUnassignedTokenRuleCalls());
assertFalse(trans2.isSyntacticallyAmbiguous());
// assertEquals(0, trans2.getDistanceWithStackToAbsorber(stack2));
assertEquals("[]", trans2.getShortestPathToAbsorber(stack2).toString());
// RuleCallStack stack3 = newStack(trans1, ">>Addition", ">>Prim");
// ISynTransition trans3 = findTransition(start, "name=ID", "stop");
// assertFalse(trans3.involvesUnassignedTokenRuleCalls());
// assertFalse(trans3.isSyntacticallyAmbiguous());
// // assertEquals(3, trans3.getDistanceWithStackToAbsorber(stack3));
// assertEquals("[<<Prim, <<Addition, ')']", trans3.getShortestStackpruningPathToAbsorber(stack3).toString());
}
use of org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynTransition in project xtext-core by eclipse.
the class SyntacticSequencerPDAProviderTest method pda2lines2.
private List<String> pda2lines2(ISynAbsorberState start) {
Set<ISynAbsorberState> states = Sets.newHashSet(start);
collectAbsorberStates(start, Sets.<ISynState>newHashSet(), states);
List<String> pdalines = Lists.newArrayList();
for (ISynAbsorberState state : states) for (ISynTransition child : state.getOutTransitions()) pdalines.add(" " + pathToStr2(child));
Collections.sort(pdalines);
return pdalines;
}
use of org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynTransition in project xtext-core by eclipse.
the class SyntacticSequencerDiagnosticProvider method createInvalidFollowingAbsorberDiagnostic.
@Override
public ISerializationDiagnostic createInvalidFollowingAbsorberDiagnostic(ISerializationContext context, EObject semanticObject, ISynAbsorberState from, AbstractElement to) {
GrammarElementTitleSwitch fmt = new GrammarElementTitleSwitch().showAssignments().showQualified();
String fromName = from.toString(fmt);
String toName = to == null ? "stop" : fmt.doSwitch(to);
List<String> targets = Lists.newArrayList();
for (ISynTransition trans : from.getOutTransitions()) targets.add(trans.getTarget().toString(fmt));
StringBuilder msg = new StringBuilder();
msg.append("State '" + toName + "' may not follow '" + fromName + "'.\n");
msg.append("Valid followers are: " + Joiner.on(", ").join(targets));
return new SerializationDiagnostic(INVALID_FOLLOWING_ABSORBER, semanticObject, context, grammarAccess.getGrammar(), msg.toString());
}
use of org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynTransition in project xtext-core by eclipse.
the class AbstractSyntacticSequencer method findTransition.
protected ISynTransition findTransition(ISerializationContext context, EObject semanticObject, ISynFollowerOwner fromState, INode fromNode, AbstractElement toEle, INode toNode, RuleCallStack stack) {
if (fromState == null)
return null;
if (fromState instanceof ISynAbsorberState) {
ISynAbsorberState fromAbsorber = (ISynAbsorberState) fromState;
ISynTransition transition = fromAbsorber.getOutTransitionsByElement().get(toEle);
if (transition == null) {
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidFollowingAbsorberDiagnostic(context, semanticObject, fromAbsorber, toEle));
return null;
}
return transition;
}
throw new IllegalStateException();
}
use of org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynTransition 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());
}
Aggregations