Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of match pattern #79

Merged
merged 1 commit into from
Feb 2, 2024

Conversation

kit494way
Copy link
Contributor

Fix #60

This PR changes the syntax tree of list destrcture pattern.

Before this change, only [$x ..$y] is supported as list destrcture pattern.
However, there are various cases (e.g. [1 ..$x], [$x $y ..]).
To support other various cases, this PR changes the way of parsing list destrcture pattern.

Before this change, parsing list destrcture pattern generates different syntax tree from list pattern.
For example, when parsing match $xs {[$x ..$y] => {}}, (val_list) and (val_variable) nodes were not generated under (match_pattern) node before this change as follows.

(nu_script
  (pipeline
    (pipe_element
      (ctrl_match
        (val_variable
          (identifier))
        (match_arm
          (match_pattern
            (identifier) ; <-- (val_list) and (val_variable) are not generated
            (identifier))
          (block))))))

After this change, the parsing is done without distinguishing between list destrcture patten and list pattern.
(val_list) and (val_variable) nodes are also generated when parsing list destrcture pattern as follows.

(nu_script
  (pipeline
    (pipe_element
      (ctrl_match
        (val_variable
          (identifier))
        (match_arm
          (match_pattern
            (val_list
              (val_variable
                (identifier))
              (val_variable
                (identifier))))
          (block))))))

@fdncred
Copy link
Collaborator

fdncred commented Feb 2, 2024

wow! nice work, thanks!

@fdncred fdncred merged commit 358c4f5 into nushell:main Feb 2, 2024
3 checks passed
@kit494way kit494way deleted the fix-parsing-match-pattern branch February 3, 2024 06:00
mrdgo pushed a commit to mrdgo/tree-sitter-nu that referenced this pull request Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parsing of list destruction match pattern fails
2 participants