Search in sources :

Example 1 with Optional

use of org.whole.lang.grammars.model.Optional 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)

Example 2 with Optional

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

the class OptionalPart method getModelSpecificChildren.

protected List<IEntity> getModelSpecificChildren() {
    Optional entity = getModelEntity();
    List<IEntity> list = new ArrayList<IEntity>(1);
    list.add(entity.getRule());
    return list;
}
Also used : Optional(org.whole.lang.grammars.model.Optional) IEntity(org.whole.lang.model.IEntity) ArrayList(java.util.ArrayList)

Aggregations

Optional (org.whole.lang.grammars.model.Optional)2 ArrayList (java.util.ArrayList)1 As (org.whole.lang.grammars.model.As)1 Concatenate (org.whole.lang.grammars.model.Concatenate)1 NonTerminal (org.whole.lang.grammars.model.NonTerminal)1 Repeat (org.whole.lang.grammars.model.Repeat)1 Rule (org.whole.lang.grammars.model.Rule)1 IEntity (org.whole.lang.model.IEntity)1