Search in sources :

Example 1 with Concatenate

use of org.whole.lang.grammars.model.Concatenate in project whole by wholeplatform.

the class ParserTemplateFactory method propagateActivation.

protected void propagateActivation(Set<ActiveRule> terminalSet, Set<NonTerminal> recursiveSet, ListIterator<ActiveRule> activeRules, ActiveRule ar) {
    Rule dotRule = ar.getDotRule();
    switch(dotRule.wGetEntityOrd()) {
        case GrammarsEntityDescriptorEnum.DataTerminal_ord:
        case GrammarsEntityDescriptorEnum.LiteralTerminal_ord:
            terminalSet.add(ar);
            break;
        case GrammarsEntityDescriptorEnum.NonTerminal_ord:
            NonTerminal nt = (NonTerminal) dotRule;
            if (recursiveSet.add(nt)) {
                activeRules.add(ar = createActiveRule(nt));
                propagateActivation(terminalSet, recursiveSet, activeRules, ar);
            } else
                ar.setRecursive(true);
            break;
        case GrammarsEntityDescriptorEnum.Concatenate_ord:
            Concatenate c = (Concatenate) dotRule;
            if (c.wSize() > 0) {
                ar.setDotRule((Rule) c.wGet(0));
                propagateActivation(terminalSet, recursiveSet, activeRules, ar);
            }
            break;
        case GrammarsEntityDescriptorEnum.Optional_ord:
            Optional o = (Optional) dotRule;
            ar.setDotRule(o.getRule());
            propagateActivation(terminalSet, recursiveSet, activeRules, ar);
            // TODO add also the rule after the optional
            break;
        case GrammarsEntityDescriptorEnum.Repeat_ord:
            Repeat r = (Repeat) dotRule;
            // TODO check lower bound and split active state for repeat continuation if 0
            ar.setDotRule(r.getRule());
            propagateActivation(terminalSet, recursiveSet, activeRules, ar);
            break;
        case GrammarsEntityDescriptorEnum.As_ord:
            As as = (As) dotRule;
            ar.setDotRule(as.getRule());
            propagateActivation(terminalSet, recursiveSet, activeRules, ar);
            break;
    }
}
Also used : As(org.whole.lang.grammars.model.As) Optional(org.whole.lang.grammars.model.Optional) Concatenate(org.whole.lang.grammars.model.Concatenate) NonTerminal(org.whole.lang.grammars.model.NonTerminal) Repeat(org.whole.lang.grammars.model.Repeat) Rule(org.whole.lang.grammars.model.Rule)

Aggregations

As (org.whole.lang.grammars.model.As)1 Concatenate (org.whole.lang.grammars.model.Concatenate)1 NonTerminal (org.whole.lang.grammars.model.NonTerminal)1 Optional (org.whole.lang.grammars.model.Optional)1 Repeat (org.whole.lang.grammars.model.Repeat)1 Rule (org.whole.lang.grammars.model.Rule)1