use of io.vertigo.commons.peg.PegChoice in project vertigo by KleeGroup.
the class DslTermQueryRule method handle.
/**
* {@inheritDoc}
*/
@Override
protected DslTermQuery handle(final List<Object> parsing) {
final String preSpaces = (String) parsing.get(0);
final String preQuery = (String) parsing.get(1);
final List<Object> term = (List<Object>) parsing.get(2);
final String preTerm = (String) term.get(1);
final String termField = (String) term.get(2);
final String postTerm = (String) term.get(3);
final Optional<PegChoice> escapeRule = (Optional<PegChoice>) term.get(5);
final EscapeMode escapeMode;
if (escapeRule.isPresent()) {
switch(escapeRule.get().getChoiceIndex()) {
case 0:
escapeMode = EscapeMode.remove;
break;
case 1:
escapeMode = EscapeMode.escape;
break;
default:
throw new IllegalArgumentException("case " + escapeRule.get().getChoiceIndex() + " not implemented");
}
} else {
escapeMode = EscapeMode.none;
}
final Optional<List<Object>> defaultRuleOpt = (Optional<List<Object>>) term.get(6);
final Optional<String> defaultValue = defaultRuleOpt.map(defaultRule -> (String) defaultRule.get(1));
final String postQuery = (String) parsing.get(3);
// final String postSpaces = (String) parsing.get(4);
return new DslTermQuery(DslUtil.concat(preSpaces, preQuery), preTerm, termField, postTerm, escapeMode, defaultValue, postQuery);
}
use of io.vertigo.commons.peg.PegChoice in project vertigo by KleeGroup.
the class DslExpressionRule method handle.
/**
* {@inheritDoc}
*/
@Override
protected DslExpression handle(final List<Object> parsing) {
String preExpression = ((Optional<String>) parsing.get(0)).orElse("") + parsing.get(1);
final String postExpression;
final Optional<DslField> field;
final Optional<DslMultiField> multiField;
final PegChoice fields = (PegChoice) parsing.get(2);
switch(fields.getChoiceIndex()) {
case 0:
field = Optional.of((DslField) fields.getValue());
multiField = Optional.empty();
postExpression = "";
break;
case 1:
final List<Object> multiFieldParsing = (List<Object>) fields.getValue();
preExpression = DslUtil.concat(preExpression, (String) multiFieldParsing.get(0));
multiField = Optional.of((DslMultiField) multiFieldParsing.get(1));
postExpression = (String) multiFieldParsing.get(2);
field = Optional.empty();
break;
default:
throw new IllegalArgumentException("case " + fields.getChoiceIndex() + " not implemented");
}
final PegChoice queries = (PegChoice) parsing.get(4);
final DslQuery query = (DslQuery) queries.getValue();
return new DslExpression(preExpression, field, multiField, query, postExpression);
}
use of io.vertigo.commons.peg.PegChoice in project vertigo by KleeGroup.
the class DslMultiExpressionRule method handle.
/**
* {@inheritDoc}
*/
@Override
protected DslMultiExpression handle(final PegChoice parsing) {
final String preMultiExpression;
final String postMultiExpression;
// ---
final List<PegChoice> many;
switch(parsing.getChoiceIndex()) {
case 0:
final List<?> blockExpression = (List<?>) parsing.getValue();
preMultiExpression = ((Optional<String>) blockExpression.get(0)).orElse("") + blockExpression.get(1);
many = (List<PegChoice>) blockExpression.get(3);
postMultiExpression = (String) blockExpression.get(5);
break;
case 1:
preMultiExpression = "";
many = (List<PegChoice>) parsing.getValue();
postMultiExpression = "";
break;
default:
throw new IllegalArgumentException("case " + parsing.getChoiceIndex() + " not implemented");
}
final List<DslExpression> expressionDefinitions = new ArrayList<>();
final List<DslMultiExpression> multiExpressionDefinitions = new ArrayList<>();
// On récupère le produit de la règle many
for (final PegChoice item : many) {
switch(item.getChoiceIndex()) {
case 0:
expressionDefinitions.add((DslExpression) item.getValue());
break;
case 1:
multiExpressionDefinitions.add((DslMultiExpression) item.getValue());
break;
default:
throw new IllegalArgumentException("case " + item.getChoiceIndex() + " not implemented");
}
}
final boolean block = parsing.getChoiceIndex() == 0;
// ---
return new DslMultiExpression(preMultiExpression, block, expressionDefinitions, multiExpressionDefinitions, postMultiExpression);
}
use of io.vertigo.commons.peg.PegChoice in project vertigo by KleeGroup.
the class DslDefinitionBodyRule method handle.
@Override
protected DslDefinitionBody handle(final List<Object> parsing) {
final List<PegChoice> many = (List<PegChoice>) parsing.get(2);
final List<DslDefinitionEntry> fieldDefinitionEntries = new ArrayList<>();
final List<DslPropertyEntry> fieldPropertyEntries = new ArrayList<>();
for (final PegChoice item : many) {
switch(item.getChoiceIndex()) {
case 0:
// Soit on est en présence d'une propriété standard
final DslPropertyEntry propertyEntry = (DslPropertyEntry) item.getValue();
fieldPropertyEntries.add(propertyEntry);
break;
case 1:
final DslDefinitionEntry xDefinitionEntry = (DslDefinitionEntry) item.getValue();
fieldDefinitionEntries.add(xDefinitionEntry);
break;
case 2:
final PegChoice subTuple = (PegChoice) item.getValue();
fieldDefinitionEntries.add((DslDefinitionEntry) subTuple.getValue());
break;
case 3:
break;
default:
throw new IllegalArgumentException("Type of rule not supported");
}
}
return new DslDefinitionBody(fieldDefinitionEntries, fieldPropertyEntries);
}
use of io.vertigo.commons.peg.PegChoice in project vertigo by KleeGroup.
the class DslRangeQueryRule method handle.
/**
* {@inheritDoc}
*/
@Override
protected DslRangeQuery handle(final List<Object> parsing) {
final String preQuery = (String) parsing.get(0);
final PegChoice startChoice = (PegChoice) parsing.get(1);
final PegChoice startTermQuery = (PegChoice) parsing.get(2);
final DslQuery startQueryDefinitions;
if (startTermQuery.getChoiceIndex() == 0) {
startQueryDefinitions = new DslFixedQuery("*");
} else {
startQueryDefinitions = (DslQuery) startTermQuery.getValue();
}
final PegChoice endTermQuery = (PegChoice) parsing.get(6);
final DslQuery endQueryDefinitions;
if (endTermQuery.getChoiceIndex() == 0) {
endQueryDefinitions = new DslFixedQuery("*");
} else {
endQueryDefinitions = (DslQuery) endTermQuery.getValue();
}
final PegChoice endChoice = (PegChoice) parsing.get(8);
final String postQuery = (String) parsing.get(9);
final String startRange = (String) startChoice.getValue();
final String endRange = (String) endChoice.getValue();
return new DslRangeQuery(preQuery, startRange, startQueryDefinitions, endQueryDefinitions, endRange, postQuery);
}
Aggregations