DerekStride / tree-sitter-sql

SQL grammar for tree-sitter
http://derek.stride.host/tree-sitter-sql/
MIT License
155 stars 52 forks source link

wip: Add a the rule _expression_without_subquery. #206

Open antoineB opened 1 year ago

antoineB commented 1 year ago

Work in progress

Is it the right way to do it ? Is it worth the trouble ? Does it at complexity too much complexity to the grammar (N° of states, time, maintainability) ?

antoineB commented 1 year ago

Maybe what is wanted is removing rules $.list and wrapped_in_parenthesis($._expression)

    _unwrapped_expression: $ => prec(1,
      choice(
        $.literal,
        alias(
          $._qualified_field,
          $.field,
        ),
        $.parameter,
        $.case,
        $.window_function,
        $.cast,
        alias($.implicit_cast, $.cast),
        $.exists,
        $.invocation,
        $.binary_expression,
        $.unary_expression,
        $.array,
        $.interval,
        $.between_expression,
      )
    ),

    _expression: $ => choice(
        $._unwrapped_expression_without_starting_subquery,
        $.subquery,
        wrapped_in_parenthesis($._expression),
        $.list
    ),

    function_declaration: $ => seq(
      $.identifier,
      $._type,
      optional(
        seq(
          ':=',
          choice(
            wrapped_in_parenthesis($.statement),
            wrapped_in_parenthesis($._unwrapped_expression_without_starting_subquery),
            $._unwrapped_expression_without_starting_subquery,
            $.list,
          ),
        ),
      ),
      ';',
    ),