Search in sources :

Example 1 with SerializerPDAState

use of org.eclipse.xtext.serializer.analysis.SerializerPDA.SerializerPDAState in project xtext-core by eclipse.

the class ContextPDAProvider method merge.

protected void merge(ISerState orig, SerializerPDAState copy, Map<ISerState, SerializerPDAState> oldToNew, IdentityHashMap<ISerState, Boolean> visited) {
    for (ISerState fol : orig.getFollowers()) {
        SerializerPDAState folCopy = oldToNew.get(fol);
        if (folCopy == null) {
            folCopy = new SerializerPDAState(fol.getGrammarElement(), fol.getType());
            oldToNew.put(fol, folCopy);
        }
        connect(copy, folCopy);
        if (visited.put(fol, Boolean.TRUE) == null)
            merge(fol, folCopy, oldToNew, visited);
    }
}
Also used : SerializerPDAState(org.eclipse.xtext.serializer.analysis.SerializerPDA.SerializerPDAState)

Example 2 with SerializerPDAState

use of org.eclipse.xtext.serializer.analysis.SerializerPDA.SerializerPDAState in project xtext-core by eclipse.

the class ContextPDAProvider method collectExtracted.

protected void collectExtracted(ISerState orig, Collection<? extends ISerState> precedents, SerializerPDAState copy, Map<Pair<AbstractElement, SerStateType>, SerializerPDAState> oldToNew, final CallStack inTop, SerializerPDAState start) {
    for (ISerState pre : precedents) {
        CallStack top = inTop;
        AbstractElement element = pre.getGrammarElement();
        switch(pre.getType()) {
            case START:
                if (top.call == null)
                    connect(start, copy);
                continue;
            case POP:
                top = new CallStack(top, (RuleCall) element);
                if (top.isLoop())
                    continue;
                break;
            case PUSH:
                if (top.call == null) {
                    connect(start, copy);
                    continue;
                } else if (top.call == element) {
                    top = top.parent;
                } else {
                    continue;
                }
            default:
                break;
        }
        Pair<AbstractElement, SerStateType> key = Tuples.create(element, pre.getType());
        SerializerPDAState pre2 = oldToNew.get(key);
        if (pre2 == null) {
            pre2 = new SerializerPDAState(element, pre.getType());
            oldToNew.put(key, pre2);
        }
        if (GrammarUtil.isAssignedAction(pre.getGrammarElement())) /* && pre.getType() != STOP */
        {
            Set<ISerState> entries = collectPushForAction(pre);
            collectExtracted(pre, entries, pre2, oldToNew, top, start);
        } else {
            if (top.visited.add(pre))
                collectExtracted(pre, pre.getPrecedents(), pre2, oldToNew, top, start);
        }
        connect(pre2, copy);
    }
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) SerializerPDAState(org.eclipse.xtext.serializer.analysis.SerializerPDA.SerializerPDAState) RuleCall(org.eclipse.xtext.RuleCall) SerStateType(org.eclipse.xtext.serializer.analysis.ISerState.SerStateType)

Aggregations

SerializerPDAState (org.eclipse.xtext.serializer.analysis.SerializerPDA.SerializerPDAState)2 AbstractElement (org.eclipse.xtext.AbstractElement)1 RuleCall (org.eclipse.xtext.RuleCall)1 SerStateType (org.eclipse.xtext.serializer.analysis.ISerState.SerStateType)1