(rx (| "/**" "/*!" "//!" "///"))
"A regexp that matches all doxygen comment styles.")
-(defun c-ts-mode--test-virtual-named-p ()
- "Return t if the virtual keyword is a namded node, nil otherwise."
- (ignore-errors
- (progn (treesit-query-compile 'cpp "(virtual)" t) t)))
-
(defun c-ts-mode--font-lock-settings (mode)
"Tree-sitter font-lock settings.
MODE is either `c' or `cpp'."
(treesit-font-lock-rules
- :language mode
+ :default-language mode
:feature 'comment
`(((comment) @font-lock-doc-face
(:match ,(rx bos "/**") @font-lock-doc-face))
(comment) @font-lock-comment-face)
- :language mode
:feature 'preprocessor
`((preproc_directive) @font-lock-preprocessor-face
")" @font-lock-preprocessor-face)
[,@c-ts-mode--preproc-keywords] @font-lock-preprocessor-face)
- :language mode
:feature 'constant
`((true) @font-lock-constant-face
(false) @font-lock-constant-face
(null) @font-lock-constant-face)
- :language mode
:feature 'keyword
`([,@(c-ts-mode--keywords mode)] @font-lock-keyword-face
,@(when (eq mode 'cpp)
'((auto) @font-lock-keyword-face
(this) @font-lock-keyword-face))
- ,@(when (and (eq mode 'cpp)
- (c-ts-mode--test-virtual-named-p))
- '((virtual) @font-lock-keyword-face))
- ,@(when (and (eq mode 'cpp)
- (not (c-ts-mode--test-virtual-named-p)))
- '("virtual" @font-lock-keyword-face)))
-
- :language mode
+ ,@(when (eq mode 'cpp)
+ (treesit-query-first-valid 'cpp
+ '((virtual) @font-lock-keyword-face)
+ '("virtual" @font-lock-keyword-face))))
+
:feature 'operator
`([,@c-ts-mode--operators
,@(when (eq mode 'cpp) c-ts-mode--c++-operators)]
@font-lock-operator-face
"!" @font-lock-negation-char-face)
- :language mode
:feature 'string
`((string_literal) @font-lock-string-face
(system_lib_string) @font-lock-string-face
,@(when (eq mode 'cpp)
'((raw_string_literal) @font-lock-string-face)))
- :language mode
:feature 'literal
`((number_literal) @font-lock-number-face
(char_literal) @font-lock-constant-face)
- :language mode
:feature 'type
`((primitive_type) @font-lock-type-face
(type_identifier) @font-lock-type-face
(namespace_identifier) @font-lock-constant-face))
[,@c-ts-mode--type-keywords] @font-lock-type-face)
- :language mode
:feature 'definition
;; Highlights identifiers in declarations.
`(,@(when (eq mode 'cpp)
(enumerator
name: (identifier) @font-lock-property-name-face))
- :language mode
:feature 'assignment
;; TODO: Recursively highlight identifiers in parenthesized
;; expressions, see `c-ts-mode--fontify-declarator' for
(identifier) @font-lock-variable-name-face))
(init_declarator declarator: (_) @c-ts-mode--fontify-declarator))
- :language mode
:feature 'function
'((call_expression
function:
[(identifier) @font-lock-function-call-face
(field_expression field: (field_identifier) @font-lock-function-call-face)]))
- :language mode
:feature 'variable
'((identifier) @c-ts-mode--fontify-variable)
- :language mode
:feature 'label
'((labeled_statement
label: (statement_identifier) @font-lock-constant-face))
- :language mode
:feature 'error
'((ERROR) @c-ts-mode--fontify-error)
:feature 'escape-sequence
- :language mode
:override t
'((escape_sequence) @font-lock-escape-face)
- :language mode
:feature 'property
'((field_identifier) @font-lock-property-use-face)
- :language mode
:feature 'bracket
'((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face)
- :language mode
:feature 'delimiter
'((["," ":" ";"]) @font-lock-delimiter-face)
- :language mode
:feature 'emacs-devel
:override t
`(((call_expression