This commit is contained in:
2026-06-03 05:23:07 +02:00
commit a67da8c917
102 changed files with 9238 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
[
(for_statement)
(if_statement)
(while_statement)
(do_statement)
(switch_statement)
(case_statement)
(function_definition)
(struct_specifier)
(enum_specifier)
(comment)
(preproc_if)
(preproc_elif)
(preproc_else)
(preproc_ifdef)
(preproc_function_def)
(initializer_list)
(gnu_asm_expression)
(preproc_include)+
] @fold
(compound_statement
(compound_statement) @fold)
+341
View File
@@ -0,0 +1,341 @@
; Lower priority to prefer @variable.parameter when identifier appears in parameter_declaration.
((identifier) @variable
(#set! priority 95))
(preproc_def
(preproc_arg) @variable)
[
"default"
"goto"
"asm"
"__asm__"
] @keyword
[
"enum"
"struct"
"union"
"typedef"
] @keyword.type
[
"sizeof"
"offsetof"
] @keyword.operator
(alignof_expression
.
_ @keyword.operator)
"return" @keyword.return
[
"while"
"for"
"do"
"continue"
"break"
] @keyword.repeat
[
"if"
"else"
"case"
"switch"
] @keyword.conditional
[
"#if"
"#ifdef"
"#ifndef"
"#else"
"#elif"
"#endif"
"#elifdef"
"#elifndef"
(preproc_directive)
] @keyword.directive
"#define" @keyword.directive.define
"#include" @keyword.import
[
";"
":"
","
"."
"::"
] @punctuation.delimiter
"..." @punctuation.special
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
[
"="
"-"
"*"
"/"
"+"
"%"
"~"
"|"
"&"
"^"
"<<"
">>"
"->"
"<"
"<="
">="
">"
"=="
"!="
"!"
"&&"
"||"
"-="
"+="
"*="
"/="
"%="
"|="
"&="
"^="
">>="
"<<="
"--"
"++"
] @operator
; Make sure the comma operator is given a highlight group after the comma
; punctuator so the operator is highlighted properly.
(comma_expression
"," @operator)
[
(true)
(false)
] @boolean
(conditional_expression
[
"?"
":"
] @keyword.conditional.ternary)
(string_literal) @string
(system_lib_string) @string
(escape_sequence) @string.escape
(null) @constant.builtin
(number_literal) @number
(char_literal) @character
(preproc_defined) @function.macro
((field_expression
(field_identifier) @property) @_parent
(#not-has-parent? @_parent template_method function_declarator call_expression))
(field_designator) @property
((field_identifier) @property
(#has-ancestor? @property field_declaration)
(#not-has-ancestor? @property function_declarator))
(statement_identifier) @label
(declaration
type: (type_identifier) @_type
declarator: (identifier) @label
(#eq? @_type "__label__"))
[
(type_identifier)
(type_descriptor)
] @type
(storage_class_specifier) @keyword.modifier
[
(type_qualifier)
(gnu_asm_qualifier)
"__extension__"
] @keyword.modifier
(linkage_specification
"extern" @keyword.modifier)
(type_definition
declarator: (type_identifier) @type.definition)
(primitive_type) @type.builtin
(sized_type_specifier
_ @type.builtin
type: _?)
((identifier) @constant
(#lua-match? @constant "^[A-Z][A-Z0-9_]+$"))
(preproc_def
(preproc_arg) @constant
(#lua-match? @constant "^[A-Z][A-Z0-9_]+$"))
(enumerator
name: (identifier) @constant)
(case_statement
value: (identifier) @constant)
((identifier) @constant.builtin
; format-ignore
(#any-of? @constant.builtin
"stderr" "stdin" "stdout"
"__FILE__" "__LINE__" "__DATE__" "__TIME__"
"__STDC__" "__STDC_VERSION__" "__STDC_HOSTED__"
"__cplusplus" "__OBJC__" "__ASSEMBLER__"
"__BASE_FILE__" "__FILE_NAME__" "__INCLUDE_LEVEL__"
"__TIMESTAMP__" "__clang__" "__clang_major__"
"__clang_minor__" "__clang_patchlevel__"
"__clang_version__" "__clang_literal_encoding__"
"__clang_wide_literal_encoding__"
"__FUNCTION__" "__func__" "__PRETTY_FUNCTION__"
"__VA_ARGS__" "__VA_OPT__"))
(preproc_def
(preproc_arg) @constant.builtin
; format-ignore
(#any-of? @constant.builtin
"stderr" "stdin" "stdout"
"__FILE__" "__LINE__" "__DATE__" "__TIME__"
"__STDC__" "__STDC_VERSION__" "__STDC_HOSTED__"
"__cplusplus" "__OBJC__" "__ASSEMBLER__"
"__BASE_FILE__" "__FILE_NAME__" "__INCLUDE_LEVEL__"
"__TIMESTAMP__" "__clang__" "__clang_major__"
"__clang_minor__" "__clang_patchlevel__"
"__clang_version__" "__clang_literal_encoding__"
"__clang_wide_literal_encoding__"
"__FUNCTION__" "__func__" "__PRETTY_FUNCTION__"
"__VA_ARGS__" "__VA_OPT__"))
(attribute_specifier
(argument_list
(identifier) @variable.builtin))
(attribute_specifier
(argument_list
(call_expression
function: (identifier) @variable.builtin)))
((call_expression
function: (identifier) @function.builtin)
(#lua-match? @function.builtin "^__builtin_"))
((call_expression
function: (identifier) @function.builtin)
(#has-ancestor? @function.builtin attribute_specifier))
; Preproc def / undef
(preproc_def
name: (_) @constant.macro)
(preproc_call
directive: (preproc_directive) @_u
argument: (_) @constant.macro
(#eq? @_u "#undef"))
(preproc_ifdef
name: (identifier) @constant.macro)
(preproc_elifdef
name: (identifier) @constant.macro)
(preproc_defined
(identifier) @constant.macro)
(call_expression
function: (identifier) @function.call)
(call_expression
function: (field_expression
field: (field_identifier) @function.call))
(function_declarator
declarator: (identifier) @function)
(function_declarator
declarator: (parenthesized_declarator
(pointer_declarator
declarator: (field_identifier) @function)))
(preproc_function_def
name: (identifier) @function.macro)
(comment) @comment @spell
((comment) @comment.documentation
(#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$"))
; Parameters
(parameter_declaration
declarator: (identifier) @variable.parameter)
(parameter_declaration
declarator: (array_declarator) @variable.parameter)
(parameter_declaration
declarator: (pointer_declarator) @variable.parameter)
; K&R functions
; To enable support for K&R functions,
; add the following lines to your own query config and uncomment them.
; They are commented out as they'll conflict with C++
; Note that you'll need to have `; extends` at the top of your query file.
;
; (parameter_list (identifier) @variable.parameter)
;
; (function_definition
; declarator: _
; (declaration
; declarator: (identifier) @variable.parameter))
;
; (function_definition
; declarator: _
; (declaration
; declarator: (array_declarator) @variable.parameter))
;
; (function_definition
; declarator: _
; (declaration
; declarator: (pointer_declarator) @variable.parameter))
(preproc_params
(identifier) @variable.parameter)
[
"__attribute__"
"__declspec"
"__based"
"__cdecl"
"__clrcall"
"__stdcall"
"__fastcall"
"__thiscall"
"__vectorcall"
(ms_pointer_modifier)
(attribute_declaration)
] @attribute
+128
View File
@@ -0,0 +1,128 @@
((preproc_arg) @injection.content
(#set! injection.language "c"))
((comment) @injection.content
(#set! injection.language "comment"))
((comment) @injection.content
(#match? @injection.content "/\\*!([a-zA-Z]+:)?re2c")
(#set! injection.language "re2c"))
((comment) @injection.content
(#lua-match? @injection.content "/[*\/][!*\/]<?[^a-zA-Z]")
(#set! injection.language "doxygen"))
((call_expression
function: (identifier) @_function
arguments: (argument_list
.
[
(string_literal
(string_content) @injection.content)
(concatenated_string
(string_literal
(string_content) @injection.content))
]))
; format-ignore
(#any-of? @_function
"printf" "printf_s"
"vprintf" "vprintf_s"
"scanf" "scanf_s"
"vscanf" "vscanf_s"
"wprintf" "wprintf_s"
"vwprintf" "vwprintf_s"
"wscanf" "wscanf_s"
"vwscanf" "vwscanf_s"
"cscanf" "_cscanf"
"printw"
"scanw")
(#set! injection.language "printf"))
((call_expression
function: (identifier) @_function
arguments: (argument_list
(_)
.
[
(string_literal
(string_content) @injection.content)
(concatenated_string
(string_literal
(string_content) @injection.content))
]))
; format-ignore
(#any-of? @_function
"fprintf" "fprintf_s"
"sprintf"
"dprintf"
"fscanf" "fscanf_s"
"sscanf" "sscanf_s"
"vsscanf" "vsscanf_s"
"vfprintf" "vfprintf_s"
"vsprintf"
"vdprintf"
"fwprintf" "fwprintf_s"
"vfwprintf" "vfwprintf_s"
"fwscanf" "fwscanf_s"
"swscanf" "swscanf_s"
"vswscanf" "vswscanf_s"
"vfscanf" "vfscanf_s"
"vfwscanf" "vfwscanf_s"
"wprintw"
"vw_printw" "vwprintw"
"wscanw"
"vw_scanw" "vwscanw")
(#set! injection.language "printf"))
((call_expression
function: (identifier) @_function
arguments: (argument_list
(_)
.
(_)
.
[
(string_literal
(string_content) @injection.content)
(concatenated_string
(string_literal
(string_content) @injection.content))
]))
; format-ignore
(#any-of? @_function
"sprintf_s"
"snprintf" "snprintf_s"
"vsprintf_s"
"vsnprintf" "vsnprintf_s"
"swprintf" "swprintf_s"
"snwprintf_s"
"vswprintf" "vswprintf_s"
"vsnwprintf_s"
"mvprintw"
"mvscanw")
(#set! injection.language "printf"))
((call_expression
function: (identifier) @_function
arguments: (argument_list
(_)
.
(_)
.
(_)
.
[
(string_literal
(string_content) @injection.content)
(concatenated_string
(string_literal
(string_content) @injection.content))
]))
(#any-of? @_function "mvwprintw" "mvwscanw")
(#set! injection.language "printf"))
; TODO: add when asm is added
; (gnu_asm_expression assembly_code: (string_literal) @injection.content
; (#set! injection.language "asm"))
; (gnu_asm_expression assembly_code: (concatenated_string (string_literal) @injection.content)
; (#set! injection.language "asm"))
+67
View File
@@ -0,0 +1,67 @@
; Functions definitions
(function_declarator
declarator: (identifier) @local.definition.function)
(preproc_function_def
name: (identifier) @local.definition.macro) @local.scope
(preproc_def
name: (identifier) @local.definition.macro)
(pointer_declarator
declarator: (identifier) @local.definition.var)
(parameter_declaration
declarator: (identifier) @local.definition.parameter)
(init_declarator
declarator: (identifier) @local.definition.var)
(array_declarator
declarator: (identifier) @local.definition.var)
(declaration
declarator: (identifier) @local.definition.var)
(enum_specifier
name: (_) @local.definition.type
(enumerator_list
(enumerator
name: (identifier) @local.definition.var)))
; Type / Struct / Enum
(field_declaration
declarator: (field_identifier) @local.definition.field)
(type_definition
declarator: (type_identifier) @local.definition.type)
(struct_specifier
name: (type_identifier) @local.definition.type)
; goto
(labeled_statement
(statement_identifier) @local.definition)
; References
(identifier) @local.reference
((field_identifier) @local.reference
(#set! reference.kind "field"))
((type_identifier) @local.reference
(#set! reference.kind "type"))
(goto_statement
(statement_identifier) @local.reference)
; Scope
[
(for_statement)
(if_statement)
(while_statement)
(translation_unit)
(function_definition)
(compound_statement) ; a block in curly braces
(struct_specifier)
] @local.scope
+151
View File
@@ -0,0 +1,151 @@
(declaration
declarator: (function_declarator)) @function.outer
(function_definition
body: (compound_statement)) @function.outer
(function_definition
body: (compound_statement
.
"{"
_+ @function.inner
"}"))
(struct_specifier
body: (_) @class.inner) @class.outer
(enum_specifier
body: (_) @class.inner) @class.outer
; conditionals
(if_statement
consequence: (compound_statement
.
"{"
_+ @conditional.inner
"}")) @conditional.outer
(if_statement
alternative: (else_clause
(compound_statement
.
"{"
_+ @conditional.inner
"}"))) @conditional.outer
(if_statement) @conditional.outer
(if_statement
condition: (_) @conditional.inner
(#offset! @conditional.inner 0 1 0 -1))
(while_statement
condition: (_) @conditional.inner
(#offset! @conditional.inner 0 1 0 -1))
(do_statement
condition: (_) @conditional.inner
(#offset! @conditional.inner 0 1 0 -1))
(for_statement
condition: (_) @conditional.inner)
; loops
(while_statement) @loop.outer
(while_statement
body: (compound_statement
.
"{"
_+ @loop.inner
"}")) @loop.outer
(for_statement) @loop.outer
(for_statement
body: (compound_statement
.
"{"
_+ @loop.inner
"}")) @loop.outer
(do_statement) @loop.outer
(do_statement
body: (compound_statement
.
"{"
_+ @loop.inner
"}")) @loop.outer
(compound_statement) @block.outer
(comment) @comment.outer
(call_expression) @call.outer
(call_expression
arguments: (argument_list
.
"("
_+ @call.inner
")"))
(return_statement
(_)? @return.inner) @return.outer
; Statements
;(expression_statement ;; this is what we actually want to capture in most cases (";" is missing) probably
;(_) @statement.inner) ;; the other statement like node type is declaration but declaration has a ";"
(compound_statement
(_) @statement.outer)
(field_declaration_list
(_) @statement.outer)
(preproc_if
(_) @statement.outer)
(preproc_elif
(_) @statement.outer)
(preproc_else
(_) @statement.outer)
(parameter_list
"," @parameter.outer
.
(parameter_declaration) @parameter.inner @parameter.outer)
(parameter_list
.
(parameter_declaration) @parameter.inner @parameter.outer
.
","? @parameter.outer)
(argument_list
"," @parameter.outer
.
(_) @parameter.inner @parameter.outer)
(argument_list
.
(_) @parameter.inner @parameter.outer
.
","? @parameter.outer)
(number_literal) @number.inner
(declaration
declarator: (init_declarator
declarator: (_) @assignment.lhs
value: (_) @assignment.rhs) @assignment.inner) @assignment.outer
(declaration
type: (primitive_type)
declarator: (_) @assignment.inner)
(expression_statement
(assignment_expression
left: (_) @assignment.lhs
right: (_) @assignment.rhs) @assignment.inner) @assignment.outer
+24
View File
@@ -0,0 +1,24 @@
[
(arguments)
(for_in_statement)
(for_statement)
(while_statement)
(arrow_function)
(function_expression)
(function_declaration)
(class_declaration)
(method_definition)
(do_statement)
(with_statement)
(switch_statement)
(switch_case)
(switch_default)
(import_statement)+
(if_statement)
(try_statement)
(catch_clause)
(array)
(object)
(generator_function)
(generator_function_declaration)
] @fold
+392
View File
@@ -0,0 +1,392 @@
; Types
; Javascript
; Variables
;-----------
(identifier) @variable
; Properties
;-----------
(property_identifier) @variable.member
(shorthand_property_identifier) @variable.member
(private_property_identifier) @variable.member
(object_pattern
(shorthand_property_identifier_pattern) @variable)
(object_pattern
(object_assignment_pattern
(shorthand_property_identifier_pattern) @variable))
; Special identifiers
;--------------------
((identifier) @type
(#lua-match? @type "^[A-Z]"))
((identifier) @constant
(#lua-match? @constant "^_*[A-Z][A-Z%d_]*$"))
((shorthand_property_identifier) @constant
(#lua-match? @constant "^_*[A-Z][A-Z%d_]*$"))
((identifier) @variable.builtin
(#any-of? @variable.builtin "arguments" "module" "console" "window" "document"))
((identifier) @type.builtin
(#any-of? @type.builtin
"Object" "Function" "Boolean" "Symbol" "Number" "Math" "Date" "String" "RegExp" "Map" "Set"
"WeakMap" "WeakSet" "Promise" "Array" "Int8Array" "Uint8Array" "Uint8ClampedArray" "Int16Array"
"Uint16Array" "Int32Array" "Uint32Array" "Float32Array" "Float64Array" "ArrayBuffer" "DataView"
"Error" "EvalError" "InternalError" "RangeError" "ReferenceError" "SyntaxError" "TypeError"
"URIError"))
(statement_identifier) @label
; Function and method definitions
;--------------------------------
(function_expression
name: (identifier) @function)
(function_declaration
name: (identifier) @function)
(generator_function
name: (identifier) @function)
(generator_function_declaration
name: (identifier) @function)
(method_definition
name: [
(property_identifier)
(private_property_identifier)
] @function.method)
(method_definition
name: (property_identifier) @constructor
(#eq? @constructor "constructor"))
(pair
key: (property_identifier) @function.method
value: (function_expression))
(pair
key: (property_identifier) @function.method
value: (arrow_function))
(assignment_expression
left: (member_expression
property: (property_identifier) @function.method)
right: (arrow_function))
(assignment_expression
left: (member_expression
property: (property_identifier) @function.method)
right: (function_expression))
(variable_declarator
name: (identifier) @function
value: (arrow_function))
(variable_declarator
name: (identifier) @function
value: (function_expression))
(assignment_expression
left: (identifier) @function
right: (arrow_function))
(assignment_expression
left: (identifier) @function
right: (function_expression))
; Function and method calls
;--------------------------
(call_expression
function: (identifier) @function.call)
(call_expression
function: (member_expression
property: [
(property_identifier)
(private_property_identifier)
] @function.method.call))
(call_expression
function: (await_expression
(identifier) @function.call))
(call_expression
function: (await_expression
(member_expression
property: [
(property_identifier)
(private_property_identifier)
] @function.method.call)))
; Builtins
;---------
((identifier) @module.builtin
(#eq? @module.builtin "Intl"))
((identifier) @function.builtin
(#any-of? @function.builtin
"eval" "isFinite" "isNaN" "parseFloat" "parseInt" "decodeURI" "decodeURIComponent" "encodeURI"
"encodeURIComponent" "require"))
; Constructor
;------------
(new_expression
constructor: (identifier) @constructor)
; Decorators
;----------
(decorator
"@" @attribute
(identifier) @attribute)
(decorator
"@" @attribute
(call_expression
(identifier) @attribute))
(decorator
"@" @attribute
(member_expression
(property_identifier) @attribute))
(decorator
"@" @attribute
(call_expression
(member_expression
(property_identifier) @attribute)))
; Literals
;---------
[
(this)
(super)
] @variable.builtin
((identifier) @variable.builtin
(#eq? @variable.builtin "self"))
[
(true)
(false)
] @boolean
[
(null)
(undefined)
] @constant.builtin
[
(comment)
(html_comment)
] @comment @spell
((comment) @comment.documentation
(#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$"))
(hash_bang_line) @keyword.directive
((string_fragment) @keyword.directive
(#eq? @keyword.directive "use strict"))
(string) @string
(template_string) @string
(escape_sequence) @string.escape
(regex_pattern) @string.regexp
(regex_flags) @character.special
(regex
"/" @punctuation.bracket) ; Regex delimiters
(number) @number
((identifier) @number
(#any-of? @number "NaN" "Infinity"))
; Punctuation
;------------
[
";"
"."
","
":"
] @punctuation.delimiter
[
"--"
"-"
"-="
"&&"
"+"
"++"
"+="
"&="
"/="
"**="
"<<="
"<"
"<="
"<<"
"="
"=="
"==="
"!="
"!=="
"=>"
">"
">="
">>"
"||"
"%"
"%="
"*"
"**"
">>>"
"&"
"|"
"^"
"??"
"*="
">>="
">>>="
"^="
"|="
"&&="
"||="
"??="
"..."
] @operator
(binary_expression
"/" @operator)
(ternary_expression
[
"?"
":"
] @keyword.conditional.ternary)
(unary_expression
[
"!"
"~"
"-"
"+"
] @operator)
(unary_expression
[
"delete"
"void"
] @keyword.operator)
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
(template_substitution
[
"${"
"}"
] @punctuation.special) @none
; Imports
;----------
(namespace_import
"*" @character.special
(identifier) @module)
(namespace_export
"*" @character.special
(identifier) @module)
(export_statement
"*" @character.special)
; Keywords
;----------
[
"if"
"else"
"switch"
"case"
] @keyword.conditional
[
"import"
"from"
"as"
"export"
] @keyword.import
[
"for"
"of"
"do"
"while"
"continue"
] @keyword.repeat
[
"break"
"const"
"debugger"
"extends"
"get"
"let"
"set"
"static"
"target"
"var"
"with"
] @keyword
"class" @keyword.type
[
"async"
"await"
] @keyword.coroutine
[
"return"
"yield"
] @keyword.return
"function" @keyword.function
[
"new"
"delete"
"in"
"instanceof"
"typeof"
] @keyword.operator
[
"throw"
"try"
"catch"
"finally"
] @keyword.exception
(export_statement
"default" @keyword)
(switch_default
"default" @keyword.conditional)
+203
View File
@@ -0,0 +1,203 @@
(((comment) @_jsdoc_comment
(#lua-match? @_jsdoc_comment "^/[*][*][^*].*[*]/$")) @injection.content
(#set! injection.language "jsdoc"))
((comment) @injection.content
(#set! injection.language "comment"))
; html(`...`), html`...`, sql(`...`), etc.
(call_expression
function: (identifier) @injection.language
arguments: [
(arguments
(template_string) @injection.content)
(template_string) @injection.content
]
(#lua-match? @injection.language "^[a-zA-Z][a-zA-Z0-9]*$")
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children)
; Languages excluded from auto-injection due to special rules
; - svg uses the html parser
; - css uses the styled parser
(#not-any-of? @injection.language "svg" "css"))
; svg`...` or svg(`...`)
(call_expression
function: (identifier) @_name
(#eq? @_name "svg")
arguments: [
(arguments
(template_string) @injection.content)
(template_string) @injection.content
]
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children)
(#set! injection.language "html"))
; Vercel PostgreSQL
; foo.sql`...` or foo.sql(`...`)
(call_expression
function: (member_expression
property: (property_identifier) @injection.language)
arguments: [
(arguments
(template_string) @injection.content)
(template_string) @injection.content
]
(#eq? @injection.language "sql")
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children))
(call_expression
function: (identifier) @_name
(#eq? @_name "gql")
arguments: (template_string) @injection.content
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children)
(#set! injection.language "graphql"))
(call_expression
function: (identifier) @_name
(#eq? @_name "hbs")
arguments: (template_string) @injection.content
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children)
(#set! injection.language "glimmer"))
; css`<css>`, keyframes`<css>`
(call_expression
function: (identifier) @_name
(#any-of? @_name "css" "keyframes")
arguments: (template_string) @injection.content
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children)
(#set! injection.language "styled"))
; styled.div`<css>`
(call_expression
function: (member_expression
object: (identifier) @_name
(#eq? @_name "styled"))
arguments: ((template_string) @injection.content
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children)
(#set! injection.language "styled")))
; styled(Component)`<css>`
(call_expression
function: (call_expression
function: (identifier) @_name
(#eq? @_name "styled"))
arguments: ((template_string) @injection.content
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children)
(#set! injection.language "styled")))
; styled.div.attrs({ prop: "foo" })`<css>`
(call_expression
function: (call_expression
function: (member_expression
object: (member_expression
object: (identifier) @_name
(#eq? @_name "styled"))))
arguments: ((template_string) @injection.content
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children)
(#set! injection.language "styled")))
; styled(Component).attrs({ prop: "foo" })`<css>`
(call_expression
function: (call_expression
function: (member_expression
object: (call_expression
function: (identifier) @_name
(#eq? @_name "styled"))))
arguments: ((template_string) @injection.content
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children)
(#set! injection.language "styled")))
((regex_pattern) @injection.content
(#set! injection.language "regex"))
; ((comment) @_gql_comment
; (#eq? @_gql_comment "/* GraphQL */")
; (template_string) @injection.content
; (#set! injection.language "graphql"))
((template_string) @injection.content
(#lua-match? @injection.content "^`#graphql")
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children)
(#set! injection.language "graphql"))
; el.innerHTML = `<html>`
(assignment_expression
left: (member_expression
property: (property_identifier) @_prop
(#any-of? @_prop "outerHTML" "innerHTML"))
right: (template_string) @injection.content
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children)
(#set! injection.language "html"))
; el.innerHTML = '<html>'
(assignment_expression
left: (member_expression
property: (property_identifier) @_prop
(#any-of? @_prop "outerHTML" "innerHTML"))
right: (string
(string_fragment) @injection.content)
(#set! injection.language "html"))
;---- Angular injections -----
; @Component({
; template: `<html>`
; })
(decorator
(call_expression
function: ((identifier) @_name
(#eq? @_name "Component"))
arguments: (arguments
(object
(pair
key: ((property_identifier) @_prop
(#eq? @_prop "template"))
value: ((template_string) @injection.content
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children)
(#set! injection.language "angular")))))))
; @Component({
; styles: [`<css>`]
; })
(decorator
(call_expression
function: ((identifier) @_name
(#eq? @_name "Component"))
arguments: (arguments
(object
(pair
key: ((property_identifier) @_prop
(#eq? @_prop "styles"))
value: (array
((template_string) @injection.content
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children)
(#set! injection.language "css"))))))))
; @Component({
; styles: `<css>`
; })
(decorator
(call_expression
function: ((identifier) @_name
(#eq? @_name "Component"))
arguments: (arguments
(object
(pair
key: ((property_identifier) @_prop
(#eq? @_prop "styles"))
value: ((template_string) @injection.content
(#set! injection.include-children)
(#offset! @injection.content 0 1 0 -1)
(#set! injection.language "css")))))))
+42
View File
@@ -0,0 +1,42 @@
; Scopes
;-------
(statement_block) @local.scope
(function_expression) @local.scope
(arrow_function) @local.scope
(function_declaration) @local.scope
(method_definition) @local.scope
(for_statement) @local.scope
(for_in_statement) @local.scope
(catch_clause) @local.scope
; Definitions
;------------
(variable_declarator
name: (identifier) @local.definition.var)
(import_specifier
(identifier) @local.definition.import)
(namespace_import
(identifier) @local.definition.import)
(function_declaration
(identifier) @local.definition.function
(#set! definition.var.scope parent))
(method_definition
(property_identifier) @local.definition.function
(#set! definition.var.scope parent))
; References
;------------
(identifier) @local.reference
(shorthand_property_identifier) @local.reference
+372
View File
@@ -0,0 +1,372 @@
(function_declaration
body: (statement_block)) @function.outer
(generator_function_declaration
body: (statement_block)) @function.outer
(function_expression
body: (statement_block)) @function.outer
(function_declaration
body: (statement_block
.
"{"
_+ @function.inner
"}"))
(generator_function_declaration
body: (statement_block
.
"{"
_+ @function.inner
"}"))
(function_expression
body: (statement_block
.
"{"
_+ @function.inner
"}"))
(export_statement
(function_declaration)) @function.outer
(arrow_function
body: (_) @function.inner) @function.outer
(arrow_function
body: (statement_block
.
"{"
_+ @function.inner
"}"))
(method_definition
body: (statement_block)) @function.outer
(method_definition
body: (statement_block
.
"{"
_+ @function.inner
"}"))
(class_declaration
body: (class_body)) @class.outer
(class_declaration
body: (class_body
.
"{"
_+ @class.inner
"}"))
(export_statement
(class_declaration)) @class.outer
(for_in_statement
body: (statement_block
.
"{"
_+ @loop.inner
"}")) @loop.outer
(for_statement
body: (statement_block
.
"{"
_+ @loop.inner
"}")) @loop.outer
(while_statement
body: (statement_block
.
"{"
_+ @loop.inner
"}")) @loop.outer
(do_statement
body: (statement_block
.
"{"
_+ @loop.inner
"}")) @loop.outer
(if_statement
consequence: (statement_block
.
"{"
_+ @conditional.inner
"}")) @conditional.outer
(if_statement
alternative: (else_clause
(statement_block
.
"{"
_+ @conditional.inner
"}"))) @conditional.outer
(if_statement) @conditional.outer
(switch_statement
body: (_)? @conditional.inner) @conditional.outer
(call_expression) @call.outer
(call_expression
arguments: (arguments
.
"("
_+ @call.inner
")"))
(new_expression
constructor: (identifier) @call.outer
arguments: (arguments
.
"("
_+ @call.inner
")") @call.outer)
; blocks
(statement_block
(_)* @block.inner) @block.outer
; parameters
; function ({ x }) ...
; function ([ x ]) ...
; function (v = default_value)
(formal_parameters
"," @parameter.outer
.
(_) @parameter.inner @parameter.outer)
(formal_parameters
.
(_) @parameter.inner @parameter.outer
.
","? @parameter.outer)
; last element with trailing comma
(formal_parameters
(_) @parameter.outer
.
"," @parameter.outer .)
; If the array/object pattern is the first parameter, treat its elements as the argument list
(formal_parameters
.
(_
[
(object_pattern
"," @parameter.outer
.
(_) @parameter.inner @parameter.outer)
(array_pattern
"," @parameter.outer
.
(_) @parameter.inner @parameter.outer)
]))
(formal_parameters
.
(_
[
(object_pattern
.
(_) @parameter.inner @parameter.outer
.
","? @parameter.outer)
(array_pattern
.
(_) @parameter.inner @parameter.outer
.
","? @parameter.outer)
]))
; last element with trailing comma
(formal_parameters
.
(_
[
(object_pattern
(_) @parameter.outer
.
"," @parameter.outer .)
(array_pattern
(_) @parameter.outer
.
"," @parameter.outer .)
]))
; arguments
(arguments
"," @parameter.outer
.
(_) @parameter.inner @parameter.outer)
(arguments
.
(_) @parameter.inner @parameter.outer
.
","? @parameter.outer)
; last element with trailing comma
(arguments
(_) @parameter.outer
.
"," @parameter.outer .)
; comment
(comment) @comment.outer
; regex
(regex
(regex_pattern) @regex.inner) @regex.outer
; number
(number) @number.inner
(lexical_declaration
(variable_declarator
name: (_) @assignment.lhs
value: (_) @assignment.inner @assignment.rhs)) @assignment.outer
(variable_declarator
name: (_) @assignment.inner)
(object
(pair
key: (_) @assignment.lhs
value: (_) @assignment.inner @assignment.rhs) @assignment.outer)
(return_statement
(_) @return.inner) @return.outer
(return_statement) @statement.outer
[
(if_statement)
(expression_statement)
(for_statement)
(while_statement)
(do_statement)
(for_in_statement)
(export_statement)
(lexical_declaration)
] @statement.outer
; 1. default import
(import_statement
(import_clause
(identifier) @parameter.inner @parameter.outer))
; 2. namespace import e.g. `* as React`
(import_statement
(import_clause
(namespace_import
(identifier) @parameter.inner) @parameter.outer))
; 3. named import e.g. `import { Bar, Baz } from ...`
(import_statement
(import_clause
(named_imports
(import_specifier) @parameter.inner)))
; 3A. named import followed by a comma
(import_statement
(import_clause
(named_imports
(import_specifier) @parameter.outer
.
"," @parameter.outer)))
; 3B. comma followed by named import
(import_statement
(import_clause
(named_imports
"," @parameter.outer
.
(import_specifier) @parameter.outer)))
; 3-C. only one named import without a comma
(import_statement
(import_clause
(named_imports
.
(import_specifier) @parameter.outer .)))
; Treat list or object elements as @parameter
; 1. parameter.inner
(object
(_) @parameter.inner)
(array
(_) @parameter.inner)
(object_pattern
(_) @parameter.inner)
(array_pattern
(_) @parameter.inner)
; 2. parameter.outer: Only one element, no comma
(object
.
(_) @parameter.outer .)
(array
.
(_) @parameter.outer .)
(object_pattern
.
(_) @parameter.outer .)
(array_pattern
.
(_) @parameter.outer .)
; 3. parameter.outer: Comma before or after
[
(object
"," @parameter.outer
.
(_) @parameter.outer)
(array
"," @parameter.outer
.
(_) @parameter.outer)
(object_pattern
"," @parameter.outer
.
(_) @parameter.outer)
(array_pattern
"," @parameter.outer
.
(_) @parameter.outer)
]
[
(object
.
(_) @parameter.outer
.
"," @parameter.outer)
(array
.
(_) @parameter.outer
.
"," @parameter.outer)
(object_pattern
.
(_) @parameter.outer
.
"," @parameter.outer)
(array_pattern
.
(_) @parameter.outer
.
"," @parameter.outer)
]
+19
View File
@@ -0,0 +1,19 @@
[
(const_declaration)
(expression_switch_statement)
(expression_case)
(default_case)
(type_switch_statement)
(type_case)
(for_statement)
(func_literal)
(function_declaration)
(if_statement)
(import_declaration)
(method_declaration)
(type_declaration)
(var_declaration)
(composite_literal)
(literal_element)
(block)
] @fold
+254
View File
@@ -0,0 +1,254 @@
; Forked from tree-sitter-go
; Copyright (c) 2014 Max Brunsfeld (The MIT License)
;
; Identifiers
(type_identifier) @type
(type_spec
name: (type_identifier) @type.definition)
(field_identifier) @property
(identifier) @variable
(package_identifier) @module
(parameter_declaration
(identifier) @variable.parameter)
(variadic_parameter_declaration
(identifier) @variable.parameter)
(label_name) @label
(const_spec
name: (identifier) @constant)
; Function calls
(call_expression
function: (identifier) @function.call)
(call_expression
function: (selector_expression
field: (field_identifier) @function.method.call))
; Function definitions
(function_declaration
name: (identifier) @function)
(method_declaration
name: (field_identifier) @function.method)
(method_elem
name: (field_identifier) @function.method)
; Constructors
((call_expression
(identifier) @constructor)
(#lua-match? @constructor "^[nN]ew.+$"))
((call_expression
(identifier) @constructor)
(#lua-match? @constructor "^[mM]ake.+$"))
; Operators
[
"--"
"-"
"-="
":="
"!"
"!="
"..."
"*"
"*"
"*="
"/"
"/="
"&"
"&&"
"&="
"&^"
"&^="
"%"
"%="
"^"
"^="
"+"
"++"
"+="
"<-"
"<"
"<<"
"<<="
"<="
"="
"=="
">"
">="
">>"
">>="
"|"
"|="
"||"
"~"
] @operator
; Keywords
[
"break"
"const"
"continue"
"default"
"defer"
"goto"
"range"
"select"
"var"
"fallthrough"
] @keyword
[
"type"
"struct"
"interface"
] @keyword.type
"func" @keyword.function
"return" @keyword.return
"go" @keyword.coroutine
"for" @keyword.repeat
[
"import"
"package"
] @keyword.import
[
"else"
"case"
"switch"
"if"
] @keyword.conditional
; Builtin types
[
"chan"
"map"
] @type.builtin
((type_identifier) @type.builtin
(#any-of? @type.builtin
"any" "bool" "byte" "comparable" "complex128" "complex64" "error" "float32" "float64" "int"
"int16" "int32" "int64" "int8" "rune" "string" "uint" "uint16" "uint32" "uint64" "uint8"
"uintptr"))
; Builtin functions
((identifier) @function.builtin
(#any-of? @function.builtin
"append" "cap" "clear" "close" "complex" "copy" "delete" "imag" "len" "make" "max" "min" "new"
"panic" "print" "println" "real" "recover"))
; Delimiters
"." @punctuation.delimiter
"," @punctuation.delimiter
":" @punctuation.delimiter
";" @punctuation.delimiter
"(" @punctuation.bracket
")" @punctuation.bracket
"{" @punctuation.bracket
"}" @punctuation.bracket
"[" @punctuation.bracket
"]" @punctuation.bracket
; Literals
(interpreted_string_literal) @string
(raw_string_literal) @string
(rune_literal) @string
(escape_sequence) @string.escape
(int_literal) @number
(float_literal) @number.float
(imaginary_literal) @number
[
(true)
(false)
] @boolean
[
(nil)
(iota)
] @constant.builtin
(keyed_element
.
(literal_element
(identifier) @variable.member))
(field_declaration
name: (field_identifier) @variable.member)
; Comments
(comment) @comment @spell
; Doc Comments
(source_file
.
(comment)+ @comment.documentation)
(source_file
(comment)+ @comment.documentation
.
(const_declaration))
(source_file
(comment)+ @comment.documentation
.
(function_declaration))
(source_file
(comment)+ @comment.documentation
.
(type_declaration))
(source_file
(comment)+ @comment.documentation
.
(var_declaration))
; Spell
((interpreted_string_literal) @spell
(#not-has-parent? @spell import_spec))
; Regex
(call_expression
(selector_expression) @_function
(#any-of? @_function
"regexp.Match" "regexp.MatchReader" "regexp.MatchString" "regexp.Compile" "regexp.CompilePOSIX"
"regexp.MustCompile" "regexp.MustCompilePOSIX")
(argument_list
.
[
(raw_string_literal
(raw_string_literal_content) @string.regexp)
(interpreted_string_literal
(interpreted_string_literal_content) @string.regexp)
]))
+42
View File
@@ -0,0 +1,42 @@
((comment) @injection.content
(#set! injection.language "comment"))
(call_expression
(selector_expression) @_function
(#any-of? @_function
"regexp.Match" "regexp.MatchReader" "regexp.MatchString" "regexp.Compile" "regexp.CompilePOSIX"
"regexp.MustCompile" "regexp.MustCompilePOSIX")
(argument_list
.
[
(raw_string_literal
(raw_string_literal_content) @injection.content)
(interpreted_string_literal
(interpreted_string_literal_content) @injection.content)
]
(#set! injection.language "regex")))
((comment) @injection.content
(#match? @injection.content "/\\*!([a-zA-Z]+:)?re2c")
(#set! injection.language "re2c"))
((call_expression
function: (selector_expression
field: (field_identifier) @_method)
arguments: (argument_list
.
(interpreted_string_literal
(interpreted_string_literal_content) @injection.content)))
(#any-of? @_method "Printf" "Sprintf" "Fatalf" "Scanf" "Errorf" "Skipf" "Logf")
(#set! injection.language "printf"))
((call_expression
function: (selector_expression
field: (field_identifier) @_method)
arguments: (argument_list
(_)
.
(interpreted_string_literal
(interpreted_string_literal_content) @injection.content)))
(#any-of? @_method "Fprintf" "Fscanf" "Appendf" "Sscanf")
(#set! injection.language "printf"))
+88
View File
@@ -0,0 +1,88 @@
((function_declaration
name: (identifier) @local.definition.function) ; @function
)
((method_declaration
name: (field_identifier) @local.definition.method) ; @function.method
)
(short_var_declaration
left: (expression_list
(identifier) @local.definition.var))
(var_spec
name: (identifier) @local.definition.var)
(parameter_declaration
(identifier) @local.definition.var)
(variadic_parameter_declaration
(identifier) @local.definition.var)
(for_statement
(range_clause
left: (expression_list
(identifier) @local.definition.var)))
(const_declaration
(const_spec
name: (identifier) @local.definition.var))
(type_declaration
(type_spec
name: (type_identifier) @local.definition.type))
; reference
(identifier) @local.reference
(type_identifier) @local.reference
(field_identifier) @local.reference
((package_identifier) @local.reference
(#set! reference.kind "namespace"))
(package_clause
(package_identifier) @local.definition.namespace)
(import_spec_list
(import_spec
name: (package_identifier) @local.definition.namespace))
; Call references
((call_expression
function: (identifier) @local.reference)
(#set! reference.kind "call"))
((call_expression
function: (selector_expression
field: (field_identifier) @local.reference))
(#set! reference.kind "call"))
((call_expression
function: (parenthesized_expression
(identifier) @local.reference))
(#set! reference.kind "call"))
((call_expression
function: (parenthesized_expression
(selector_expression
field: (field_identifier) @local.reference)))
(#set! reference.kind "call"))
; Scopes
(func_literal) @local.scope
(source_file) @local.scope
(function_declaration) @local.scope
(if_statement) @local.scope
(block) @local.scope
(expression_switch_statement) @local.scope
(for_statement) @local.scope
(method_declaration) @local.scope
+153
View File
@@ -0,0 +1,153 @@
; inner function textobject
(function_declaration
body: (block
.
"{"
_+ @function.inner
"}"))
; inner function literals
(func_literal
body: (block
.
"{"
_+ @function.inner
"}"))
; method as inner function textobject
(method_declaration
body: (block
.
"{"
_+ @function.inner
"}"))
; outer function textobject
(function_declaration) @function.outer
; outer function literals
(func_literal
(_)?) @function.outer
; method as outer function textobject
(method_declaration
body: (block)?) @function.outer
; struct and interface declaration as class textobject?
(type_declaration
(type_spec
(type_identifier)
(struct_type
(field_declaration_list
(_)?) @class.inner))) @class.outer
(type_declaration
(type_spec
(type_identifier)
(interface_type) @class.inner)) @class.outer
; struct literals as class textobject
(composite_literal
(type_identifier)?
(struct_type
(_))?
(literal_value
(_)) @class.inner) @class.outer
; conditionals
(if_statement
alternative: (_
(_) @conditional.inner)?) @conditional.outer
(if_statement
consequence: (block)? @conditional.inner)
(if_statement
condition: (_) @conditional.inner)
; loops
(for_statement
body: (block)? @loop.inner) @loop.outer
; blocks
(_
(block) @block.inner) @block.outer
; statements
(block
(_) @statement.outer)
; comments
(comment) @comment.outer
; calls
(call_expression) @call.outer
(call_expression
arguments: (argument_list
.
"("
_+ @call.inner
")"))
; parameters
(parameter_list
"," @parameter.outer
.
(parameter_declaration) @parameter.inner @parameter.outer)
(parameter_list
.
(parameter_declaration) @parameter.inner @parameter.outer
.
","? @parameter.outer)
(parameter_declaration
name: (identifier)
type: (_)) @parameter.inner
(parameter_declaration
name: (identifier)
type: (_)) @parameter.inner
(parameter_list
"," @parameter.outer
.
(variadic_parameter_declaration) @parameter.inner @parameter.outer)
; arguments
(argument_list
"," @parameter.outer
.
(_) @parameter.inner @parameter.outer)
(argument_list
.
(_) @parameter.inner @parameter.outer
.
","? @parameter.outer)
; assignments
(short_var_declaration
left: (_) @assignment.lhs
right: (_) @assignment.rhs @assignment.inner) @assignment.outer
(assignment_statement
left: (_) @assignment.lhs
right: (_) @assignment.rhs @assignment.inner) @assignment.outer
(var_spec
name: (_) @assignment.lhs
value: (_) @assignment.rhs @assignment.inner) @assignment.outer
(var_spec
name: (_) @assignment.inner
type: (_)) @assignment.outer
(const_spec
name: (_) @assignment.lhs
value: (_) @assignment.rhs @assignment.inner) @assignment.outer
(const_spec
name: (_) @assignment.inner
type: (_)) @assignment.outer
+55
View File
@@ -0,0 +1,55 @@
; Keywords
"let" @keyword
"if" @keyword.conditional
"then" @keyword.conditional
"else" @keyword.conditional
"import" @keyword.import
; Literals
(string) @string
(string_content) @string
(escape_sequence) @string.escape
(number) @number
(boolean) @boolean
; Identifiers
(identifier) @variable
; Types
(type_annotation) @type
; Fields
(record_field
key: (identifier) @property)
(field_access
(identifier) @property)
; Functions
(call_expression
function: (identifier) @function.call)
; Operators
"=" @operator
":" @punctuation.delimiter
"?" @operator
"..." @operator
"." @punctuation.delimiter
; Punctuation
"{" @punctuation.bracket
"}" @punctuation.bracket
"[" @punctuation.bracket
"]" @punctuation.bracket
"(" @punctuation.bracket
")" @punctuation.bracket
";" @punctuation.delimiter
"," @punctuation.delimiter
; Interpolation
(interpolation
"${" @punctuation.special
"}" @punctuation.special)
; Comments
(comment) @comment
+1
View File
@@ -0,0 +1 @@
; inherits: ecma,jsx
@@ -0,0 +1,56 @@
; inherits: ecma,jsx
; Parameters
(formal_parameters
(identifier) @variable.parameter)
(formal_parameters
(rest_pattern
(identifier) @variable.parameter))
; ({ a }) => null
(formal_parameters
(object_pattern
(shorthand_property_identifier_pattern) @variable.parameter))
; ({ a = b }) => null
(formal_parameters
(object_pattern
(object_assignment_pattern
(shorthand_property_identifier_pattern) @variable.parameter)))
; ({ a: b }) => null
(formal_parameters
(object_pattern
(pair_pattern
value: (identifier) @variable.parameter)))
; ([ a ]) => null
(formal_parameters
(array_pattern
(identifier) @variable.parameter))
; ({ a } = { a }) => null
(formal_parameters
(assignment_pattern
(object_pattern
(shorthand_property_identifier_pattern) @variable.parameter)))
; ({ a = b } = { a }) => null
(formal_parameters
(assignment_pattern
(object_pattern
(object_assignment_pattern
(shorthand_property_identifier_pattern) @variable.parameter))))
; a => null
(arrow_function
parameter: (identifier) @variable.parameter)
; optional parameters
(formal_parameters
(assignment_pattern
left: (identifier) @variable.parameter))
; punctuation
(optional_chain) @punctuation.delimiter
@@ -0,0 +1 @@
; inherits: ecma,jsx
+69
View File
@@ -0,0 +1,69 @@
; inherits: ecma,jsx
; Both properties are matched here.
;
; class Foo {
; this.#bar = "baz";
; this.quuz = "qux";
; }
(field_definition
property: [
(property_identifier)
(private_property_identifier)
] @local.definition.var)
; this.foo = "bar"
(assignment_expression
left: (member_expression
object: (this)
property: (property_identifier) @local.definition.var))
(formal_parameters
(identifier) @local.definition.parameter)
; function(arg = []) {
(formal_parameters
(assignment_pattern
left: (identifier) @local.definition.parameter))
; x => x
(arrow_function
parameter: (identifier) @local.definition.parameter)
; ({ a }) => null
(formal_parameters
(object_pattern
(shorthand_property_identifier_pattern) @local.definition.parameter))
; ({ a: b }) => null
(formal_parameters
(object_pattern
(pair_pattern
value: (identifier) @local.definition.parameter)))
; ([ a ]) => null
(formal_parameters
(array_pattern
(identifier) @local.definition.parameter))
(formal_parameters
(rest_pattern
(identifier) @local.definition.parameter))
; Both methods are matched here.
;
; class Foo {
; #bar(x) { x }
; baz(y) { y }
; }
(method_definition
[
(property_identifier)
(private_property_identifier)
] @local.definition.function
(#set! definition.var.scope parent))
; this.foo()
(member_expression
object: (this)
property: (property_identifier) @local.reference)
@@ -0,0 +1 @@
; inherits: ecma,jsx
+1
View File
@@ -0,0 +1 @@
(jsx_element) @fold
+157
View File
@@ -0,0 +1,157 @@
(jsx_element
open_tag: (jsx_opening_element
[
"<"
">"
] @tag.delimiter))
(jsx_element
close_tag: (jsx_closing_element
[
"</"
">"
] @tag.delimiter))
(jsx_self_closing_element
[
"<"
"/>"
] @tag.delimiter)
(jsx_attribute
(property_identifier) @tag.attribute)
(jsx_opening_element
name: (identifier) @tag.builtin)
(jsx_closing_element
name: (identifier) @tag.builtin)
(jsx_self_closing_element
name: (identifier) @tag.builtin)
(jsx_opening_element
((identifier) @tag
(#lua-match? @tag "^[A-Z]")))
; Handle the dot operator effectively - <My.Component>
(jsx_opening_element
(member_expression
(identifier) @tag.builtin
(property_identifier) @tag))
(jsx_closing_element
((identifier) @tag
(#lua-match? @tag "^[A-Z]")))
; Handle the dot operator effectively - </My.Component>
(jsx_closing_element
(member_expression
(identifier) @tag.builtin
(property_identifier) @tag))
(jsx_self_closing_element
((identifier) @tag
(#lua-match? @tag "^[A-Z]")))
; Handle the dot operator effectively - <My.Component />
(jsx_self_closing_element
(member_expression
(identifier) @tag.builtin
(property_identifier) @tag))
(html_character_reference) @tag
(jsx_text) @none @spell
(html_character_reference) @character.special
((jsx_element
(jsx_opening_element
name: (identifier) @_tag)
(jsx_text) @markup.heading)
(#eq? @_tag "title"))
((jsx_element
(jsx_opening_element
name: (identifier) @_tag)
(jsx_text) @markup.heading.1)
(#eq? @_tag "h1"))
((jsx_element
(jsx_opening_element
name: (identifier) @_tag)
(jsx_text) @markup.heading.2)
(#eq? @_tag "h2"))
((jsx_element
(jsx_opening_element
name: (identifier) @_tag)
(jsx_text) @markup.heading.3)
(#eq? @_tag "h3"))
((jsx_element
(jsx_opening_element
name: (identifier) @_tag)
(jsx_text) @markup.heading.4)
(#eq? @_tag "h4"))
((jsx_element
(jsx_opening_element
name: (identifier) @_tag)
(jsx_text) @markup.heading.5)
(#eq? @_tag "h5"))
((jsx_element
(jsx_opening_element
name: (identifier) @_tag)
(jsx_text) @markup.heading.6)
(#eq? @_tag "h6"))
((jsx_element
(jsx_opening_element
name: (identifier) @_tag)
(jsx_text) @markup.strong)
(#any-of? @_tag "strong" "b"))
((jsx_element
(jsx_opening_element
name: (identifier) @_tag)
(jsx_text) @markup.italic)
(#any-of? @_tag "em" "i"))
((jsx_element
(jsx_opening_element
name: (identifier) @_tag)
(jsx_text) @markup.strikethrough)
(#any-of? @_tag "s" "del"))
((jsx_element
(jsx_opening_element
name: (identifier) @_tag)
(jsx_text) @markup.underline)
(#eq? @_tag "u"))
((jsx_element
(jsx_opening_element
name: (identifier) @_tag)
(jsx_text) @markup.raw)
(#any-of? @_tag "code" "kbd"))
((jsx_element
(jsx_opening_element
name: (identifier) @_tag)
(jsx_text) @markup.link.label)
(#eq? @_tag "a"))
((jsx_attribute
(property_identifier) @_attr
(string
(string_fragment) @string.special.url))
(#any-of? @_attr "href" "src"))
((jsx_element) @_jsx_element
(#set! @_jsx_element bo.commentstring "{/* %s */}"))
((jsx_attribute) @_jsx_attribute
(#set! @_jsx_attribute bo.commentstring "// %s"))
+11
View File
@@ -0,0 +1,11 @@
; Styled Jsx <style jsx>
(jsx_element
(jsx_opening_element
(identifier) @_name
(#eq? @_name "style")
(jsx_attribute) @_attr
(#eq? @_attr "jsx"))
(jsx_expression
((template_string) @injection.content
(#set! injection.language "css"))
(#offset! @injection.content 0 1 0 -1)))
+8
View File
@@ -0,0 +1,8 @@
; inherits: ecma
(jsx_attribute) @attribute.outer
(jsx_attribute
(property_identifier)
(_
(_) @attribute.inner))
+12
View File
@@ -0,0 +1,12 @@
[
(do_statement)
(while_statement)
(repeat_statement)
(if_statement)
(for_statement)
(function_declaration)
(function_definition)
(parameters)
(arguments)
(table_constructor)
] @fold
+265
View File
@@ -0,0 +1,265 @@
; Keywords
"return" @keyword.return
[
"goto"
"in"
"local"
] @keyword
(break_statement) @keyword
(do_statement
[
"do"
"end"
] @keyword)
(while_statement
[
"while"
"do"
"end"
] @keyword.repeat)
(repeat_statement
[
"repeat"
"until"
] @keyword.repeat)
(if_statement
[
"if"
"elseif"
"else"
"then"
"end"
] @keyword.conditional)
(elseif_statement
[
"elseif"
"then"
"end"
] @keyword.conditional)
(else_statement
[
"else"
"end"
] @keyword.conditional)
(for_statement
[
"for"
"do"
"end"
] @keyword.repeat)
(function_declaration
[
"function"
"end"
] @keyword.function)
(function_definition
[
"function"
"end"
] @keyword.function)
; Operators
[
"and"
"not"
"or"
] @keyword.operator
[
"+"
"-"
"*"
"/"
"%"
"^"
"#"
"=="
"~="
"<="
">="
"<"
">"
"="
"&"
"~"
"|"
"<<"
">>"
"//"
".."
] @operator
; Punctuations
[
";"
":"
"::"
","
"."
] @punctuation.delimiter
; Brackets
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
; Variables
(identifier) @variable
((identifier) @constant.builtin
(#eq? @constant.builtin "_VERSION"))
((identifier) @variable.builtin
(#eq? @variable.builtin "self"))
((identifier) @module.builtin
(#any-of? @module.builtin "_G" "debug" "io" "jit" "math" "os" "package" "string" "table" "utf8"))
((identifier) @keyword.coroutine
(#eq? @keyword.coroutine "coroutine"))
(variable_list
(attribute
"<" @punctuation.bracket
(identifier) @attribute
">" @punctuation.bracket))
; Labels
(label_statement
(identifier) @label)
(goto_statement
(identifier) @label)
; Constants
((identifier) @constant
(#lua-match? @constant "^[A-Z][A-Z_0-9]*$"))
(nil) @constant.builtin
[
(false)
(true)
] @boolean
; Tables
(field
name: (identifier) @property)
(dot_index_expression
field: (identifier) @variable.member)
(table_constructor
[
"{"
"}"
] @constructor)
; Functions
(parameters
(identifier) @variable.parameter)
(vararg_expression) @variable.parameter.builtin
(function_declaration
name: [
(identifier) @function
(dot_index_expression
field: (identifier) @function)
])
(function_declaration
name: (method_index_expression
method: (identifier) @function.method))
(assignment_statement
(variable_list
.
name: [
(identifier) @function
(dot_index_expression
field: (identifier) @function)
])
(expression_list
.
value: (function_definition)))
(table_constructor
(field
name: (identifier) @function
value: (function_definition)))
(function_call
name: [
(identifier) @function.call
(dot_index_expression
field: (identifier) @function.call)
(method_index_expression
method: (identifier) @function.method.call)
])
(function_call
(identifier) @function.builtin
(#any-of? @function.builtin
; built-in functions in Lua 5.1
"assert" "collectgarbage" "dofile" "error" "getfenv" "getmetatable" "ipairs" "load" "loadfile"
"loadstring" "module" "next" "pairs" "pcall" "print" "rawequal" "rawget" "rawlen" "rawset"
"require" "select" "setfenv" "setmetatable" "tonumber" "tostring" "type" "unpack" "xpcall"
"__add" "__band" "__bnot" "__bor" "__bxor" "__call" "__concat" "__div" "__eq" "__gc" "__idiv"
"__index" "__le" "__len" "__lt" "__metatable" "__mod" "__mul" "__name" "__newindex" "__pairs"
"__pow" "__shl" "__shr" "__sub" "__tostring" "__unm"))
; Others
(comment) @comment @spell
((comment) @comment.documentation
(#lua-match? @comment.documentation "^[-][-][-]"))
((comment) @comment.documentation
(#lua-match? @comment.documentation "^[-][-](%s?)@"))
(hash_bang_line) @keyword.directive
(number) @number
(string) @string
(escape_sequence) @string.escape
; string.match("123", "%d+")
(function_call
(dot_index_expression
field: (identifier) @_method
(#any-of? @_method "find" "match" "gmatch" "gsub"))
arguments: (arguments
.
(_)
.
(string
content: (string_content) @string.regexp)))
;("123"):match("%d+")
(function_call
(method_index_expression
method: (identifier) @_method
(#any-of? @_method "find" "match" "gmatch" "gsub"))
arguments: (arguments
.
(string
content: (string_content) @string.regexp)))
+202
View File
@@ -0,0 +1,202 @@
((function_call
name: [
(identifier) @_cdef_identifier
(_
_
(identifier) @_cdef_identifier)
]
arguments: (arguments
(string
content: _ @injection.content)))
(#set! injection.language "c")
(#eq? @_cdef_identifier "cdef"))
((function_call
name: (_) @_vimcmd_identifier
arguments: (arguments
(string
content: _ @injection.content)))
(#set! injection.language "vim")
(#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec2"))
((function_call
name: (_) @_vimcmd_identifier
arguments: (arguments
(string
content: _ @injection.content) .))
(#set! injection.language "query")
(#any-of? @_vimcmd_identifier "vim.treesitter.query.set" "vim.treesitter.query.parse"))
((function_call
name: (_) @_vimcmd_identifier
arguments: (arguments
.
(_)
.
(string
content: _ @_method)
.
(string
content: _ @injection.content)))
(#any-of? @_vimcmd_identifier "vim.rpcrequest" "vim.rpcnotify")
(#eq? @_method "nvim_exec_lua")
(#set! injection.language "lua"))
; exec_lua [[ ... ]] in functionaltests
((function_call
name: (identifier) @_function
arguments: (arguments
(string
content: (string_content) @injection.content)))
(#eq? @_function "exec_lua")
(#set! injection.language "lua"))
; vim.api.nvim_create_autocmd("FileType", { command = "injected here" })
(function_call
name: (_) @_vimcmd_identifier
arguments: (arguments
.
(_)
.
(table_constructor
(field
name: (identifier) @_command
value: (string
content: (_) @injection.content))) .)
; limit so only 2-argument functions gets matched before pred handle
(#eq? @_vimcmd_identifier "vim.api.nvim_create_autocmd")
(#eq? @_command "command")
(#set! injection.language "vim"))
(function_call
name: (_) @_user_cmd
arguments: (arguments
.
(_)
.
(string
content: (_) @injection.content)
.
(_) .)
(#eq? @_user_cmd "vim.api.nvim_create_user_command")
(#set! injection.language "vim"))
(function_call
name: (_) @_user_cmd
arguments: (arguments
.
(_)
.
(_)
.
(string
content: (_) @injection.content)
.
(_) .)
; Limiting predicate handling to only functions with 4 arguments
(#eq? @_user_cmd "vim.api.nvim_buf_create_user_command")
(#set! injection.language "vim"))
; rhs highlighting for vim.keymap.set/vim.api.nvim_set_keymap/vim.api.nvim_buf_set_keymap
; (function_call
; name: (_) @_map
; arguments:
; (arguments
; . (_)
; . (_)
; .
; (string
; content: (_) @injection.content))
; (#any-of? @_map "vim.api.nvim_set_keymap" "vim.keymap.set")
; (#set! injection.language "vim"))
;
; (function_call
; name: (_) @_map
; arguments:
; (arguments
; . (_)
; . (_)
; . (_)
; .
; (string
; content: (_) @injection.content)
; . (_) .)
; (#eq? @_map "vim.api.nvim_buf_set_keymap")
; (#set! injection.language "vim"))
; highlight string as query if starts with `;; query`
(string
content: _ @injection.content
(#lua-match? @injection.content "^%s*;+%s?query")
(#set! injection.language "query"))
(comment
content: (_) @injection.content
(#lua-match? @injection.content "^[-][%s]*[@|]")
(#set! injection.language "luadoc")
(#offset! @injection.content 0 1 0 0))
; string.match("123", "%d+")
(function_call
(dot_index_expression
field: (identifier) @_method
(#any-of? @_method "find" "match" "gmatch" "gsub"))
arguments: (arguments
.
(_)
.
(string
content: (string_content) @injection.content
(#set! injection.language "luap")
(#set! injection.include-children))))
;("123"):match("%d+")
(function_call
(method_index_expression
method: (identifier) @_method
(#any-of? @_method "find" "match" "gmatch" "gsub"))
arguments: (arguments
.
(string
content: (string_content) @injection.content
(#set! injection.language "luap")
(#set! injection.include-children))))
; string.format("pi = %.2f", 3.14159)
((function_call
(dot_index_expression
field: (identifier) @_method)
arguments: (arguments
.
(string
(string_content) @injection.content)))
(#eq? @_method "format")
(#set! injection.language "printf"))
; ("pi = %.2f"):format(3.14159)
((function_call
(method_index_expression
table: (_
(string
(string_content) @injection.content))
method: (identifier) @_method))
(#eq? @_method "format")
(#set! injection.language "printf"))
(comment
content: (_) @injection.content
(#set! injection.language "comment"))
; vim.filetype.add({ pattern = { ["some lua pattern here"] = "filetype" } })
((function_call
name: (_) @_filetypeadd_identifier
arguments: (arguments
(table_constructor
(field
name: (_) @_pattern_key
value: (table_constructor
(field
name: (string
content: _ @injection.content)))))))
(#set! injection.language "luap")
(#eq? @_filetypeadd_identifier "vim.filetype.add")
(#eq? @_pattern_key "pattern"))
+54
View File
@@ -0,0 +1,54 @@
; Scopes
[
(chunk)
(do_statement)
(while_statement)
(repeat_statement)
(if_statement)
(for_statement)
(function_declaration)
(function_definition)
] @local.scope
; Definitions
(assignment_statement
(variable_list
(identifier) @local.definition.var))
(assignment_statement
(variable_list
(dot_index_expression
.
(_) @local.definition.associated
(identifier) @local.definition.var)))
((function_declaration
name: (identifier) @local.definition.function)
(#set! definition.function.scope "parent"))
((function_declaration
name: (dot_index_expression
.
(_) @local.definition.associated
(identifier) @local.definition.function))
(#set! definition.method.scope "parent"))
((function_declaration
name: (method_index_expression
.
(_) @local.definition.associated
(identifier) @local.definition.method))
(#set! definition.method.scope "parent"))
(for_generic_clause
(variable_list
(identifier) @local.definition.var))
(for_numeric_clause
name: (identifier) @local.definition.var)
(parameters
(identifier) @local.definition.parameter)
; References
(identifier) @local.reference
+109
View File
@@ -0,0 +1,109 @@
; block
(_
(block) @block.inner) @block.outer
; call
(function_call) @call.outer
(function_call
(arguments) @call.inner
(#match? @call.inner "^[^\\(]"))
(function_call
arguments: (arguments
.
"("
_+ @call.inner
")"))
; class
; comment
(comment
(comment_content) @comment.inner) @comment.outer
; conditional
(if_statement
alternative: (_
(_) @conditional.inner)?) @conditional.outer
(if_statement
consequence: (block)? @conditional.inner)
(if_statement
condition: (_) @conditional.inner)
; frame
; function
[
(function_declaration)
(function_definition)
] @function.outer
(function_declaration
body: (_) @function.inner)
(function_definition
body: (_) @function.inner)
; return
(return_statement
(_)? @return.inner) @return.outer
; loop
[
(while_statement)
(for_statement)
(repeat_statement)
] @loop.outer
(while_statement
body: (_) @loop.inner)
(for_statement
body: (_) @loop.inner)
(repeat_statement
body: (_) @loop.inner)
; parameter
(arguments
.
(_) @parameter.inner @parameter.outer
.
","? @parameter.outer)
(parameters
.
(_) @parameter.inner @parameter.outer
.
","? @parameter.outer)
(table_constructor
(field) @parameter.inner @parameter.outer
","? @parameter.outer)
(arguments
"," @parameter.outer
.
(_) @parameter.inner @parameter.outer)
(parameters
"," @parameter.outer
.
(_) @parameter.inner @parameter.outer)
; number
(number) @number.inner
(assignment_statement
(variable_list) @assignment.lhs
(expression_list) @assignment.inner @assignment.rhs) @assignment.outer
(assignment_statement
(variable_list) @assignment.inner)
; scopename
; statement
(statement) @statement.outer
(return_statement) @statement.outer
+11
View File
@@ -0,0 +1,11 @@
; Nix doesn't really have blocks, so just guess what people might want folds for
[
(if_expression)
(with_expression)
(let_expression)
(function_expression)
(attrset_expression)
(rec_attrset_expression)
(list_expression)
(indented_string_expression)
] @fold
+210
View File
@@ -0,0 +1,210 @@
; basic keywords
[
"assert"
"in"
"inherit"
"let"
"rec"
"with"
] @keyword
; if/then/else
[
"if"
"then"
"else"
] @keyword.conditional
; field access default (`a.b or c`)
"or" @keyword.operator
; comments
(comment) @comment @spell
; strings
(string_fragment) @string
(string_expression
"\"" @string)
(indented_string_expression
"''" @string)
; paths and URLs
[
(path_expression)
(hpath_expression)
(spath_expression)
] @string.special.path
(uri_expression) @string.special.url
; escape sequences
(escape_sequence) @string.escape
; delimiters
[
"."
";"
":"
","
] @punctuation.delimiter
; brackets
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
; `?` in `{ x ? y }:`, used to set defaults for named function arguments
(formal
name: (identifier) @variable.parameter
"?"? @operator)
; `...` in `{ ... }`, used to ignore unknown named function arguments (see above)
(ellipses) @variable.parameter.builtin
; universal is the parameter of the function expression
; `:` in `x: y`, used to separate function argument from body (see above)
(function_expression
universal: (identifier) @variable.parameter
":" @punctuation.special)
; function calls
(apply_expression
function: (variable_expression
name: (identifier) @function.call))
; basic identifiers
(variable_expression) @variable
(variable_expression
name: (identifier) @keyword.import
(#eq? @keyword.import "import"))
(variable_expression
name: (identifier) @boolean
(#any-of? @boolean "true" "false"))
; string interpolation (this was very annoying to get working properly)
(interpolation
"${" @punctuation.special
(_)
"}" @punctuation.special) @none
(select_expression
expression: (_) @_expr
attrpath: (attrpath
attr: (identifier) @variable.member)
(#not-eq? @_expr "builtins"))
(attrset_expression
(binding_set
(binding
.
(attrpath
(identifier) @variable.member))))
(rec_attrset_expression
(binding_set
(binding
.
(attrpath
(identifier) @variable.member))))
function: (select_expression
attrpath: (attrpath
attr: (identifier) @function.call .))
; builtin functions (with builtins prefix)
(select_expression
expression: (variable_expression
name: (identifier) @_id)
attrpath: (attrpath
attr: (identifier) @function.builtin)
(#eq? @_id "builtins"))
; builtin functions (without builtins prefix)
(variable_expression
name: (identifier) @function.builtin
(#any-of? @function.builtin
; nix eval --impure --expr 'with builtins; filter (x: !(elem x [ "abort" "import" "throw" ]) && isFunction builtins.${x}) (attrNames builtins)'
"add" "addErrorContext" "all" "any" "appendContext" "attrNames" "attrValues" "baseNameOf"
"bitAnd" "bitOr" "bitXor" "break" "catAttrs" "ceil" "compareVersions" "concatLists" "concatMap"
"concatStringsSep" "deepSeq" "derivation" "derivationStrict" "dirOf" "div" "elem" "elemAt"
"fetchGit" "fetchMercurial" "fetchTarball" "fetchTree" "fetchurl" "filter" "filterSource"
"findFile" "floor" "foldl'" "fromJSON" "fromTOML" "functionArgs" "genList" "genericClosure"
"getAttr" "getContext" "getEnv" "getFlake" "groupBy" "hasAttr" "hasContext" "hashFile"
"hashString" "head" "intersectAttrs" "isAttrs" "isBool" "isFloat" "isFunction" "isInt" "isList"
"isNull" "isPath" "isString" "length" "lessThan" "listToAttrs" "map" "mapAttrs" "match" "mul"
"parseDrvName" "partition" "path" "pathExists" "placeholder" "readDir" "readFile" "removeAttrs"
"replaceStrings" "scopedImport" "seq" "sort" "split" "splitVersion" "storePath" "stringLength"
"sub" "substring" "tail" "toFile" "toJSON" "toPath" "toString" "toXML" "trace" "traceVerbose"
"tryEval" "typeOf" "unsafeDiscardOutputDependency" "unsafeDiscardStringContext"
"unsafeGetAttrPos" "zipAttrsWith"
; primops, `__<tab>` in `nix repl`
"__add" "__filter" "__isFunction" "__split" "__addErrorContext" "__filterSource" "__isInt"
"__splitVersion" "__all" "__findFile" "__isList" "__storeDir" "__any" "__floor" "__isPath"
"__storePath" "__appendContext" "__foldl'" "__isString" "__stringLength" "__attrNames"
"__fromJSON" "__langVersion" "__sub" "__attrValues" "__functionArgs" "__length" "__substring"
"__bitAnd" "__genList" "__lessThan" "__tail" "__bitOr" "__genericClosure" "__listToAttrs"
"__toFile" "__bitXor" "__getAttr" "__mapAttrs" "__toJSON" "__catAttrs" "__getContext" "__match"
"__toPath" "__ceil" "__getEnv" "__mul" "__toXML" "__compareVersions" "__getFlake" "__nixPath"
"__trace" "__concatLists" "__groupBy" "__nixVersion" "__traceVerbose" "__concatMap" "__hasAttr"
"__parseDrvName" "__tryEval" "__concatStringsSep" "__hasContext" "__partition" "__typeOf"
"__currentSystem" "__hashFile" "__path" "__unsafeDiscardOutputDependency" "__currentTime"
"__hashString" "__pathExists" "__unsafeDiscardStringContext" "__deepSeq" "__head" "__readDir"
"__unsafeGetAttrPos" "__div" "__intersectAttrs" "__readFile" "__zipAttrsWith" "__elem"
"__isAttrs" "__replaceStrings" "__elemAt" "__isBool" "__seq" "__fetchurl" "__isFloat" "__sort"))
; constants
(variable_expression
name: (identifier) @constant.builtin
(#any-of? @constant.builtin
; nix eval --impure --expr 'with builtins; filter (x: !(isFunction builtins.${x} || isBool builtins.${x})) (attrNames builtins)'
"builtins" "currentSystem" "currentTime" "langVersion" "nixPath" "nixVersion" "null" "storeDir"))
; function definition
(binding
attrpath: (attrpath
attr: (identifier) @function)
expression: (function_expression))
; unary operators
(unary_expression
operator: _ @operator)
; binary operators
(binary_expression
operator: _ @operator)
[
"="
"@"
"?"
] @operator
; integers, also highlight a unary -
[
(unary_expression
"-"
(integer_expression))
(integer_expression)
] @number
; floats, also highlight a unary -
[
(unary_expression
"-"
(float_expression))
(float_expression)
] @number.float
; exceptions
(variable_expression
name: (identifier) @keyword.exception
(#any-of? @keyword.exception "abort" "throw"))
+190
View File
@@ -0,0 +1,190 @@
((comment) @injection.content
(#set! injection.language "comment"))
((comment) @injection.language
. ; this is to make sure only adjacent comments are accounted for the injections
[
(string_expression
(string_fragment) @injection.content)
(indented_string_expression
(string_fragment) @injection.content)
]
(#gsub! @injection.language "/%*%s*([%w%p]+)%s*%*/" "%1")
(#set! injection.combined))
; #-style Comments
((comment) @injection.language
. ; this is to make sure only adjacent comments are accounted for the injections
[
(string_expression
(string_fragment) @injection.content)
(indented_string_expression
(string_fragment) @injection.content)
]
(#gsub! @injection.language "#%s*([%w%p]+)%s*" "%1")
(#set! injection.combined))
(apply_expression
function: (_) @_func
argument: [
(string_expression
((string_fragment) @injection.content
(#set! injection.language "regex")))
(indented_string_expression
((string_fragment) @injection.content
(#set! injection.language "regex")))
]
(#match? @_func "(^|\\.)match$")
(#set! injection.combined))
(binding
attrpath: (attrpath
(identifier) @_path)
expression: [
(string_expression
((string_fragment) @injection.content
(#set! injection.language "bash")))
(indented_string_expression
((string_fragment) @injection.content
(#set! injection.language "bash")))
]
(#match? @_path "(^\\w+(Phase|Hook|Check)|(pre|post)[A-Z]\\w+|script)$"))
(apply_expression
function: (_) @_func
argument: (_
(_)*
(_
(_)*
(binding
attrpath: (attrpath
(identifier) @_path)
expression: [
(string_expression
((string_fragment) @injection.content
(#set! injection.language "bash")))
(indented_string_expression
((string_fragment) @injection.content
(#set! injection.language "bash")))
])))
(#match? @_func "(^|\\.)writeShellApplication$")
(#match? @_path "^text$")
(#set! injection.combined))
(apply_expression
function: (apply_expression
function: (apply_expression
function: (_) @_func))
argument: [
(string_expression
((string_fragment) @injection.content
(#set! injection.language "bash")))
(indented_string_expression
((string_fragment) @injection.content
(#set! injection.language "bash")))
]
(#match? @_func "(^|\\.)runCommand((No)?CC)?(Local)?$")
(#set! injection.combined))
((apply_expression
function: (apply_expression
function: (_) @_func)
argument: [
(string_expression
((string_fragment) @injection.content
(#set! injection.language "bash")))
(indented_string_expression
((string_fragment) @injection.content
(#set! injection.language "bash")))
])
(#match? @_func "(^|\\.)write(Bash|Dash|ShellScript)(Bin)?$")
(#set! injection.combined))
((apply_expression
function: (apply_expression
function: (_) @_func)
argument: [
(string_expression
((string_fragment) @injection.content
(#set! injection.language "fish")))
(indented_string_expression
((string_fragment) @injection.content
(#set! injection.language "fish")))
])
(#match? @_func "(^|\\.)writeFish(Bin)?$")
(#set! injection.combined))
((apply_expression
function: (apply_expression
function: (apply_expression
function: (_) @_func))
argument: [
(string_expression
((string_fragment) @injection.content
(#set! injection.language "haskell")))
(indented_string_expression
((string_fragment) @injection.content
(#set! injection.language "haskell")))
])
(#match? @_func "(^|\\.)writeHaskell(Bin)?$")
(#set! injection.combined))
((apply_expression
function: (apply_expression
function: (apply_expression
function: (_) @_func))
argument: [
(string_expression
((string_fragment) @injection.content
(#set! injection.language "javascript")))
(indented_string_expression
((string_fragment) @injection.content
(#set! injection.language "javascript")))
])
(#match? @_func "(^|\\.)writeJS(Bin)?$")
(#set! injection.combined))
((apply_expression
function: (apply_expression
function: (apply_expression
function: (_) @_func))
argument: [
(string_expression
((string_fragment) @injection.content
(#set! injection.language "perl")))
(indented_string_expression
((string_fragment) @injection.content
(#set! injection.language "perl")))
])
(#match? @_func "(^|\\.)writePerl(Bin)?$")
(#set! injection.combined))
((apply_expression
function: (apply_expression
function: (apply_expression
function: (_) @_func))
argument: [
(string_expression
((string_fragment) @injection.content
(#set! injection.language "python")))
(indented_string_expression
((string_fragment) @injection.content
(#set! injection.language "python")))
])
(#match? @_func "(^|\\.)write(PyPy|Python)[23](Bin)?$")
(#set! injection.combined))
((apply_expression
function: (apply_expression
function: (apply_expression
function: (_) @_func))
argument: [
(string_expression
((string_fragment) @injection.content
(#set! injection.language "rust")))
(indented_string_expression
((string_fragment) @injection.content
(#set! injection.language "rust")))
])
(#match? @_func "(^|\\.)writeRust(Bin)?$")
(#set! injection.combined))
+34
View File
@@ -0,0 +1,34 @@
; let bindings
(let_expression
(binding_set
(binding
.
(attrpath) @local.definition.var))) @local.scope
; rec attrsets
(rec_attrset_expression
(binding_set
(binding
.
(attrpath) @local.definition.field))) @local.scope
; functions and parameters
(function_expression
.
[
(identifier) @local.definition.parameter
(formals
(formal
.
(identifier) @local.definition.parameter))
]) @local.scope
((formals)
"@"
(identifier) @local.definition.parameter) ; I couldn't get this to work properly inside the (function)
(variable_expression
(identifier) @local.reference)
(inherited_attrs
attr: (identifier) @local.reference)
+26
View File
@@ -0,0 +1,26 @@
; named function
(binding
(function_expression)) @function.outer
; anonymous function
(function_expression
(_) ; argument
(_) @function.inner) @function.outer
(function_expression
(formals
(formal) @parameter.inner))
(function_expression
(_) @parameter.outer
(_))
(comment) @comment.outer
(if_expression
(_) @conditional.inner) @conditional.outer
[
(integer_expression)
(float_expression)
] @number.inner
+1
View File
@@ -0,0 +1 @@
; inherits: php_only
+1
View File
@@ -0,0 +1 @@
; inherits: php_only
+5
View File
@@ -0,0 +1,5 @@
; inherits: php_only
((text) @injection.content
(#set! injection.language "html")
(#set! injection.combined))
+1
View File
@@ -0,0 +1 @@
; inherits: php_only
+235
View File
@@ -0,0 +1,235 @@
; functions
(function_definition
body: (compound_statement
.
"{"
_+ @function.inner
"}"))
(function_definition) @function.outer
(anonymous_function
body: (compound_statement
.
"{"
_+ @function.inner
"}"))
(anonymous_function) @function.outer
; methods
(method_declaration
body: (compound_statement
.
"{"
_+ @function.inner
"}"))
(method_declaration) @function.outer
; traits
(trait_declaration
body: (declaration_list
.
"{"
_+ @class.inner
"}"))
(trait_declaration) @class.outer
; interfaces
(interface_declaration
body: (declaration_list
.
"{"
_+ @class.inner
"}"))
(interface_declaration) @class.outer
; enums
(enum_declaration
body: (enum_declaration_list
.
"{"
_+ @class.inner
"}"))
(enum_declaration) @class.outer
; classes
(class_declaration
body: (declaration_list
.
"{"
_+ @class.inner
"}"))
(class_declaration) @class.outer
; loops
(for_statement
(compound_statement
.
"{"
_+ @loop.inner
"}"))
(for_statement) @loop.outer
(foreach_statement
body: (compound_statement
.
"{"
_+ @loop.inner
"}"))
(foreach_statement) @loop.outer
(while_statement
body: (compound_statement
.
"{"
_+ @loop.inner
"}"))
(while_statement) @loop.outer
(do_statement
body: (compound_statement
.
"{"
_+ @loop.inner
"}"))
(do_statement) @loop.outer
; conditionals
(switch_statement
body: (switch_block
.
"{"
_+ @conditional.inner
"}"))
(switch_statement) @conditional.outer
(if_statement
body: (compound_statement
.
"{"
_+ @conditional.inner
"}"))
(if_statement) @conditional.outer
(else_clause
body: (compound_statement
.
"{"
_+ @conditional.inner
"}"))
(else_if_clause
body: (compound_statement
.
"{"
_+ @conditional.inner
"}"))
; blocks
(_
(switch_block) @block.inner) @block.outer
; parameters
(arguments
"," @parameter.outer
.
(_) @parameter.inner @parameter.outer)
(arguments
.
(_) @parameter.inner @parameter.outer
.
","? @parameter.outer)
(formal_parameters
"," @parameter.outer
.
(_) @parameter.inner @parameter.outer)
(formal_parameters
.
(_) @parameter.inner @parameter.outer
.
","? @parameter.outer)
; comments
(comment) @comment.outer
; call
(function_call_expression) @call.outer
(member_call_expression) @call.outer
(nullsafe_member_call_expression) @call.outer
(scoped_call_expression) @call.outer
(function_call_expression
arguments: (arguments
.
"("
_+ @call.inner
")"))
(member_call_expression
arguments: (arguments
.
"("
_+ @call.inner
")"))
(nullsafe_member_call_expression
arguments: (arguments
.
"("
_+ @call.inner
")"))
(scoped_call_expression
arguments: (arguments
.
"("
_+ @call.inner
")"))
; statement
[
(expression_statement)
(declare_statement)
(return_statement)
(namespace_use_declaration)
(namespace_definition)
(if_statement)
(empty_statement)
(switch_statement)
(while_statement)
(do_statement)
(for_statement)
(foreach_statement)
(goto_statement)
(continue_statement)
(break_statement)
(try_statement)
(echo_statement)
(unset_statement)
(const_declaration)
(function_definition)
(class_declaration)
(interface_declaration)
(trait_declaration)
(enum_declaration)
(global_declaration)
(function_static_declaration)
] @statement.outer
+17
View File
@@ -0,0 +1,17 @@
[
(if_statement)
(switch_statement)
(while_statement)
(do_statement)
(for_statement)
(foreach_statement)
(try_statement)
(function_definition)
(class_declaration)
(interface_declaration)
(trait_declaration)
(enum_declaration)
(function_static_declaration)
(method_declaration)
(namespace_use_declaration)+
] @fold
+479
View File
@@ -0,0 +1,479 @@
; Keywords
[
"and"
"as"
"instanceof"
"or"
"xor"
] @keyword.operator
[
"fn"
"function"
] @keyword.function
[
"clone"
"declare"
"default"
"echo"
"enddeclare"
"extends"
"global"
"goto"
"implements"
"insteadof"
"print"
"new"
"unset"
] @keyword
[
"enum"
"class"
"interface"
"namespace"
"trait"
] @keyword.type
[
"abstract"
"const"
"final"
"private"
"protected"
"public"
"readonly"
(static_modifier)
] @keyword.modifier
(function_static_declaration
"static" @keyword.modifier)
[
"return"
"exit"
"yield"
] @keyword.return
(yield_expression
"from" @keyword.return)
[
"case"
"else"
"elseif"
"endif"
"endswitch"
"if"
"switch"
"match"
"??"
] @keyword.conditional
[
"break"
"continue"
"do"
"endfor"
"endforeach"
"endwhile"
"for"
"foreach"
"while"
] @keyword.repeat
[
"catch"
"finally"
"throw"
"try"
] @keyword.exception
[
"include_once"
"include"
"require_once"
"require"
"use"
] @keyword.import
[
","
";"
":"
"\\"
] @punctuation.delimiter
[
(php_tag)
"?>"
"("
")"
"["
"]"
"{"
"}"
"#["
] @punctuation.bracket
[
"="
"."
"-"
"*"
"/"
"+"
"%"
"**"
"~"
"|"
"^"
"&"
"<<"
">>"
"<<<"
"->"
"?->"
"=>"
"<"
"<="
">="
">"
"<>"
"<=>"
"=="
"!="
"==="
"!=="
"!"
"&&"
"||"
".="
"-="
"+="
"*="
"/="
"%="
"**="
"&="
"|="
"^="
"<<="
">>="
"??="
"--"
"++"
"@"
"::"
] @operator
; Variables
(variable_name) @variable
; Constants
((name) @constant
(#lua-match? @constant "^_?[A-Z][A-Z%d_]*$"))
((name) @constant.builtin
(#lua-match? @constant.builtin "^__[A-Z][A-Z%d_]+__$"))
(const_declaration
(const_element
(name) @constant))
; Types
[
(primitive_type)
(cast_type)
(bottom_type)
] @type.builtin
(named_type
[
(name) @type
(qualified_name
(name) @type)
(relative_name
(name) @type)
])
(named_type
(name) @type.builtin
(#any-of? @type.builtin "static" "self"))
(class_declaration
name: (name) @type)
(base_clause
[
(name) @type
(qualified_name
(name) @type)
(relative_name
(name) @type)
])
(enum_declaration
name: (name) @type)
(interface_declaration
name: (name) @type)
(namespace_use_clause
[
(name) @type
(qualified_name
(name) @type)
alias: (name) @type.definition
])
(namespace_use_clause
type: "function"
[
(name) @function
(qualified_name
(name) @function)
alias: (name) @function
])
(namespace_use_declaration
type: "function"
body: (namespace_use_group
(namespace_use_clause
[
(name) @function
(qualified_name
(name) @function)
alias: (name) @function
])))
(namespace_use_clause
type: "const"
[
(name) @constant
(qualified_name
(name) @constant)
alias: (name) @constant
])
(namespace_use_declaration
type: "const"
body: (namespace_use_group
(namespace_use_clause
[
(name) @constant
(qualified_name
(name) @constant)
alias: (name) @constant
])))
(class_interface_clause
[
(name) @type
(qualified_name
(name) @type)
(relative_name
(name) @type)
])
(scoped_call_expression
scope: [
(name) @type
(qualified_name
(name) @type)
(relative_name
(name) @type)
])
(class_constant_access_expression
.
[
(name) @type
(qualified_name
(name) @type)
(relative_name
(name) @type)
]
(name) @constant)
(scoped_property_access_expression
scope: [
(name) @type
(qualified_name
(name) @type)
(relative_name
(name) @type)
])
(scoped_property_access_expression
name: (variable_name) @variable.member)
(trait_declaration
name: (name) @type)
(use_declaration
(name) @type)
(binary_expression
operator: "instanceof"
right: [
(name) @type
(qualified_name
(name) @type)
(relative_name
(name) @type)
])
; Functions, methods, constructors
(array_creation_expression
"array" @function.builtin)
(list_literal
"list" @function.builtin)
(exit_statement
"exit" @function.builtin
"(")
(method_declaration
name: (name) @function.method)
(function_call_expression
function: [
(name) @function.call
(qualified_name
(name) @function.call)
(relative_name
(name) @function.call)
])
(scoped_call_expression
name: (name) @function.call)
(member_call_expression
name: (name) @function.method.call)
(function_definition
name: (name) @function)
(nullsafe_member_call_expression
name: (name) @function.method)
(use_instead_of_clause
(class_constant_access_expression
(_)
(name) @function.method)
(name) @type)
(use_as_clause
(class_constant_access_expression
(_)
(name) @function.method)*
(name) @function.method)
(method_declaration
name: (name) @constructor
(#eq? @constructor "__construct"))
(object_creation_expression
[
(name) @constructor
(qualified_name
(name) @constructor)
(relative_name
(name) @constructor)
])
; Parameters
(variadic_parameter
"..." @operator
name: (variable_name) @variable.parameter)
(simple_parameter
name: (variable_name) @variable.parameter)
(argument
(name) @variable.parameter)
; Member
(property_element
(variable_name) @property)
(member_access_expression
name: (variable_name
(name)) @variable.member)
(member_access_expression
name: (name) @variable.member)
(nullsafe_member_access_expression
name: (variable_name
(name)) @variable.member)
(nullsafe_member_access_expression
name: (name) @variable.member)
; Variables
(relative_scope) @variable.builtin
((variable_name) @variable.builtin
(#eq? @variable.builtin "$this"))
; Namespace
(namespace_definition
name: (namespace_name
(name) @module))
(namespace_name
(name) @module)
(relative_name
"namespace" @module.builtin)
; Attributes
(attribute_list) @attribute
; Conditions ( ? : )
(conditional_expression
"?" @keyword.conditional.ternary
":" @keyword.conditional.ternary)
; Directives
(declare_directive
[
"strict_types"
"ticks"
"encoding"
] @variable.parameter)
; Basic tokens
[
(string)
(encapsed_string)
(heredoc_body)
(nowdoc_body)
(shell_command_expression) ; backtick operator: `ls -la`
] @string
(escape_sequence) @string.escape
[
(heredoc_start)
(heredoc_end)
] @label
(nowdoc
"'" @label)
(boolean) @boolean
(null) @constant.builtin
(integer) @number
(float) @number.float
(comment) @comment @spell
(named_label_statement) @label
@@ -0,0 +1,43 @@
((comment) @injection.content
(#set! injection.language "phpdoc"))
(heredoc
(heredoc_body) @injection.content
(heredoc_end) @injection.language
(#set! injection.include-children)
(#downcase! @injection.language))
(nowdoc
(nowdoc_body) @injection.content
(heredoc_end) @injection.language
(#set! injection.include-children)
(#downcase! @injection.language))
; regex
((function_call_expression
function: (_) @_preg_func_identifier
arguments: (arguments
.
(argument
(_
(string_content) @injection.content))))
(#set! injection.language "regex")
(#lua-match? @_preg_func_identifier "^preg_"))
; bash
((function_call_expression
function: (_) @_shell_func_identifier
arguments: (arguments
.
(argument
(_
(string_content) @injection.content))))
(#set! injection.language "bash")
(#any-of? @_shell_func_identifier
"shell_exec" "escapeshellarg" "escapeshellcmd" "exec" "passthru" "proc_open" "shell_exec"
"system"))
(expression_statement
(shell_command_expression
(string_content) @injection.content)
(#set! injection.language "bash"))
+84
View File
@@ -0,0 +1,84 @@
; Scopes
;-------
((class_declaration
name: (name) @local.definition.type) @local.scope
(#set! definition.type.scope "parent"))
((method_declaration
name: (name) @local.definition.method) @local.scope
(#set! definition.method.scope "parent"))
((function_definition
name: (name) @local.definition.function) @local.scope
(#set! definition.function.scope "parent"))
(anonymous_function
(anonymous_function_use_clause
(variable_name
(name) @local.definition.var))) @local.scope
; Definitions
;------------
(simple_parameter
(variable_name
(name) @local.definition.var))
(foreach_statement
(pair
(variable_name
(name) @local.definition.var)))
(foreach_statement
(variable_name
(name) @local.reference
(#set! reference.kind "var"))
(variable_name
(name) @local.definition.var))
(property_declaration
(property_element
(variable_name
(name) @local.definition.field)))
(namespace_use_clause
(qualified_name
(name) @local.definition.type))
; References
;------------
(named_type
(name) @local.reference
(#set! reference.kind "type"))
(named_type
(qualified_name) @local.reference
(#set! reference.kind "type"))
(variable_name
(name) @local.reference
(#set! reference.kind "var"))
(member_access_expression
name: (name) @local.reference
(#set! reference.kind "field"))
(member_call_expression
name: (name) @local.reference
(#set! reference.kind "method"))
(function_call_expression
function: (qualified_name
(name) @local.reference
(#set! reference.kind "function")))
(object_creation_expression
(qualified_name
(name) @local.reference
(#set! reference.kind "type")))
(scoped_call_expression
scope: (qualified_name
(name) @local.reference
(#set! reference.kind "type"))
name: (name) @local.reference
(#set! reference.kind "method"))
@@ -0,0 +1 @@
; inherits php
+25
View File
@@ -0,0 +1,25 @@
[
(mod_item)
(foreign_mod_item)
(function_item)
(struct_item)
(trait_item)
(enum_item)
(impl_item)
(type_item)
(union_item)
(const_item)
(let_declaration)
(loop_expression)
(for_expression)
(while_expression)
(if_expression)
(match_expression)
(call_expression)
(array_expression)
(macro_definition)
(macro_invocation)
(attribute_item)
(block)
(use_declaration)+
] @fold
+531
View File
@@ -0,0 +1,531 @@
; Forked from https://github.com/tree-sitter/tree-sitter-rust
; Copyright (c) 2017 Maxim Sokolov
; Licensed under the MIT license.
; Identifier conventions
(shebang) @keyword.directive
(identifier) @variable
((identifier) @type
(#lua-match? @type "^[A-Z]"))
(const_item
name: (identifier) @constant)
; Assume all-caps names are constants
((identifier) @constant
(#lua-match? @constant "^[A-Z][A-Z%d_]*$"))
; Other identifiers
(type_identifier) @type
(primitive_type) @type.builtin
(field_identifier) @variable.member
(shorthand_field_identifier) @variable.member
(shorthand_field_initializer
(identifier) @variable.member)
(mod_item
name: (identifier) @module)
(self) @variable.builtin
"_" @character.special
(label
[
"'"
(identifier)
] @label)
; Function definitions
(function_item
(identifier) @function)
(function_signature_item
(identifier) @function)
(parameter
[
(identifier)
"_"
] @variable.parameter)
(parameter
(ref_pattern
[
(mut_pattern
(identifier) @variable.parameter)
(identifier) @variable.parameter
]))
(closure_parameters
(_) @variable.parameter)
; Function calls
(call_expression
function: (identifier) @function.call)
(call_expression
function: (scoped_identifier
(identifier) @function.call .))
(call_expression
function: (field_expression
field: (field_identifier) @function.call))
(generic_function
function: (identifier) @function.call)
(generic_function
function: (scoped_identifier
name: (identifier) @function.call))
(generic_function
function: (field_expression
field: (field_identifier) @function.call))
; Assume other uppercase names are enum constructors
((field_identifier) @constant
(#lua-match? @constant "^[A-Z]"))
(enum_variant
name: (identifier) @constant)
; Assume that uppercase names in paths are types
(scoped_identifier
path: (identifier) @module)
(scoped_identifier
(scoped_identifier
name: (identifier) @module))
(scoped_type_identifier
path: (identifier) @module)
(scoped_type_identifier
path: (identifier) @type
(#lua-match? @type "^[A-Z]"))
(scoped_type_identifier
(scoped_identifier
name: (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]"))
[
(crate)
(super)
] @module
(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]"))
; Correct enum constructors
(call_expression
function: (scoped_identifier
"::"
name: (identifier) @constant)
(#lua-match? @constant "^[A-Z]"))
; Assume uppercase names in a match arm are constants.
((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"))
; Macro definitions
"$" @function.macro
(metavariable) @function.macro
(macro_definition
"macro_rules!" @function.macro)
; Attribute macros
(attribute_item
(attribute
(identifier) @function.macro))
(inner_attribute_item
(attribute
(identifier) @function.macro))
(attribute
(scoped_identifier
(identifier) @function.macro .))
; Derive macros (assume all arguments are types)
; (attribute
; (identifier) @_name
; arguments: (attribute (attribute (identifier) @type))
; (#eq? @_name "derive"))
; Function-like macros
(macro_invocation
macro: (identifier) @function.macro)
(macro_invocation
macro: (scoped_identifier
(identifier) @function.macro .))
; Literals
(boolean_literal) @boolean
(integer_literal) @number
(float_literal) @number.float
[
(raw_string_literal)
(string_literal)
] @string
(escape_sequence) @string.escape
(char_literal) @character
; Keywords
[
"use"
"mod"
] @keyword.import
(use_as_clause
"as" @keyword.import)
[
"default"
"impl"
"let"
"move"
"unsafe"
"where"
] @keyword
[
"enum"
"struct"
"union"
"trait"
"type"
] @keyword.type
[
"async"
"await"
"gen"
] @keyword.coroutine
"try" @keyword.exception
[
"ref"
"pub"
"raw"
(mutable_specifier)
"const"
"static"
"dyn"
"extern"
] @keyword.modifier
(lifetime
"'" @keyword.modifier)
(lifetime
(identifier) @attribute)
(lifetime
(identifier) @attribute.builtin
(#any-of? @attribute.builtin "static" "_"))
"fn" @keyword.function
[
"return"
"yield"
] @keyword.return
(type_cast_expression
"as" @keyword.operator)
(qualified_type
"as" @keyword.operator)
(use_list
(self) @module)
(scoped_use_list
(self) @module)
(scoped_identifier
[
(crate)
(super)
(self)
] @module)
(visibility_modifier
[
(crate)
(super)
(self)
] @module)
[
"if"
"else"
"match"
] @keyword.conditional
[
"break"
"continue"
"in"
"loop"
"while"
] @keyword.repeat
"for" @keyword
(for_expression
"for" @keyword.repeat)
; Operators
[
"!"
"!="
"%"
"%="
"&"
"&&"
"&="
"*"
"*="
"+"
"+="
"-"
"-="
".."
"..="
"..."
"/"
"/="
"<"
"<<"
"<<="
"<="
"="
"=="
">"
">="
">>"
">>="
"?"
"@"
"^"
"^="
"|"
"|="
"||"
] @operator
(use_wildcard
"*" @character.special)
(remaining_field_pattern
".." @character.special)
(range_pattern
[
".."
"..="
"..."
] @character.special)
; Punctuation
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
(closure_parameters
"|" @punctuation.bracket)
(type_arguments
[
"<"
">"
] @punctuation.bracket)
(type_parameters
[
"<"
">"
] @punctuation.bracket)
(bracketed_type
[
"<"
">"
] @punctuation.bracket)
(for_lifetimes
[
"<"
">"
] @punctuation.bracket)
[
","
"."
":"
"::"
";"
"->"
"=>"
] @punctuation.delimiter
(attribute_item
"#" @punctuation.special)
(inner_attribute_item
[
"!"
"#"
] @punctuation.special)
(macro_invocation
"!" @function.macro)
(never_type
"!" @type.builtin)
(macro_invocation
macro: (identifier) @_identifier @keyword.exception
"!" @keyword.exception
(#eq? @_identifier "panic"))
(macro_invocation
macro: (identifier) @_identifier @keyword.exception
"!" @keyword.exception
(#contains? @_identifier "assert"))
(macro_invocation
macro: (identifier) @_identifier @keyword.debug
"!" @keyword.debug
(#eq? @_identifier "dbg"))
; Comments
[
(line_comment)
(block_comment)
(outer_doc_comment_marker)
(inner_doc_comment_marker)
] @comment @spell
(line_comment
(doc_comment)) @comment.documentation
(block_comment
(doc_comment)) @comment.documentation
(call_expression
function: (scoped_identifier
path: (identifier) @_regex
(#any-of? @_regex "Regex" "ByteRegexBuilder")
name: (identifier) @_new
(#eq? @_new "new"))
arguments: (arguments
(raw_string_literal
(string_content) @string.regexp)))
(call_expression
function: (scoped_identifier
path: (scoped_identifier
(identifier) @_regex
(#any-of? @_regex "Regex" "ByteRegexBuilder") .)
name: (identifier) @_new
(#eq? @_new "new"))
arguments: (arguments
(raw_string_literal
(string_content) @string.regexp)))
(call_expression
function: (scoped_identifier
path: (identifier) @_regex
(#any-of? @_regex "RegexSet" "RegexSetBuilder")
name: (identifier) @_new
(#eq? @_new "new"))
arguments: (arguments
(array_expression
(raw_string_literal
(string_content) @string.regexp))))
(call_expression
function: (scoped_identifier
path: (scoped_identifier
(identifier) @_regex
(#any-of? @_regex "RegexSet" "RegexSetBuilder") .)
name: (identifier) @_new
(#eq? @_new "new"))
arguments: (arguments
(array_expression
(raw_string_literal
(string_content) @string.regexp))))
+89
View File
@@ -0,0 +1,89 @@
(macro_invocation
macro: [
(scoped_identifier
name: (_) @_macro_name)
(identifier) @_macro_name
]
(token_tree) @injection.content
(#not-any-of? @_macro_name "slint" "html" "json")
(#set! injection.language "rust")
(#set! injection.include-children))
(macro_invocation
macro: [
(scoped_identifier
name: (_) @injection.language)
(identifier) @injection.language
]
(token_tree) @injection.content
(#any-of? @injection.language "slint" "html" "json")
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children))
(macro_definition
(macro_rule
left: (token_tree_pattern) @injection.content
(#set! injection.language "rust")))
(macro_definition
(macro_rule
right: (token_tree) @injection.content
(#set! injection.language "rust")))
([
(line_comment)
(block_comment)
] @injection.content
(#set! injection.language "comment"))
(call_expression
function: (scoped_identifier
path: (identifier) @_regex
(#any-of? @_regex "Regex" "RegexBuilder")
name: (identifier) @_new
(#eq? @_new "new"))
arguments: (arguments
(raw_string_literal
(string_content) @injection.content))
(#set! injection.language "regex"))
(call_expression
function: (scoped_identifier
path: (scoped_identifier
(identifier) @_regex
(#any-of? @_regex "Regex" "RegexBuilder") .)
name: (identifier) @_new
(#eq? @_new "new"))
arguments: (arguments
(raw_string_literal
(string_content) @injection.content))
(#set! injection.language "regex"))
(call_expression
function: (scoped_identifier
path: (identifier) @_regex
(#any-of? @_regex "RegexSet" "RegexSetBuilder")
name: (identifier) @_new
(#eq? @_new "new"))
arguments: (arguments
(array_expression
(raw_string_literal
(string_content) @injection.content)))
(#set! injection.language "regex"))
(call_expression
function: (scoped_identifier
path: (scoped_identifier
(identifier) @_regex
(#any-of? @_regex "RegexSet" "RegexSetBuilder") .)
name: (identifier) @_new
(#eq? @_new "new"))
arguments: (arguments
(array_expression
(raw_string_literal
(string_content) @injection.content)))
(#set! injection.language "regex"))
((block_comment) @injection.content
(#match? @injection.content "/\\*!([a-zA-Z]+:)?re2c")
(#set! injection.language "re2c"))
+98
View File
@@ -0,0 +1,98 @@
; Imports
(extern_crate_declaration
name: (identifier) @local.definition.import)
(use_declaration
argument: (scoped_identifier
name: (identifier) @local.definition.import))
(use_as_clause
alias: (identifier) @local.definition.import)
(use_list
(identifier) @local.definition.import) ; use std::process::{Child, Command, Stdio};
; Functions
(function_item
name: (identifier) @local.definition.function)
(function_item
name: (identifier) @local.definition.method
parameters: (parameters
(self_parameter)))
; Variables
(parameter
pattern: (identifier) @local.definition.var)
(let_declaration
pattern: (identifier) @local.definition.var)
(const_item
name: (identifier) @local.definition.var)
(tuple_pattern
(identifier) @local.definition.var)
(let_condition
pattern: (_
(identifier) @local.definition.var))
(tuple_struct_pattern
(identifier) @local.definition.var)
(closure_parameters
(identifier) @local.definition.var)
(self_parameter
(self) @local.definition.var)
(for_expression
pattern: (identifier) @local.definition.var)
; Types
(struct_item
name: (type_identifier) @local.definition.type)
(enum_item
name: (type_identifier) @local.definition.type)
; Fields
(field_declaration
name: (field_identifier) @local.definition.field)
(enum_variant
name: (identifier) @local.definition.field)
; References
(identifier) @local.reference
((type_identifier) @local.reference
(#set! reference.kind "type"))
((field_identifier) @local.reference
(#set! reference.kind "field"))
; Macros
(macro_definition
name: (identifier) @local.definition.macro)
; Module
(mod_item
name: (identifier) @local.definition.namespace)
; Scopes
[
(block)
(function_item)
(closure_expression)
(while_expression)
(for_expression)
(loop_expression)
(if_expression)
(match_expression)
(match_arm)
(struct_item)
(enum_item)
(impl_item)
] @local.scope
+409
View File
@@ -0,0 +1,409 @@
; functions
(function_signature_item) @function.outer
(function_item) @function.outer
(function_item
body: (block
.
"{"
_+ @function.inner
"}"))
; quantifies as class(es)
(struct_item) @class.outer
(struct_item
body: (field_declaration_list
.
"{"
_+ @class.inner
"}"))
(enum_item) @class.outer
(enum_item
body: (enum_variant_list
.
"{"
_+ @class.inner
"}"))
(union_item) @class.outer
(union_item
body: (field_declaration_list
.
"{"
_+ @class.inner
"}"))
(trait_item) @class.outer
(trait_item
body: (declaration_list
.
"{"
_+ @class.inner
"}"))
(impl_item) @class.outer
(impl_item
body: (declaration_list
.
"{"
_+ @class.inner
"}"))
(mod_item) @class.outer
(mod_item
body: (declaration_list
.
"{"
_+ @class.inner
"}"))
; conditionals
(if_expression
alternative: (_
(_) @conditional.inner)?) @conditional.outer
(if_expression
alternative: (else_clause
(block) @conditional.inner))
(if_expression
condition: (_) @conditional.inner)
(if_expression
consequence: (block) @conditional.inner)
(match_arm
(_)) @conditional.inner
(match_expression) @conditional.outer
; loops
(loop_expression
body: (block
.
"{"
_+ @loop.inner
"}")) @loop.outer
(while_expression
body: (block
.
"{"
_+ @loop.inner
"}")) @loop.outer
(for_expression
body: (block
.
"{"
_+ @loop.inner
"}")) @loop.outer
; blocks
(block
(_)* @block.inner) @block.outer
(unsafe_block
(_)* @block.inner) @block.outer
; calls
(macro_invocation) @call.outer
(macro_invocation
(token_tree
.
"("
_+ @call.inner
")"))
(call_expression) @call.outer
(call_expression
arguments: (arguments
.
"("
_+ @call.inner
")"))
; returns
(return_expression
(_)? @return.inner) @return.outer
; statements
(block
(_) @statement.outer)
; comments
(line_comment) @comment.outer
(block_comment) @comment.outer
; parameter
(parameters
"," @parameter.outer
.
[
(self_parameter)
(parameter)
(type_identifier)
] @parameter.inner @parameter.outer)
(parameters
.
[
(self_parameter)
(parameter)
(type_identifier)
] @parameter.inner @parameter.outer
.
","? @parameter.outer)
; last element, with trailing comma
(parameters
[
(self_parameter)
(parameter)
(type_identifier)
] @parameter.outer
.
"," @parameter.outer .)
(type_parameters
"," @parameter.outer
.
(_) @parameter.inner @parameter.outer)
(type_parameters
.
(_) @parameter.inner @parameter.outer
.
","? @parameter.outer)
; last element, with trailing comma
(type_parameters
(_) @parameter.outer
.
"," @parameter.outer .)
(tuple_pattern
"," @parameter.outer
.
(identifier) @parameter.inner @parameter.outer)
(tuple_pattern
.
(identifier) @parameter.inner @parameter.outer
.
","? @parameter.outer)
; last element, with trailing comma
(tuple_pattern
(identifier) @parameter.outer
.
"," @parameter.outer .)
(tuple_struct_pattern
"," @parameter.outer
.
(identifier) @parameter.inner @parameter.outer)
(tuple_struct_pattern
.
(identifier) @parameter.inner @parameter.outer
.
","? @parameter.outer)
; last element, with trailing comma
(tuple_struct_pattern
(identifier) @parameter.outer
.
"," @parameter.outer .)
(tuple_expression
"," @parameter.outer
.
(_) @parameter.inner @parameter.outer)
(tuple_expression
.
(_) @parameter.inner @parameter.outer
.
","? @parameter.outer)
; last element, with trailing comma
(tuple_expression
(_) @parameter.outer
.
"," @parameter.outer .)
(tuple_type
"," @parameter.outer
.
(_) @parameter.inner @parameter.outer)
(tuple_type
.
(_) @parameter.inner @parameter.outer
.
","? @parameter.outer)
; last element, with trailing comma
(tuple_type
(_) @parameter.outer
.
"," @parameter.outer .)
(struct_item
body: (field_declaration_list
"," @parameter.outer
.
(_) @parameter.inner @parameter.outer))
(struct_item
body: (field_declaration_list
.
(_) @parameter.inner @parameter.outer
.
","? @parameter.outer))
; last element, with trailing comma
(struct_item
body: (field_declaration_list
(_) @parameter.outer
.
"," @parameter.outer .))
(struct_expression
body: (field_initializer_list
"," @parameter.outer
.
(_) @parameter.inner @parameter.outer))
(struct_expression
body: (field_initializer_list
.
(_) @parameter.inner @parameter.outer
.
","? @parameter.outer))
; last element, with trailing comma
(struct_expression
body: (field_initializer_list
(_) @parameter.outer
.
"," @parameter.outer .))
(closure_parameters
"," @parameter.outer
.
(_) @parameter.inner @parameter.outer)
(closure_parameters
.
(_) @parameter.inner @parameter.outer
.
","? @parameter.outer)
; last element, with trailing comma
(closure_parameters
(_) @parameter.outer
.
"," @parameter.outer .)
(arguments
"," @parameter.outer
.
(_) @parameter.inner @parameter.outer)
(arguments
.
(_) @parameter.inner @parameter.outer
.
","? @parameter.outer)
; last element, with trailing comma
(arguments
(_) @parameter.outer
.
"," @parameter.outer .)
(type_arguments
"," @parameter.outer
.
(_) @parameter.inner @parameter.outer)
(type_arguments
.
(_) @parameter.inner @parameter.outer
.
","? @parameter.outer)
; last element, with trailing comma
(type_arguments
(_) @parameter.outer
.
"," @parameter.outer .)
(token_tree
"," @parameter.outer
.
(_) @parameter.inner @parameter.outer)
(token_tree
.
(_) @parameter.inner @parameter.outer
.
","? @parameter.outer)
; last element, with trailing comma
(token_tree
(_) @parameter.outer
.
"," @parameter.outer .)
(scoped_use_list
list: (use_list
"," @parameter.outer
.
(_) @parameter.inner @parameter.outer))
(scoped_use_list
list: (use_list
.
(_) @parameter.inner @parameter.outer
.
","? @parameter.outer))
; last element, with trailing comma
(scoped_use_list
list: (use_list
(_) @parameter.outer
.
"," @parameter.outer .))
[
(integer_literal)
(float_literal)
] @number.inner
(let_declaration
pattern: (_) @assignment.lhs
value: (_) @assignment.inner @assignment.rhs) @assignment.outer
(let_declaration
pattern: (_) @assignment.inner)
(assignment_expression
left: (_) @assignment.lhs
right: (_) @assignment.inner @assignment.rhs) @assignment.outer
(assignment_expression
left: (_) @assignment.inner)
+23
View File
@@ -0,0 +1,23 @@
[
(block)
(switch_expression)
(initializer_list)
(asm_expression)
(multiline_string)
(if_statement)
(while_statement)
(for_statement)
(if_expression)
(else_clause)
(for_expression)
(while_expression)
(if_type_expression)
(function_signature)
(parameters)
(call_expression)
(struct_declaration)
(opaque_declaration)
(enum_declaration)
(union_declaration)
(error_set_declaration)
] @fold
+283
View File
@@ -0,0 +1,283 @@
; Variables
(identifier) @variable
; Parameters
(parameter
name: (identifier) @variable.parameter)
(payload
(identifier) @variable.parameter)
; Types
(parameter
type: (identifier) @type)
((identifier) @type
(#lua-match? @type "^[A-Z_][a-zA-Z0-9_]*"))
(variable_declaration
(identifier) @type
"="
[
(struct_declaration)
(enum_declaration)
(union_declaration)
(opaque_declaration)
])
[
(builtin_type)
"anyframe"
] @type.builtin
; Constants
((identifier) @constant
(#lua-match? @constant "^[A-Z][A-Z_0-9]+$"))
[
"null"
"unreachable"
"undefined"
] @constant.builtin
(field_expression
.
member: (identifier) @constant)
(enum_declaration
(container_field
type: (identifier) @constant))
; Labels
(block_label
(identifier) @label)
(break_label
(identifier) @label)
; Fields
(field_initializer
.
(identifier) @variable.member)
(field_expression
(_)
member: (identifier) @variable.member)
(container_field
name: (identifier) @variable.member)
(initializer_list
(assignment_expression
left: (field_expression
.
member: (identifier) @variable.member)))
; Functions
(builtin_identifier) @function.builtin
(call_expression
function: (identifier) @function.call)
(call_expression
function: (field_expression
member: (identifier) @function.call))
(function_declaration
name: (identifier) @function)
; Modules
(variable_declaration
(identifier) @module
(builtin_function
(builtin_identifier) @keyword.import
(#any-of? @keyword.import "@import" "@cImport")))
; Builtins
[
"c"
"..."
] @variable.builtin
((identifier) @variable.builtin
(#eq? @variable.builtin "_"))
(calling_convention
(identifier) @variable.builtin)
; Keywords
[
"asm"
"defer"
"errdefer"
"test"
"error"
"const"
"var"
] @keyword
[
"struct"
"union"
"enum"
"opaque"
] @keyword.type
[
"async"
"await"
"suspend"
"nosuspend"
"resume"
] @keyword.coroutine
"fn" @keyword.function
[
"and"
"or"
"orelse"
] @keyword.operator
"return" @keyword.return
[
"if"
"else"
"switch"
] @keyword.conditional
[
"for"
"while"
"break"
"continue"
] @keyword.repeat
[
"usingnamespace"
"export"
] @keyword.import
[
"try"
"catch"
] @keyword.exception
[
"volatile"
"allowzero"
"noalias"
"addrspace"
"align"
"callconv"
"linksection"
"pub"
"inline"
"noinline"
"extern"
"comptime"
"packed"
"threadlocal"
] @keyword.modifier
; Operator
[
"="
"*="
"*%="
"*|="
"/="
"%="
"+="
"+%="
"+|="
"-="
"-%="
"-|="
"<<="
"<<|="
">>="
"&="
"^="
"|="
"!"
"~"
"-"
"-%"
"&"
"=="
"!="
">"
">="
"<="
"<"
"&"
"^"
"|"
"<<"
">>"
"<<|"
"+"
"++"
"+%"
"-%"
"+|"
"-|"
"*"
"/"
"%"
"**"
"*%"
"*|"
"||"
".*"
".?"
"?"
".."
] @operator
; Literals
(character) @character
([
(string)
(multiline_string)
] @string
(#set! "priority" 95))
(integer) @number
(float) @number.float
(boolean) @boolean
(escape_sequence) @string.escape
; Punctuation
[
"["
"]"
"("
")"
"{"
"}"
] @punctuation.bracket
[
";"
"."
","
":"
"=>"
"->"
] @punctuation.delimiter
(payload
"|" @punctuation.bracket)
; Comments
(comment) @comment @spell
((comment) @comment.documentation
(#lua-match? @comment.documentation "^//!"))
+10
View File
@@ -0,0 +1,10 @@
((comment) @injection.content
(#set! injection.language "comment"))
; TODO: add when asm is added
; (asm_output_item (string) @injection.content
; (#set! injection.language "asm"))
; (asm_input_item (string) @injection.content
; (#set! injection.language "asm"))
; (asm_clobbers (string) @injection.content
; (#set! injection.language "asm"))
+96
View File
@@ -0,0 +1,96 @@
; Definitions
(function_declaration
name: (identifier) @local.definition.function)
(parameter
name: (identifier) @local.definition.parameter)
(variable_declaration
(identifier) @local.definition.var)
(variable_declaration
(identifier) @local.definition.type
(enum_declaration))
(container_field
type: (identifier) @local.definition.field)
(enum_declaration
(function_declaration
name: (identifier) @local.definition.method))
(variable_declaration
(identifier) @local.definition.type
(struct_declaration))
(struct_declaration
(function_declaration
name: (identifier) @local.definition.method))
(container_field
name: (identifier) @local.definition.field)
(variable_declaration
(identifier) @local.definition.type
(union_declaration))
(union_declaration
(function_declaration
name: (identifier) @local.definition.method))
(payload
(identifier) @local.definition.var)
(block_label
(identifier) @local.definition)
; References
(identifier) @local.reference
(parameter
type: (identifier) @local.reference
(#set! reference.kind "type"))
(pointer_type
(identifier) @local.reference
(#set! reference.kind "type"))
(nullable_type
(identifier) @local.reference
(#set! reference.kind "type"))
(struct_initializer
(identifier) @local.reference
(#set! reference.kind "type"))
(array_type
(_)
(identifier) @local.reference
(#set! reference.kind "type"))
(slice_type
(identifier) @local.reference
(#set! reference.kind "type"))
(field_expression
member: (identifier) @local.reference
(#set! reference.kind "field"))
(call_expression
function: (field_expression
member: (identifier) @local.reference
(#set! reference.kind "function")))
(break_label
(identifier) @local.reference)
[
(for_statement)
(if_statement)
(while_statement)
(function_declaration)
(block)
(source_file)
(enum_declaration)
(struct_declaration)
] @local.scope
+110
View File
@@ -0,0 +1,110 @@
; "Classes"
(variable_declaration
(struct_declaration)) @class.outer
(variable_declaration
(struct_declaration
"struct"
"{"
_+ @class.inner
"}"))
; functions
(function_declaration) @function.outer
(function_declaration
body: (block
.
"{"
_+ @function.inner
"}"))
; loops
(for_statement) @loop.outer
(for_statement
body: (_) @loop.inner)
(while_statement) @loop.outer
(while_statement
body: (_) @loop.inner)
; blocks
(block) @block.outer
(block
"{"
_+ @block.inner
"}")
; statements
(statement) @statement.outer
; parameters
(parameters
"," @parameter.outer
.
(parameter) @parameter.inner @parameter.outer)
(parameters
.
(parameter) @parameter.inner @parameter.outer
.
","? @parameter.outer)
; arguments
(call_expression
function: (_)
arguments: (arguments
"("
"," @parameter.outer
.
(_) @parameter.inner @parameter.outer
")"))
(call_expression
function: (_)
arguments: (arguments
"("
.
(_) @parameter.inner @parameter.outer
.
","? @parameter.outer
")"))
; comments
(comment) @comment.outer
; conditionals
(if_statement) @conditional.outer
(if_statement
condition: (_) @conditional.inner)
(if_statement
body: (_) @conditional.inner)
(switch_expression) @conditional.outer
(switch_expression
"("
(_) @conditional.inner
")")
(switch_expression
"{"
_+ @conditional.inner
"}")
(while_statement
condition: (_) @conditional.inner)
; calls
(call_expression) @call.outer
(call_expression
arguments: (arguments
"("
_+ @call.inner
")"))