nvim-treesitter/queries/cairo/highlights.scm
Christian Clason 1ae9b0e455 feat!: align standard captures with upstream
Problem: Sharing highlight queries with upstream tree-sitter and
Helix is difficult.

Solution: Where reasonable, use capture names in tree-sitter's standard
list or Helix's Atom-style hierarchy.

Specifically:

* tree-sitter "standard capture names"
  (3f44b89685/highlight/src/lib.rs (L20-L72)):

  - `@parameter` -> `@variable.parameter`
  - `@field` -> `@variable.member`
  - `@namespace` -> `@module`
  - `@float` -> `@number.float`
  - `@symbol` -> `@string.special.symbol`
  - `@string.regex` -> `@string.regexp`
  - `@text.*` -> `@markup.*` (`strong`, `italic`, `link`, `strikethrough`; with exceptions; see below)
  - `@text.title` -> `@markup.heading`
  - `@text.literal` -> `@markup.raw`
  - `@text.reference` -> `@markup.link`
  - `@text.uri` -> `@markup.link.url` (in markup links)
  - `@string.special` -> `@markup.link.label` (non-url links)
  - `@punctuation.special` -> `@markup.list` (markdown lists only; move subitems from `@text.todo`)

* Helix captures
  (https://docs.helix-editor.com/master/themes.html#syntax-highlighting):

  - `@method` -> `@function.method`
  - `@method.call` -> `@function.method.call`
  - `@text.{todo,warning,note,danger}` -> `@comment.{error,warning,hint,info,todo}`
  - `@text.diff.{add,delete,}` -> `@diff.{plus,minus,delta}`
  - `@text.uri` -> `@string.special.url` (outside markup)
  - `@preproc` -> `@keyword.directive`
  - `@define` -> `@keyword.directive`(`.define`?)
  - `@storageclass` -> `@keyword.storage`
  - `@conditional` -> `@keyword.conditional`
  - `@debug` -> `@keyword.debug`
  - `@exception` -> `@keyword.exception`
  - `@include` -> `@keyword.import`
  - `@repeat` -> `@keyword.repeat`

* cleanup

  - remove some redundant `@conceal` (but still allow it for conceal-only patterns)
  - remove obsolete `@error` (syntax linting is out of scope for this repo)
  - sort, cleanup capture list in `CONTRIBUTING.md`
2024-01-19 16:58:37 +01:00

334 lines
5.3 KiB
Scheme

; Preproc
[
"%builtins"
"%lang"
] @keyword.directive
; Includes
(import_statement [ "from" "import" ] @keyword.import module_name: (dotted_name (identifier) @module . ))
[
"as"
"use"
"mod"
] @keyword.import
; Variables
(identifier) @variable
; Namespaces
(namespace_definition (identifier) @module)
(mod_item
name: (identifier) @module)
(use_list (self) @module)
(scoped_use_list (self) @module)
(scoped_identifier
path: (identifier) @module)
(scoped_identifier
(scoped_identifier
name: (identifier) @module))
(scoped_type_identifier
path: (identifier) @module)
((scoped_identifier
path: (identifier) @type)
(#lua-match? @type "^[A-Z]"))
((scoped_identifier
name: (identifier) @type)
(#lua-match? @type "^[A-Z]"))
((scoped_identifier
name: (identifier) @constant)
(#lua-match? @constant "^[A-Z][A-Z%d_]*$"))
((scoped_identifier
path: (identifier) @type
name: (identifier) @constant)
(#lua-match? @type "^[A-Z]")
(#lua-match? @constant "^[A-Z]"))
((scoped_type_identifier
path: (identifier) @type
name: (type_identifier) @constant)
(#lua-match? @type "^[A-Z]")
(#lua-match? @constant "^[A-Z]"))
(scoped_use_list
path: (identifier) @module)
(scoped_use_list
path: (scoped_identifier
(identifier) @module))
(use_list (scoped_identifier (identifier) @module . (_)))
(use_list (identifier) @type (#lua-match? @type "^[A-Z]"))
(use_as_clause alias: (identifier) @type (#lua-match? @type "^[A-Z]"))
; Keywords
[
; 0.x
"using"
"namespace"
"struct"
"let"
"const"
"local"
"rel"
"abs"
"dw"
"alloc_locals"
(inst_ret)
"with_attr"
"with"
"call"
"nondet"
; 1.0
"type"
"impl"
"implicits"
"of"
"ref"
"mut"
"trait"
"enum"
] @keyword
[
"func"
"fn"
"end"
] @keyword.function
"return" @keyword.return
[
"cast"
"new"
"and"
] @keyword.operator
[
"tempvar"
"extern"
] @keyword.storage
[
"if"
"else"
"match"
] @keyword.conditional
[
"loop"
] @keyword.repeat
[
"assert"
"static_assert"
"nopanic"
] @keyword.exception
; Fields
(implicit_arguments (typed_identifier (identifier) @variable.member))
(member_expression "." (identifier) @variable.member)
(call_expression (assignment_expression left: (identifier) @variable.member))
(tuple_expression (assignment_expression left: (identifier) @variable.member))
(field_identifier) @variable.member
(shorthand_field_initializer (identifier) @variable.member)
; Parameters
(arguments (typed_identifier (identifier) @variable.parameter))
(call_expression (tuple_expression (assignment_expression left: (identifier) @variable.parameter)))
(return_type (tuple_type (named_type . (identifier) @variable.parameter)))
(parameter (identifier) @variable.parameter)
; Builtins
(builtin_directive (identifier) @variable.builtin)
(lang_directive (identifier) @variable.builtin)
[
"ap"
"fp"
(self)
] @variable.builtin
; Functions
(function_definition "func" (identifier) @function)
(function_definition "fn" (identifier) @function)
(function_signature "fn" (identifier) @function)
(extern_function_statement (identifier) @function)
(call_expression
function: (identifier) @function.call)
(call_expression
function: (scoped_identifier
(identifier) @function.call .))
(call_expression
function: (field_expression
field: (field_identifier) @function.call))
[
"jmp"
] @function.builtin
; Types
(struct_definition . (identifier) @type (typed_identifier (identifier) @variable.member)?)
(named_type (identifier) @type .)
[
(builtin_type)
(primitive_type)
] @type.builtin
((identifier) @type
(#lua-match? @type "^[A-Z][a-zA-Z0-9_]*$"))
(type_identifier) @type
; Constants
((identifier) @constant
(#lua-match? @constant "^[A-Z_][A-Z0-9_]*$"))
(enum_variant
name: (identifier) @constant)
(call_expression
function: (scoped_identifier
"::"
name: (identifier) @constant)
(#lua-match? @constant "^[A-Z]"))
((match_arm
pattern: (match_pattern (identifier) @constant))
(#lua-match? @constant "^[A-Z]"))
((match_arm
pattern: (match_pattern
(scoped_identifier
name: (identifier) @constant)))
(#lua-match? @constant "^[A-Z]"))
((identifier) @constant.builtin
(#any-of? @constant.builtin "Some" "None" "Ok" "Err"))
; Constructors
(unary_expression "new" (call_expression . (identifier) @constructor))
((call_expression . (identifier) @constructor)
(#lua-match? @constructor "^%u"))
; Attributes
(decorator "@" @attribute (identifier) @attribute)
(attribute_item (identifier) @function.macro)
(attribute_item (scoped_identifier (identifier) @function.macro .))
; Labels
(label . (identifier) @label)
(inst_jmp_to_label "jmp" . (identifier) @label)
(inst_jnz_to_label "jmp" . (identifier) @label)
; Operators
[
"+"
"-"
"*"
"/"
"**"
"=="
"!="
"&"
"="
"++"
"+="
"@"
"!"
"~"
".."
"&&"
"||"
"^"
"<"
"<="
">"
">="
"<<"
">>"
"%"
"-="
"*="
"/="
"%="
"&="
"|="
"^="
"<<="
">>="
"?"
] @operator
; Literals
(number) @number
(boolean) @boolean
[
(string)
(short_string)
] @string
; Punctuation
(attribute_item "#" @punctuation.special)
[ "." "," ":" ";" "->" "=>" "::" ] @punctuation.delimiter
[ "{" "}" "(" ")" "[" "]" "%{" "%}" ] @punctuation.bracket
(type_parameters [ "<" ">" ] @punctuation.bracket)
(type_arguments [ "<" ">" ] @punctuation.bracket)
; Comment
(comment) @comment @spell