Search in sources :

Example 1 with RuleCallStack

use of org.eclipse.xtext.serializer.sequencer.RuleCallStack in project xtext-core by eclipse.

the class SyntacticSequencerPDAProviderNavigatorTest method newStack.

protected RuleCallStack newStack(ISynTransition start, String... ruleCalls) {
    RuleCallStack result = new RuleCallStack();
    for (String name : ruleCalls) {
        ISynEmitterState emitter = findEmitter(start, name, Sets.<ISynFollowerOwner>newHashSet());
        result.push((RuleCall) emitter.getGrammarElement());
    }
    return result;
}
Also used : RuleCallStack(org.eclipse.xtext.serializer.sequencer.RuleCallStack) ISynEmitterState(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynEmitterState)

Example 2 with RuleCallStack

use of org.eclipse.xtext.serializer.sequencer.RuleCallStack 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());
}
Also used : ISynAbsorberState(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState) RuleCallStack(org.eclipse.xtext.serializer.sequencer.RuleCallStack) ISynTransition(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynTransition) Test(org.junit.Test)

Aggregations

RuleCallStack (org.eclipse.xtext.serializer.sequencer.RuleCallStack)2 ISynAbsorberState (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState)1 ISynEmitterState (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynEmitterState)1 ISynTransition (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynTransition)1 Test (org.junit.Test)1