Skip to content

Commit

Permalink
[language-c] Support declarations of pointers-of-pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
savetheclocktower committed Jan 23, 2024
1 parent 6466d25 commit 995196a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
20 changes: 8 additions & 12 deletions packages/language-c/grammars/tree-sitter-c/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@
declarator: (identifier) @variable.declaration.c)

; The "x" in `SomeType *x;`
(declaration
declarator: (pointer_declarator
declarator: (identifier) @variable.declaration.pointer.c))
; (Should work no matter how many pointers deep we are.)
(pointer_declarator
declarator: [(identifier) (field_identifier)] @variable.declaration.pointer.c
(#is? test.descendantOfType "declaration field_declaration"))

; A member of a struct.
(field_declaration
Expand Down Expand Up @@ -193,15 +194,10 @@
declarator: (identifier) @variable.parameter.c)

; The "foo" in `const char *foo` within a parameter list.
(parameter_declaration
declarator: (pointer_declarator
declarator: (identifier) @variable.parameter.c))

; The "foo" in `SomeType **foo` within a parameter list.
(parameter_declaration
declarator: (pointer_declarator
declarator: (pointer_declarator
declarator: (identifier) @variable.parameter.c)))
; (Should work no matter how many pointers deep we are.)
(pointer_declarator
declarator: [(identifier) (field_identifier)] @variable.parameter.pointer.c
(#is? test.descendantOfType "parameter_declaration"))

; The "foo" in `const char foo[]` within a parameter list.
(parameter_declaration
Expand Down
20 changes: 8 additions & 12 deletions packages/language-c/grammars/tree-sitter-cpp/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,10 @@
declarator: (identifier) @variable.declaration.cpp)

; The "x" in `SomeType *x;`
(declaration
declarator: (pointer_declarator
declarator: (identifier) @variable.declaration.pointer.c))
; (Should work no matter how many pointers deep we are.)
(pointer_declarator
declarator: [(identifier) (field_identifier)] @variable.declaration.pointer.c
(#is? test.descendantOfType "declaration field_declaration"))

; A member of a struct.
(field_declaration
Expand Down Expand Up @@ -286,15 +287,10 @@
declarator: (identifier) @variable.parameter.cpp)

; The "foo" in `const char *foo` within a parameter list.
(parameter_declaration
declarator: (pointer_declarator
declarator: (identifier) @variable.parameter.cpp))

; The "foo" in `SomeType **foo` within a parameter list.
(parameter_declaration
declarator: (pointer_declarator
declarator: (pointer_declarator
declarator: (identifier) @variable.parameter.c)))
; (Should work no matter how many pointers deep we are.)
(pointer_declarator
declarator: [(identifier) (field_identifier)] @variable.parameter.pointer.c
(#is? test.descendantOfType "parameter_declaration"))

(parameter_declaration
declarator: (reference_declarator
Expand Down

0 comments on commit 995196a

Please sign in to comment.