Search in sources :

Example 1 with DslEntityLink

use of io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntityLink in project vertigo by KleeGroup.

the class DslDefinitionBodyRule method createMainRule.

private static PegRule<List<Object>> createMainRule(final DslEntity entity) {
    Assertion.checkNotNull(entity);
    final List<String> attributeNames = new ArrayList<>();
    final List<PegRule<?>> innerDefinitionRules = new ArrayList<>();
    for (final DslEntityField dslEntityField : entity.getFields()) {
        attributeNames.add(dslEntityField.getName());
        final DslEntity dslEntity;
        if (dslEntityField.getType() instanceof DslEntity) {
            dslEntity = DslEntity.class.cast(dslEntityField.getType());
        } else if (dslEntityField.getType() instanceof DslEntityLink) {
            dslEntity = DslEntityLink.class.cast(dslEntityField.getType()).getEntity();
        } else {
            // case property
            dslEntity = null;
        }
        if (dslEntity != null) {
            innerDefinitionRules.add(new DslInnerDefinitionRule(dslEntityField.getName(), dslEntity));
        }
    }
    final DslPropertyDeclarationRule propertyDeclarationRule = new DslPropertyDeclarationRule(entity.getPropertyNames());
    final DslDefinitionEntryRule xDefinitionEntryRule = new DslDefinitionEntryRule(attributeNames);
    final PegRule<PegChoice> firstOfRule = PegRules.choice(// 0
    propertyDeclarationRule, // 1
    xDefinitionEntryRule, // 2,
    PegRules.choice(innerDefinitionRules), SPACES);
    final PegRule<List<PegChoice>> manyRule = PegRules.zeroOrMore(firstOfRule, false);
    return PegRules.sequence(OBJECT_START, SPACES, // 2
    manyRule, SPACES, OBJECT_END);
}
Also used : DslEntityLink(io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntityLink) ArrayList(java.util.ArrayList) PegChoice(io.vertigo.commons.peg.PegChoice) PegRule(io.vertigo.commons.peg.PegRule) DslEntity(io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity) DslEntityField(io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntityField) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

PegChoice (io.vertigo.commons.peg.PegChoice)1 PegRule (io.vertigo.commons.peg.PegRule)1 DslEntity (io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity)1 DslEntityField (io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntityField)1 DslEntityLink (io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntityLink)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1