diff --git a/grammar.js b/grammar.js index a5c9f2b9..41c43266 100644 --- a/grammar.js +++ b/grammar.js @@ -1940,7 +1940,15 @@ module.exports = grammar({ invocation: $ => seq( field('name', $.identifier), - paren_list(field('parameter', $._select_expression)), + paren_list( + seq( + optional($.keyword_distinct), + field( + 'parameter', + $._select_expression, + ), + optional($.order_by) + )), ), exists: $ => seq( @@ -2241,11 +2249,11 @@ module.exports = grammar({ $._expression, ), - order_by: $ => seq( + order_by: $ => prec.right(seq( $.keyword_order, $.keyword_by, comma_list($.order_target, true), - ), + )), order_target: $ => seq( $._expression, diff --git a/test/corpus/functions.txt b/test/corpus/functions.txt index ac32a406..a0e05d07 100644 --- a/test/corpus/functions.txt +++ b/test/corpus/functions.txt @@ -168,12 +168,16 @@ FROM table_a; (term value: (invocation name: (identifier) + (keyword_distinct) parameter: (term value: (field - name: (identifier)) - alias: (identifier)) - (ERROR - (keyword_by)))))) + name: (identifier))) + (order_by + (keyword_order) + (keyword_by) + (order_target + (field + name: (identifier)))))))) (from (keyword_from) (relation diff --git a/test/corpus/select.txt b/test/corpus/select.txt index a44f269f..843aae81 100644 --- a/test/corpus/select.txt +++ b/test/corpus/select.txt @@ -474,10 +474,10 @@ FROM my_table; (term value: (invocation name: (identifier) + (keyword_distinct) parameter: (term value: (field - name: (identifier)) - alias: (identifier))) + name: (identifier)))) (keyword_as) alias: (identifier)))) (from @@ -727,12 +727,10 @@ FROM my_table; (term value: (invocation name: (identifier) + (keyword_distinct) parameter: (term - value: (invocation - name: (identifier) - parameter: (term - value: (field - name: (identifier))))))))) + value: (field + name: (identifier))))))) (from (keyword_from) (relation @@ -778,10 +776,10 @@ FROM my_table; (term value: (invocation name: (identifier) + (keyword_distinct) parameter: (term value: (field - name: (identifier)) - alias: (identifier)))))) + name: (identifier))))))) (from (keyword_from) (relation