use of io.vertigo.commons.peg.PegChoice in project vertigo by KleeGroup.
the class DslMultiQueryRule method handle.
/**
* {@inheritDoc}
*/
@Override
protected DslBlockQuery handle(final List<Object> parsing) {
final String preQuery = (String) parsing.get(0);
final List<DslQuery> queryDefinitions = new ArrayList<>();
final String postQuery = (String) parsing.get(4);
final List<PegChoice> manyQueries = (List<PegChoice>) parsing.get(2);
for (final PegChoice item : manyQueries) {
queryDefinitions.add((DslQuery) item.getValue());
}
return new DslBlockQuery(preQuery, queryDefinitions, postQuery);
}
use of io.vertigo.commons.peg.PegChoice in project vertigo by KleeGroup.
the class DslMultiExpressionRule method handle.
/**
* {@inheritDoc}
*/
@Override
protected RuleMultiExpression handle(final PegChoice parsing) {
final List<Object> innerBlock;
switch(parsing.getChoiceIndex()) {
case 0:
final List<?> blockExpression = (List<?>) parsing.getValue();
innerBlock = (List<Object>) blockExpression.get(2);
break;
case 1:
innerBlock = (List<Object>) parsing.getValue();
break;
default:
throw new IllegalArgumentException("case " + parsing.getChoiceIndex() + " not implemented");
}
final List<RuleExpression> expressionDefinitions = new ArrayList<>();
final List<RuleMultiExpression> multiExpressionDefinitions = new ArrayList<>();
// first (expression1|multiExpression1)
final PegChoice firstExpressionChoice = (PegChoice) innerBlock.get(1);
switch(firstExpressionChoice.getChoiceIndex()) {
case 0:
expressionDefinitions.add((RuleExpression) firstExpressionChoice.getValue());
break;
case 1:
multiExpressionDefinitions.add((RuleMultiExpression) firstExpressionChoice.getValue());
break;
default:
throw new IllegalArgumentException("case " + parsing.getChoiceIndex() + " not implemented");
}
// manyNextExpressionsRule
final List<List<Object>> many = (List<List<Object>>) innerBlock.get(3);
// On récupère le produit de la règle many
BoolOperator operator = null;
for (final List<Object> item : many) {
if (operator != null && operator != item.get(1)) {
throw new IllegalArgumentException("Can't use different operator in same block, attempt to find " + operator);
}
operator = (BoolOperator) item.get(1);
// next (expression2|multiExpression2)
final PegChoice nextExpressionChoice = (PegChoice) item.get(3);
switch(nextExpressionChoice.getChoiceIndex()) {
case 0:
expressionDefinitions.add((RuleExpression) nextExpressionChoice.getValue());
break;
case 1:
multiExpressionDefinitions.add((RuleMultiExpression) nextExpressionChoice.getValue());
break;
default:
throw new IllegalArgumentException("case " + nextExpressionChoice.getChoiceIndex() + " not implemented");
}
}
final boolean block = parsing.getChoiceIndex() == 0;
// ---
return new RuleMultiExpression(block, operator != null ? operator : BoolOperator.AND, expressionDefinitions, multiExpressionDefinitions);
}
use of io.vertigo.commons.peg.PegChoice 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);
}
use of io.vertigo.commons.peg.PegChoice in project vertigo by KleeGroup.
the class DslDefinitionEntryRule method handle.
@Override
protected DslDefinitionEntry handle(final List<Object> parsing) {
final String fieldName = (String) ((PegChoice) parsing.get(0)).getValue();
final List<String> definitionKeys;
final PegChoice definitionChoice = (PegChoice) parsing.get(4);
switch(definitionChoice.getChoiceIndex()) {
case 1:
// Déclaration d'une liste de définitions identifiée par leurs clés
definitionKeys = (List<String>) definitionChoice.getValue();
break;
case 0:
// Déclaration d'une définition identifiée par sa clé
final String value = (String) definitionChoice.getValue();
definitionKeys = java.util.Collections.singletonList(value);
break;
default:
throw new IllegalStateException();
}
return new DslDefinitionEntry(fieldName, definitionKeys);
}
use of io.vertigo.commons.peg.PegChoice in project vertigo by KleeGroup.
the class DslKspRule method handle.
@Override
protected Dummy handle(final List<Object> parsing) {
final String packageName = (String) parsing.get(1);
final List<PegChoice> declarationChoices = (List<PegChoice>) parsing.get(3);
for (final PegChoice declarationChoice : declarationChoices) {
// - à des gestion de droits.
switch(declarationChoice.getChoiceIndex()) {
case 0:
// On positionne le Package
final DslDefinition oldDynamicDefinition = (DslDefinition) declarationChoice.getValue();
final DslDefinition newDynamicDefinition = DslDefinition.builder(oldDynamicDefinition.getName(), oldDynamicDefinition.getEntity()).withPackageName(packageName).merge(oldDynamicDefinition).build();
handleDefinitionRule(newDynamicDefinition);
break;
case 1:
handleTemplateRule((DslDefinition) declarationChoice.getValue());
break;
default:
throw new IllegalArgumentException("case " + declarationChoice.getChoiceIndex() + " not implemented");
}
}
return Dummy.INSTANCE;
}
Aggregations