diff --git a/grammar.js b/grammar.js index 69d0a1d4..fef5688f 100644 --- a/grammar.js +++ b/grammar.js @@ -30,10 +30,11 @@ module.exports = grammar({ 'binary_exp', 'binary_times', 'binary_plus', + 'unary_other', + 'binary_other', 'binary_in', 'binary_compare', 'binary_relation', - 'binary_concat', 'pattern_matching', 'between', 'clause_connective', @@ -3001,6 +3002,52 @@ module.exports = grammar({ ) ), + op_other: $ => token( + choice( + '->', + '->>', + '#>', + '#>>', + '~', + '!~', + '~*', + '!~*', + '|', + '&', + '#', + '<<', + '>>', + '<<=', + '>>=', + '##', + '<->', + '@>', + '<@', + '&<', + '&>', + '|>>', + '<<|', + '&<|', + '|&>', + '<^', + '^>', + '?#', + '?-', + '?|', + '?-|', + '?||', + '@@', + '@@@', + '@?', + '#-', + '?&', + '?', + '-|-', + '||', + '^@', + ), + ), + binary_expression: $ => choice( ...[ ['+', 'binary_plus'], @@ -3009,7 +3056,6 @@ module.exports = grammar({ ['/', 'binary_times'], ['%', 'binary_times'], ['^', 'binary_exp'], - ['||', 'binary_concat'], ['=', 'binary_relation'], ['<', 'binary_relation'], ['<=', 'binary_relation'], @@ -3017,10 +3063,7 @@ module.exports = grammar({ ['>=', 'binary_relation'], ['>', 'binary_relation'], ['<>', 'binary_relation'], - ['->', 'binary_relation'], - ['->>', 'binary_relation'], - ['#>', 'binary_relation'], - ['#>>', 'binary_relation'], + [$.op_other, 'binary_other'], [$.keyword_is, 'binary_is'], [$.is_not, 'binary_is'], [$.keyword_like, 'pattern_matching'], @@ -3060,6 +3103,21 @@ module.exports = grammar({ ), ), + op_unary_other: $ => token( + choice( + '|/', + '||/', + '@', + '~', + '@-@', + '@@', + '#', + '?-', + '?|', + '!!', + ), + ), + unary_expression: $ => choice( ...[ [$.keyword_not, 'unary_not'], @@ -3067,6 +3125,7 @@ module.exports = grammar({ [$.keyword_any, 'unary_not'], [$.keyword_some, 'unary_not'], [$.keyword_all, 'unary_not'], + [$.op_unary_other, 'unary_other'], ].map(([operator, precedence]) => prec.left(precedence, seq( field('operator', operator), diff --git a/queries/highlights.scm b/queries/highlights.scm index 22d11839..ab0caf5b 100644 --- a/queries/highlights.scm +++ b/queries/highlights.scm @@ -401,10 +401,8 @@ ">=" ">" "<>" - "->" - "->>" - "#>" - "#>>" + (op_other) + (op_unary_other) ] @operator [ diff --git a/test/corpus/expressions.txt b/test/corpus/expressions.txt index ce2e2ae2..a6e34c1e 100644 --- a/test/corpus/expressions.txt +++ b/test/corpus/expressions.txt @@ -588,3 +588,52 @@ WHERE left: (field name: (identifier)) right: (literal)))))) + +================================================================================ +string operator concat and start with +================================================================================ + +SELECT 'abc' ^@ 'a' || 'z'; + +-------------------------------------------------------------------------------- + +(program + (statement + (select + (keyword_select) + (select_expression + (term + (binary_expression + (binary_expression + (literal) + (op_other) + (literal)) + (op_other) + (literal))))))) + +================================================================================ +full text search operators +================================================================================ + +SELECT 'fat cats ate rats' @@ !! ('cat' <-> 'rat'::tsquery); + +-------------------------------------------------------------------------------- + +(program + (statement + (select + (keyword_select) + (select_expression + (term + (binary_expression + (literal) + (op_other) + (unary_expression + (op_unary_other) + (cast + (binary_expression + (literal) + (op_other) + (literal)) + (object_reference + (identifier)))))))))) diff --git a/test/corpus/json.txt b/test/corpus/json.txt index 522b2cf7..b819a217 100644 --- a/test/corpus/json.txt +++ b/test/corpus/json.txt @@ -20,6 +20,7 @@ FROM users; (term value: (binary_expression left: (literal) + operator: (op_other) right: (literal)) (keyword_as) alias: (identifier)) @@ -27,23 +28,29 @@ FROM users; value: (binary_expression left: (binary_expression left: (literal) + operator: (op_other) right: (literal)) + operator: (op_other) right: (literal))) (term value: (binary_expression left: (binary_expression left: (literal) + operator: (op_other) right: (literal)) + operator: (op_other) right: (literal)) (keyword_as) alias: (identifier)) (term value: (binary_expression left: (literal) + operator: (op_other) right: (literal))) (term value: (binary_expression left: (literal) + operator: (op_other) right: (literal)) (keyword_as) alias: (identifier)))) diff --git a/test/corpus/select.txt b/test/corpus/select.txt index ba37484c..6f98ad10 100644 --- a/test/corpus/select.txt +++ b/test/corpus/select.txt @@ -2081,7 +2081,9 @@ SELECT id || '-' || name FROM my_table; left: (binary_expression left: (field name: (identifier)) + operator: (op_other) right: (literal)) + operator: (op_other) right: (field name: (identifier)))))) (from