Search in sources :

Example 6 with ISynTransition

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());
}
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)

Example 7 with ISynTransition

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

Example 8 with ISynTransition

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());
}
Also used : GrammarElementTitleSwitch(org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch) ISynTransition(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynTransition)

Example 9 with ISynTransition

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

Example 10 with ISynTransition

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

Aggregations

ISynTransition (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynTransition)11 ISynAbsorberState (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState)10 Test (org.junit.Test)8 GrammarElementTitleSwitch (org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch)1 RuleCallStack (org.eclipse.xtext.serializer.sequencer.RuleCallStack)1