tree-sitter-c icon indicating copy to clipboard operation
tree-sitter-c copied to clipboard

Add else_clause

Open antoinemadec opened this issue 1 year ago • 1 comments

This would fix problems like this: https://github.com/nvim-treesitter/nvim-treesitter-context/issues/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])))))))))

antoinemadec avatar Sep 19 '22 09:09 antoinemadec

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

aryx avatar Sep 19 '22 10:09 aryx