nushell / tree-sitter-nu

A tree-sitter grammar for nu-lang, the language of nushell
MIT License
97 stars 24 forks source link

Fix corner case for ctrl_match with _ and match_guard #118

Closed blindFS closed 1 week ago

blindFS commented 1 week ago

New test case of "match" with _ and if condition:

match $x {
   _ if $x == 4 => {},
   _ => {}
}

It will previously cause parsing error:

(nu_script ; [0, 0] - [4, 0]
  (ERROR ; [0, 0] - [3, 1]
    (val_variable ; [0, 6] - [0, 8]
      name: (identifier)) ; [0, 7] - [0, 8]
    (val_variable ; [1, 7] - [1, 9]
      name: (identifier)) ; [1, 8] - [1, 9]
    (val_number) ; [1, 13] - [1, 14]
    (ERROR) ; [1, 15] - [1, 16]
    (expr_binary ; [1, 18] - [2, 9]
      lhs: (val_record) ; [1, 18] - [1, 20]
      (ERROR) ; [2, 2] - [2, 5]
      rhs: (val_record)))) ; [2, 7] - [2, 9]
fdncred commented 1 week ago

Good catch. Thanks!