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

Add else_clause #115

Merged
merged 1 commit into from
Jul 17, 2023
Merged

Add else_clause #115

merged 1 commit into from
Jul 17, 2023

Conversation

antoinemadec
Copy link
Contributor

This would fix problems like this: nvim-treesitter/nvim-treesitter-context#72

For info, this else_clause already exists in treesitter's JS, Python and Rust parser (did not check other languages).

E.g.:

if (true) {
  foo();
} else if (true) {
  bar();
} else {
  foobar();
}

Old parse was:

(translation_unit [0, 0] - [7, 0]
  (if_statement [0, 0] - [6, 1]
    condition: (parenthesized_expression [0, 3] - [0, 9]
      (true [0, 4] - [0, 8]))
    consequence: (compound_statement [0, 10] - [2, 1]
      (expression_statement [1, 2] - [1, 8]
        (call_expression [1, 2] - [1, 7]
          function: (identifier [1, 2] - [1, 5])
          arguments: (argument_list [1, 5] - [1, 7]))))
    alternative: (if_statement [2, 7] - [6, 1]
      condition: (parenthesized_expression [2, 10] - [2, 16]
        (true [2, 11] - [2, 15]))
      consequence: (compound_statement [2, 17] - [4, 1]
        (expression_statement [3, 2] - [3, 8]
          (call_expression [3, 2] - [3, 7]
            function: (identifier [3, 2] - [3, 5])
            arguments: (argument_list [3, 5] - [3, 7]))))
      alternative: (compound_statement [4, 7] - [6, 1]
        (expression_statement [5, 2] - [5, 11]
          (call_expression [5, 2] - [5, 10]
            function: (identifier [5, 2] - [5, 8])
            arguments: (argument_list [5, 8] - [5, 10])))))))

New parse is:

(translation_unit [0, 0] - [7, 0]
  (if_statement [0, 0] - [6, 1]
    condition: (parenthesized_expression [0, 3] - [0, 9]
      (true [0, 4] - [0, 8]))
    consequence: (compound_statement [0, 10] - [2, 1]
      (expression_statement [1, 2] - [1, 8]
        (call_expression [1, 2] - [1, 7]
          function: (identifier [1, 2] - [1, 5])
          arguments: (argument_list [1, 5] - [1, 7]))))
    alternative: (else_clause [2, 2] - [6, 1]
      (if_statement [2, 7] - [6, 1]
        condition: (parenthesized_expression [2, 10] - [2, 16]
          (true [2, 11] - [2, 15]))
        consequence: (compound_statement [2, 17] - [4, 1]
          (expression_statement [3, 2] - [3, 8]
            (call_expression [3, 2] - [3, 7]
              function: (identifier [3, 2] - [3, 5])
              arguments: (argument_list [3, 5] - [3, 7]))))
        alternative: (else_clause [4, 2] - [6, 1]
          (compound_statement [4, 7] - [6, 1]
            (expression_statement [5, 2] - [5, 11]
              (call_expression [5, 2] - [5, 10]
                function: (identifier [5, 2] - [5, 8])
                arguments: (argument_list [5, 8] - [5, 10])))))))))

@aryx aryx requested a review from jdrouhard September 19, 2022 10:13
@aryx
Copy link
Contributor

aryx commented Sep 19, 2022

@jdrouhard any idea what is this appveyor thing? Why this tree-sitter repo uses a different kind of CI?

@XVilka
Copy link
Contributor

XVilka commented Feb 28, 2023

Any updates on this?

@amaanq
Copy link
Member

amaanq commented Jul 10, 2023

@antoinemadec this would be good imo, but can you rebase?

@antoinemadec
Copy link
Contributor Author

antoinemadec commented Jan 6, 2024

@amaanq sorry about the slow response, thanks a lot for rebasing and merging this ❤️

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.

4 participants