From 48e0701909ebcea77e824fc15c944e2d5b4acf99 Mon Sep 17 00:00:00 2001 From: Christian De la Hoz Date: Wed, 1 Sep 2021 19:14:42 +0200 Subject: [PATCH] in, between.. --- corpus/select_statement/value_expression.txt | 44 ++++++++++++++++++++ grammar.js | 6 ++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/corpus/select_statement/value_expression.txt b/corpus/select_statement/value_expression.txt index 5e2e2ec..ecadf07 100644 --- a/corpus/select_statement/value_expression.txt +++ b/corpus/select_statement/value_expression.txt @@ -211,6 +211,50 @@ SELECT 'hello' || 'quote''s everywh''ere'; (other_op) (string))))) +================================================================================ +contains_op +================================================================================ +SELECT + 1 in (1, 2), + 'one' in ('one', 'two'), + 2 between 4 and 8, + 'foo' like '%oo', + 'foo' ilike '%oo'; +-------------------------------------------------------------------------------- + +(source_file + (select_statement + (select_item + (op_expression + (number) + (contains_op) + (number) + (number))) + (select_item + (op_expression + (string) + (contains_op) + (string) + (string))) + (select_item + (op_expression + (op_expression + (number) + (contains_op) + (number)) + (and) + (number))) + (select_item + (op_expression + (string) + (contains_op) + (string))) + (select_item + (op_expression + (string) + (contains_op) + (string))))) + ================================================================================ is null, isnull, is not null, notnull ================================================================================ diff --git a/grammar.js b/grammar.js index c6530cc..5ee2b23 100644 --- a/grammar.js +++ b/grammar.js @@ -729,7 +729,7 @@ module.exports = grammar({ $.null, $.star, seq("(", $.select_statement, ")"), - seq("(", $._value_expression, ")"), + seq("(", commaSep1($._value_expression), ")"), $.function_call, $.op_expression, $.time_expression, @@ -786,7 +786,7 @@ module.exports = grammar({ prec.left(8, seq($._value_expression, choice("*", "/", "%"), $._value_expression,)), prec.left(7, seq($._value_expression, choice("-", "+"), $._value_expression,)), prec.left(6, seq($._value_expression, $.other_op, $._value_expression)), - // between in like ilike similar + prec.left(5, seq($._value_expression, $.contains_op, $._value_expression,)), prec.left(4, seq($._value_expression, $.comparison_op, $._value_expression,)), prec.left(3, seq($._value_expression, $.comparison_kw, $._value_expression,)), prec.left(3, seq($._value_expression, $.comparison_null)), @@ -798,6 +798,8 @@ module.exports = grammar({ // TODO(chrde): https://www.postgresql.org/docs/13/sql-syntax-lexical.html comparison_op: $ => choice("<", ">", "=", "<=", ">=", "<>", "!="), + // TODO(chrde): is there a better name other than `contains_op`? + contains_op: $ => choice(kw("between"), kw("in"), kw("like"), kw("ilike")), comparison_null: $ => choice( kw("is null"), kw("isnull"),