Search in sources :

Example 16 with ISynAbsorberState

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

Example 17 with ISynAbsorberState

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

Example 18 with ISynAbsorberState

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

Example 19 with ISynAbsorberState

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

Aggregations

ISynAbsorberState (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState)19 ISynTransition (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynTransition)10 Test (org.junit.Test)8 ISerializationContext (org.eclipse.xtext.serializer.ISerializationContext)3 EClass (org.eclipse.emf.ecore.EClass)2 Grammar (org.eclipse.xtext.Grammar)2 ISyntacticSequencerPDAProvider (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider)2 ISynNavigable (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynNavigable)2 ISynState (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynState)2 ParserRule (org.eclipse.xtext.ParserRule)1 INode (org.eclipse.xtext.nodemodel.INode)1 SynAbsorberNfaAdapter (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.SynAbsorberNfaAdapter)1 SerializationContextMap (org.eclipse.xtext.serializer.analysis.SerializationContextMap)1 RuleCallStack (org.eclipse.xtext.serializer.sequencer.RuleCallStack)1 Nfa (org.eclipse.xtext.util.formallang.Nfa)1