diff --git a/corpus/plpgsql/if_statement.txt b/corpus/plpgsql/if_statement.txt index 14be606..8288308 100644 --- a/corpus/plpgsql/if_statement.txt +++ b/corpus/plpgsql/if_statement.txt @@ -154,3 +154,71 @@ end $$; (return_statement (number))))) (dollar_quote)))) + +================================================================================ +if is not null +================================================================================ +do $$ begin +if foo is not null then select 1; end if; +end $$; +-------------------------------------------------------------------------------- + +(source_file + (do_block + (block + (dollar_quote) + (body + (if_statement + (op_expression + (identifier) + (comparison_null)) + (select_statement + (select_item + (number))))) + (dollar_quote)))) + +================================================================================ +if is not distinct from +================================================================================ +do $$ begin +if foo is not distinct from bar then select 1; end if; +end $$; +-------------------------------------------------------------------------------- + +(source_file + (do_block + (block + (dollar_quote) + (body + (if_statement + (op_expression + (identifier) + (comparison_kw) + (identifier)) + (select_statement + (select_item + (number))))) + (dollar_quote)))) + +================================================================================ +if is distinct from +================================================================================ +do $$ begin +if foo is distinct from bar then select 1; end if; +end $$; +-------------------------------------------------------------------------------- + +(source_file + (do_block + (block + (dollar_quote) + (body + (if_statement + (op_expression + (identifier) + (comparison_kw) + (identifier)) + (select_statement + (select_item + (number))))) + (dollar_quote)))) diff --git a/grammar.js b/grammar.js index c12b497..07cd682 100644 --- a/grammar.js +++ b/grammar.js @@ -757,7 +757,8 @@ module.exports = grammar({ prec.left(6, seq($._value_expression, $.other_op, $._value_expression)), // between in like ilike similar prec.left(4, seq($._value_expression, $.comparison_op, $._value_expression,)), - // is isnull notnull + prec.left(3, seq($._value_expression, $.comparison_kw, $._value_expression,)), + prec.left(3, seq($._value_expression, $.comparison_null)), prec.right(2, seq($.not, $._value_expression)), prec.left(1, seq($._value_expression, choice($.and, $.or), $._value_expression,)), ), @@ -766,8 +767,19 @@ module.exports = grammar({ // TODO(chrde): https://www.postgresql.org/docs/13/sql-syntax-lexical.html comparison_op: $ => choice("<", ">", "=", "<=", ">=", "<>", "!="), + comparison_null: $ => choice( + kw("is null"), + kw("isnull"), + kw("is not null"), + kw("notnull"), + ), + comparison_kw: $ => choice( + kw("is"), + kw("is distinct from"), + kw("is not distinct from") + ), // TODO(chrde): this should be a regex - other_op: $ => choice("||"), + other_op: $ => choice("||", "<@", "@>", "<<", ">>", "&&", "&<", "&>", "-|-"), cast: $ => "::", minus: $ => "-", plus: $ => "+",