Search in sources :

Example 1 with SerStateType

use of org.eclipse.xtext.serializer.analysis.ISerState.SerStateType in project xtext-core by eclipse.

the class ContextPDAProvider method filterUnneededUnassignedRuleCalls.

protected Pda<ISerState, RuleCall> filterUnneededUnassignedRuleCalls(Pda<ISerState, RuleCall> pda, Map<ParserRule, Integer> indexedRules) {
    Set<ParserRule> exclude = findRuleCallsToExclude(pda, indexedRules);
    if (exclude.isEmpty())
        return pda;
    SerializerPDA filtered = pdaUtil.filter(pda, new Predicate<ISerState>() {

        @Override
        public boolean apply(ISerState input) {
            SerStateType type = input.getType();
            if (type == SerStateType.PUSH || type == SerStateType.POP) {
                AbstractRule rule = ((RuleCall) input.getGrammarElement()).getRule();
                return !exclude.contains(rule);
            }
            return true;
        }
    }, new SerializerPDACloneFactory());
    return filtered;
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) AbstractRule(org.eclipse.xtext.AbstractRule) SerStateType(org.eclipse.xtext.serializer.analysis.ISerState.SerStateType) SerializerPDACloneFactory(org.eclipse.xtext.serializer.analysis.SerializerPDA.SerializerPDACloneFactory)

Example 2 with SerStateType

use of org.eclipse.xtext.serializer.analysis.ISerState.SerStateType 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

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