tree-sitter / tree-sitter-c

C grammar for tree-sitter
MIT License
225 stars 100 forks source link

feature: C23 auto keyword #220

Closed duarm closed 3 weeks ago

duarm commented 4 weeks ago

Did you check the tree-sitter docs?

Is your feature request related to a problem? Please describe.

the new c23 auto keyword is highlighted as a keyword.modifier, as opposed to type

image

amaanq commented 3 weeks ago

highlighting is handled with your downstream application, not here. this is just the parser repo

duarm commented 3 weeks ago

I've opened an issue in the neovim repo https://github.com/tree-sitter/tree-sitter-c/issues/220 and they sent me back here because there are ERROR nodes, so the problem is in the parser. snippet


struct ui {
  int a;
};

struct ui *ui_get_root_info() { return &(struct ui){}; }

int main() {
  auto root = ui_get_root_info();
}
(translation_unit ; [0, 0] - [11, 0]
  (struct_specifier ; [0, 0] - [2, 1]
    name: (type_identifier) ; [0, 7] - [0, 9]
    body: (field_declaration_list ; [0, 10] - [2, 1]
      (field_declaration ; [1, 2] - [1, 8]
        type: (primitive_type) ; [1, 2] - [1, 5]
        declarator: (field_identifier)))) ; [1, 6] - [1, 7]
  (function_definition ; [4, 0] - [4, 56]
    type: (struct_specifier ; [4, 0] - [4, 9]
      name: (type_identifier)) ; [4, 7] - [4, 9]
    declarator: (pointer_declarator ; [4, 10] - [4, 29]
      declarator: (function_declarator ; [4, 11] - [4, 29]
        declarator: (identifier) ; [4, 11] - [4, 27]
        parameters: (parameter_list))) ; [4, 27] - [4, 29]
    body: (compound_statement ; [4, 30] - [4, 56]
      (return_statement ; [4, 32] - [4, 54]
        (pointer_expression ; [4, 39] - [4, 53]
          argument: (compound_literal_expression ; [4, 40] - [4, 53]
            type: (type_descriptor ; [4, 41] - [4, 50]
              type: (struct_specifier ; [4, 41] - [4, 50]
                name: (type_identifier))) ; [4, 48] - [4, 50]
            value: (initializer_list)))))) ; [4, 51] - [4, 53]
  (function_definition ; [6, 0] - [10, 1]
    type: (primitive_type) ; [6, 0] - [6, 3]
    declarator: (function_declarator ; [6, 4] - [6, 10]
      declarator: (identifier) ; [6, 4] - [6, 8]
      parameters: (parameter_list)) ; [6, 8] - [6, 10]
    body: (compound_statement ; [6, 11] - [10, 1]
      (declaration ; [7, 2] - [7, 30]
        (storage_class_specifier) ; [7, 2] - [7, 8]
        type: (primitive_type) ; [7, 9] - [7, 12]
        declarator: (init_declarator ; [7, 13] - [7, 29]
          declarator: (identifier) ; [7, 13] - [7, 25]
          value: (number_literal))) ; [7, 28] - [7, 29]
      (declaration ; [9, 2] - [9, 33]
        (storage_class_specifier) ; [9, 2] - [9, 6]
        type: (type_identifier) ; [9, 7] - [9, 11]
        (ERROR) ; [9, 12] - [9, 13]
        declarator: (function_declarator ; [9, 14] - [9, 32]
          declarator: (identifier) ; [9, 14] - [9, 30]
          parameters: (parameter_list)))))) ; [9, 30] - [9, 32]