mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-11 11:15:24 +03:00
[language-c] Apply some fixes to C/C++ highlighting
Choosing the other side of some dilemmas I had to resolve six months ago. Highlighting between modern and legacy Tree-sitters now appears to be identical to me (with rare exception) on the One Dark theme.
This commit is contained in:
parent
f171f33844
commit
937cb15953
@ -13,6 +13,10 @@
|
||||
"#define" @keyword.control.directive.define.c
|
||||
"#include" @keyword.control.directive.include.c
|
||||
|
||||
(["#if" "#ifdef" "#ifndef" "#endif" "#elif" "#else" "#define" "#include"] @punctuation.definition.directive.c
|
||||
(#set! adjust.endAfterFirstMatchOf "^#"))
|
||||
|
||||
|
||||
; This will match if the more specific rules above haven't matched. The
|
||||
; anonymous nodes will match under ideal conditions, but might not be present
|
||||
; if the parser is flummoxed.
|
||||
@ -116,32 +120,45 @@
|
||||
; Declarations and assignments
|
||||
; ----------------------------
|
||||
|
||||
; The "x" in `int x`;
|
||||
; The "x" in `int x;`
|
||||
(declaration
|
||||
declarator: (identifier) @variable.declaration.c)
|
||||
|
||||
; The "x" in `int x = y`;
|
||||
; The "x" in `int x = y;`
|
||||
(init_declarator
|
||||
declarator: (identifier) @variable.declaration.c)
|
||||
|
||||
; The "x" in `SomeType *x;`
|
||||
(declaration
|
||||
declarator: (pointer_declarator
|
||||
declarator: (identifier) @variable.declaration.pointer.c))
|
||||
|
||||
; A member of a struct.
|
||||
(field_declaration
|
||||
(field_identifier) @entity.other.attribute-name.c)
|
||||
(field_identifier) @variable.declaration.member.c)
|
||||
|
||||
(field_declaration
|
||||
(pointer_declarator
|
||||
(field_identifier) @entity.other.attribute-name.c))
|
||||
(field_identifier) @variable.declaration.member.c))
|
||||
|
||||
(field_declaration
|
||||
(array_declarator
|
||||
(field_identifier) @entity.other.attribute-name.c))
|
||||
(field_identifier) @variable.declaration.member.c))
|
||||
|
||||
(init_declarator
|
||||
(pointer_declarator
|
||||
(identifier) @entity.other.attribute-name.c))
|
||||
(identifier) @variable.declaration.member.c))
|
||||
|
||||
; The "x" in `x = y;`
|
||||
(assignment_expression
|
||||
left: (identifier) @variable.other.assignment.c)
|
||||
|
||||
; The "foo" in `something->foo = "bar";`
|
||||
(assignment_expression
|
||||
left: (field_expression
|
||||
field: (field_identifier) @variable.other.member.assignment.c)
|
||||
(#set! capture.final))
|
||||
|
||||
|
||||
; Function parameters
|
||||
; -------------------
|
||||
@ -172,7 +189,7 @@
|
||||
; The "size" in `finfo->size`.
|
||||
(field_expression
|
||||
"->"
|
||||
field: (field_identifier) @support.other.property.c)
|
||||
field: (field_identifier) @variable.other.member.c)
|
||||
|
||||
|
||||
; FUNCTIONS
|
||||
@ -309,8 +326,10 @@
|
||||
|
||||
";" @punctuation.terminator.statement.c
|
||||
|
||||
"," @punctuation.separator.comma.c
|
||||
"->" @punctuation.separator.pointer-access.c
|
||||
("," @punctuation.separator.comma.c
|
||||
(#set! capture.shy))
|
||||
("->" @keyword.operator.accessor.pointer-access.c
|
||||
(#set! capture.shy))
|
||||
|
||||
(parameter_list
|
||||
"(" @punctuation.definition.parameters.begin.bracket.round.c
|
||||
@ -335,6 +354,22 @@
|
||||
"[" @punctuation.definition.array.begin.bracket.square.c
|
||||
"]" @punctuation.definition.array.end.bracket.square.c
|
||||
|
||||
|
||||
; META
|
||||
; ====
|
||||
|
||||
((compound_statement) @meta.block.c
|
||||
(#set! adjust.startAt firstChild.endPosition)
|
||||
(#set! adjust.endAt lastChild.startPosition))
|
||||
|
||||
((enumerator_list) @meta.block.enum.c
|
||||
(#set! adjust.startAt firstChild.endPosition)
|
||||
(#set! adjust.endAt lastChild.startPosition))
|
||||
|
||||
((field_declaration_list) @meta.block.field.c
|
||||
(#set! adjust.startAt firstChild.endPosition)
|
||||
(#set! adjust.endAt lastChild.startPosition))
|
||||
|
||||
; TODO:
|
||||
;
|
||||
; * TM-style grammar has a lot of `mac-classic` scopes. I doubt they'd be
|
||||
|
@ -13,6 +13,10 @@
|
||||
"#define" @keyword.control.directive.define.cpp
|
||||
"#include" @keyword.control.directive.include.cpp
|
||||
|
||||
(["#if" "#ifdef" "#ifndef" "#endif" "#elif" "#else" "#define" "#include"] @punctuation.definition.directive.c
|
||||
(#set! adjust.endAfterFirstMatchOf "^#"))
|
||||
|
||||
|
||||
; This will match if the more specific rules above haven't matched. The
|
||||
; anonymous nodes will match under ideal conditions, but might not be present
|
||||
; if the parser is flummoxed.
|
||||
@ -207,36 +211,43 @@
|
||||
; Declarations and assignments
|
||||
; ----------------------------
|
||||
|
||||
; The "x" in `int x`;
|
||||
; The "x" in `int x;`
|
||||
(declaration
|
||||
declarator: (identifier) @variable.declaration.cpp)
|
||||
|
||||
; The "x" in `int x = y`;
|
||||
; The "x" in `int x = y;`
|
||||
(init_declarator
|
||||
declarator: (identifier) @variable.declaration.cpp)
|
||||
|
||||
; The "x" in `SomeType *x;`
|
||||
(declaration
|
||||
declarator: (pointer_declarator
|
||||
declarator: (identifier) @variable.declaration.pointer.c))
|
||||
|
||||
(field_declaration
|
||||
(field_identifier) @variable.declaration.cpp)
|
||||
(field_identifier) @variable.declaration.member.cpp)
|
||||
|
||||
(field_declaration
|
||||
(pointer_declarator
|
||||
(field_identifier) @variable.declaration.cpp))
|
||||
(field_identifier) @variable.declaration.member.cpp))
|
||||
|
||||
(field_declaration
|
||||
(array_declarator
|
||||
(field_identifier) @variable.declaration.cpp))
|
||||
(field_identifier) @variable.declaration.member.cpp))
|
||||
|
||||
(init_declarator
|
||||
(pointer_declarator
|
||||
(identifier) @variable.declaration.cpp))
|
||||
(identifier) @variable.declaration.member.cpp))
|
||||
|
||||
; The "x" in `x = y;`
|
||||
(assignment_expression
|
||||
left: (identifier) @variable.other.assignment.cpp)
|
||||
|
||||
; The "foo" in `bar.foo = "baz"`.
|
||||
; The "foo" in `something->foo = "bar";`
|
||||
(assignment_expression
|
||||
left: (field_expression
|
||||
field: (field_identifier) @variable.other.member.assignment.cpp))
|
||||
field: (field_identifier) @variable.other.member.assignment.cpp)
|
||||
(#set! capture.final))
|
||||
|
||||
((reference_declarator
|
||||
(identifier) @variable.declaration.cpp)
|
||||
@ -420,8 +431,10 @@
|
||||
|
||||
";" @punctuation.terminator.statement.cpp
|
||||
|
||||
"," @punctuation.separator.comma.cpp
|
||||
"->" @keyword.operator.accessor.cpp
|
||||
("," @punctuation.separator.comma.cpp
|
||||
(#set! capture.shy))
|
||||
("->" @keyword.operator.accessor.pointer-access.cpp
|
||||
(#set! capture.shy))
|
||||
|
||||
(parameter_list
|
||||
"(" @punctuation.definition.parameters.begin.bracket.round.cpp
|
||||
@ -446,6 +459,22 @@
|
||||
"[" @punctuation.definition.array.begin.bracket.square.cpp
|
||||
"]" @punctuation.definition.array.end.bracket.square.cpp
|
||||
|
||||
; META
|
||||
; ====
|
||||
|
||||
((compound_statement) @meta.block.cpp
|
||||
(#set! adjust.startAt firstChild.endPosition)
|
||||
(#set! adjust.endAt lastChild.startPosition))
|
||||
|
||||
((enumerator_list) @meta.block.enum.cpp
|
||||
(#set! adjust.startAt firstChild.endPosition)
|
||||
(#set! adjust.endAt lastChild.startPosition))
|
||||
|
||||
((field_declaration_list) @meta.block.field.cpp
|
||||
(#set! adjust.startAt firstChild.endPosition)
|
||||
(#set! adjust.endAt lastChild.startPosition))
|
||||
|
||||
|
||||
; TODO:
|
||||
;
|
||||
; * TM-style grammar has a lot of `mac-classic` scopes. I doubt they'd be
|
||||
|
Loading…
Reference in New Issue
Block a user