tree-sitter / tree-sitter-c-sharp

C# Grammar for tree-sitter
MIT License
177 stars 48 forks source link

Improve pattern parsing #282

Open tamasvajk opened 1 year ago

tamasvajk commented 1 year ago

The below code reports parsing errors in the recursive patterns R(E.A), R(E.A or E.B), (E.A):

void M(R expr)
{
    var x = expr is R(E.A) v0;
    var y = expr is R(E.A or E.B) v1;
    var z = expr is (E.A or E.B) v2;
}

record R(E e) { }
enum E { A, B }

This is a recurring coding pattern in Roslyn.

tamasvajk commented 1 year ago

There's no parse error for

void M()
{
    var a = expr switch
    {
        R(E.A) => 1
    };
}

So the above might be related to is [pattern].

At the same time, the sample added to this comment produces incorrect AST for the pattern:

(switch_expression_arm [4, 8] - [4, 19]
  (constant_pattern [4, 8] - [4, 14]
    (invocation_expression [4, 8] - [4, 14]
      function: (identifier [4, 8] - [4, 9])
      arguments: (argument_list [4, 9] - [4, 14]
        (argument [4, 10] - [4, 13]
          (member_access_expression [4, 10] - [4, 13]
            expression: (identifier [4, 10] - [4, 11])
            name: (identifier [4, 12] - [4, 13]))))))

The pattern should be a recursive pattern and not a constant one.

vanessa-rodrigues commented 5 months ago

Are there any updates on this?