use of io.vertigo.commons.peg.PegRule 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);
}
Aggregations