replace 'in' queries with a simpler syntax
field in (val1, val2) was replaced with field=val1,val2 or field=(val1, val2)
This commit is contained in:
@@ -9,12 +9,15 @@ start : expression EOF ;
|
||||
expression
|
||||
: LPAREN expression RPAREN #parenExpression
|
||||
| NOT expression #notExpression
|
||||
| prop=identifier eq=equal value=propValue #propertyExpression
|
||||
//| prop=identifier in=inExpr LPAREN listOfProperties=listOfPropValues RPAREN #inExpression
|
||||
| '_in' prop=identifier in=inExpr LPAREN listOfProperties=listOfPropValues RPAREN #inExpression
|
||||
| prop=identifier eq=equal enclosedListOfPropValues #propertyExpression
|
||||
| left=expression AND right=expression #binaryAndExpression
|
||||
| left=expression OR right=expression #binaryOrExpression
|
||||
;
|
||||
|
||||
enclosedListOfPropValues
|
||||
: listOfPropValues
|
||||
| LPAREN listOfProperties=listOfPropValues RPAREN
|
||||
;
|
||||
|
||||
listOfPropValues
|
||||
: value=propValue
|
||||
@@ -29,7 +32,6 @@ propValue
|
||||
;
|
||||
|
||||
equal : EQUAL ;
|
||||
inExpr : IN ;
|
||||
|
||||
AND : 'and' ;
|
||||
OR : 'or' ;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class Proposer {
|
||||
result = ProposerParser.parse(q.toString(), dataStore, caretIndex + 1);
|
||||
}
|
||||
|
||||
return CollectionUtils.filter(result, p -> p.hasResults());
|
||||
return CollectionUtils.filter(result, Proposal::hasResults);
|
||||
}
|
||||
|
||||
private SortedSet<Proposal> proposeForAllKeys() {
|
||||
|
||||
@@ -26,7 +26,7 @@ public class ProposerParser {
|
||||
final CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||
|
||||
final QueryCompletionPdbLangParser parser = new QueryCompletionPdbLangParser(tokens);
|
||||
parser.setTrace(true);
|
||||
parser.setTrace(false);
|
||||
|
||||
final Listener listener = parser.new Listener(query, dataStore, caretIndex);
|
||||
parser.addErrorListener(listener);
|
||||
|
||||
@@ -60,7 +60,8 @@ public class QueryCompletionPdbLangParser extends PdbLangParser {
|
||||
if (_ctx.getParent() instanceof ListOfPropValuesContext) {
|
||||
// for in-expressions, e.g. key in (val)
|
||||
ParserRuleContext parent = _ctx.getParent();
|
||||
while (parent instanceof ListOfPropValuesContext) {
|
||||
while (parent instanceof ListOfPropValuesContext
|
||||
|| parent instanceof EnclosedListOfPropValuesContext) {
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
||||
@@ -274,26 +275,10 @@ public class QueryCompletionPdbLangParser extends PdbLangParser {
|
||||
public void enterEqual(final EqualContext ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterInExpr(final InExprContext ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterInExpression(final InExpressionContext ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exitEqual(final EqualContext ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exitInExpr(final InExprContext ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exitInExpression(final InExpressionContext ctx) {
|
||||
}
|
||||
|
||||
private boolean isEOF(final TerminalNode node) {
|
||||
return node.getSymbol().getType() < 0;
|
||||
}
|
||||
@@ -326,6 +311,14 @@ public class QueryCompletionPdbLangParser extends PdbLangParser {
|
||||
@Override
|
||||
public void exitListOfPropValues(final ListOfPropValuesContext ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterEnclosedListOfPropValues(final EnclosedListOfPropValuesContext ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exitEnclosedListOfPropValues(final EnclosedListOfPropValuesContext ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
public QueryCompletionPdbLangParser(final TokenStream input) {
|
||||
|
||||
@@ -13,16 +13,14 @@ import org.lucares.pdb.datastore.lang.Expression.InExpression;
|
||||
import org.lucares.pdb.datastore.lang.Expression.ListOfPropertyValues;
|
||||
import org.lucares.pdb.datastore.lang.Expression.Not;
|
||||
import org.lucares.pdb.datastore.lang.Expression.OrTemporary;
|
||||
import org.lucares.pdb.datastore.lang.Expression.Property;
|
||||
import org.lucares.pdb.datastore.lang.Expression.TemporaryExpression;
|
||||
import org.lucares.pdb.datastore.lang.Expression.Terminal;
|
||||
import org.lucares.pdb.datastore.lang.PdbLangParser.BinaryAndExpressionContext;
|
||||
import org.lucares.pdb.datastore.lang.PdbLangParser.BinaryOrExpressionContext;
|
||||
import org.lucares.pdb.datastore.lang.PdbLangParser.EnclosedListOfPropValuesContext;
|
||||
import org.lucares.pdb.datastore.lang.PdbLangParser.IdentifierExpressionContext;
|
||||
import org.lucares.pdb.datastore.lang.PdbLangParser.InExpressionContext;
|
||||
import org.lucares.pdb.datastore.lang.PdbLangParser.ListOfPropValuesContext;
|
||||
import org.lucares.pdb.datastore.lang.PdbLangParser.NotExpressionContext;
|
||||
import org.lucares.pdb.datastore.lang.PdbLangParser.PropertyExpressionContext;
|
||||
import org.lucares.pdb.datastore.lang.PdbLangParser.PropertyTerminalExpressionContext;
|
||||
|
||||
public class QueryLanguage {
|
||||
@@ -72,16 +70,16 @@ public class QueryLanguage {
|
||||
|
||||
stack.push(new Terminal(ctx.getText(), line, startIndex, stopIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exitPropertyExpression(final PropertyExpressionContext ctx) {
|
||||
// System.out.println("property expression");
|
||||
|
||||
final Expression value = stack.pop();
|
||||
final Terminal property = (Terminal) stack.pop();
|
||||
|
||||
stack.push(new Property(property.getValue(), (Terminal) value));
|
||||
}
|
||||
// TODO remove
|
||||
// @Override
|
||||
// public void exitPropertyExpression(final PropertyExpressionContext ctx) {
|
||||
// // System.out.println("property expression");
|
||||
//
|
||||
// final Expression value = stack.pop();
|
||||
// final Terminal property = (Terminal) stack.pop();
|
||||
//
|
||||
// stack.push(new Property(property.getValue(), (Terminal) value));
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void exitNotExpression(final NotExpressionContext ctx) {
|
||||
@@ -134,7 +132,7 @@ public class QueryLanguage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exitInExpression(final InExpressionContext ctx) {
|
||||
public void exitEnclosedListOfPropValues(final EnclosedListOfPropValuesContext ctx) {
|
||||
|
||||
final ListOfPropertyValues propertyValues = (ListOfPropertyValues) stack.pop();
|
||||
final Terminal propertyName = (Terminal) stack.pop();
|
||||
|
||||
Reference in New Issue
Block a user