Merge branch 'master' into rust-queries

This commit is contained in:
Thomas Vigouroux 2020-07-07 13:28:24 +02:00 committed by GitHub
commit 8a76b16814
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 2887 additions and 1109 deletions

110
queries/bash/highlights.scm Normal file
View file

@ -0,0 +1,110 @@
[
"("
")"
"{"
"}"
"["
"]"
] @punctuation.bracket
[
";"
";;"
(heredoc_start)
] @punctuation.delimiter
[
">"
"<"
"&"
"&&"
"|"
"||"
"="
"=="
"!="
] @operator
[
(string)
(raw_string)
(heredoc_body)
] @string
[
"if"
"then"
"else"
"elif"
"fi"
"case"
"in"
"esac"
] @conditional
[
"for"
"do"
"done"
"while"
] @repeat
[
"declare"
"export"
"local"
"readonly"
"unset"
] @keyword
[
(special_variable_name)
("$" (special_variable_name))
] @constant
((word) @constant
(#match? @constant "SIG(INT|TERM|QUIT|TIN|TOU|STP|HUP)"))
((word) @boolean
(#match? @boolean "true|false"))
((word) @number
(#match? @number "^\d*$"))
(comment) @comment
(test_operator) @string.
(command_substitution
[ "$(" ")" ] @punctuation.bracket)
(function_definition
name: (word) @function)
(command_name (word)) @function
(command
argument: [
(word) @parameter
((word) @number
(#match? @number "^\d*$"))
(concatenation (word) @parameter)
])
(file_redirect
descriptor: (file_descriptor) @operator
destination: (word) @parameter)
("$" (variable_name)) @identifier
(expansion
[ "${" "}" ] @punctuation.bracket)
(variable_name) @identifier
(case_item
value: (word) @parameter)
(concatenation (word) @parameter)

View file

@ -1,52 +1,79 @@
"break" @keyword
"case" @conditional
"const" @keyword
"continue" @repeat
"default" @keyword
"do" @repeat
"else" @conditional
"enum" @keyword
"extern" @keyword
"for" @repeat
"if" @conditional
"inline" @keyword
"return" @keyword
"sizeof" @keyword
"static" @keyword
"struct" @keyword
"switch" @keyword
"typedef" @keyword
"union" @keyword
"volatile" @keyword
"while" @repeat
[
"const"
"default"
"enum"
"extern"
"inline"
"return"
"sizeof"
"static"
"struct"
"typedef"
"union"
"volatile"
] @keyword
[
"while"
"for"
"do"
"continue"
"break"
] @repeat
[
"if"
"else"
"case"
"switch"
] @conditional
(conditional_expression [ "?" ":" ] @conditional)
"#define" @constant.macro
"#else" @keyword
"#endif" @keyword
"#if" @keyword
"#ifdef" @keyword
"#ifndef" @keyword
"#include" @keyword
(preproc_directive) @keyword
[
"#if"
"#ifdef"
"#ifndef"
"#else"
"#elif"
"#endif"
"#include"
(preproc_directive)
] @keyword
"--" @operator
"-" @operator
"-=" @operator
"->" @operator
"!=" @operator
"*" @operator
"&" @operator
"&&" @operator
"+" @operator
"++" @operator
"+=" @operator
"<" @operator
"==" @operator
">" @operator
"||" @operator
[
"--"
"-"
"->"
"!="
"*"
"/"
"&"
"&&"
"+"
"++"
"<"
"<="
"=="
"="
"~"
">"
">="
"!"
"||"
"." @delimiter
";" @delimiter
"-="
"+="
"*="
"/="
"|="
"&="
] @operator
[ "." ";" ":" "," ] @punctuation.delimiter
[ "(" ")" "[" "]" "{" "}"] @punctuation.bracket
(string_literal) @string
(system_lib_string) @string
@ -64,6 +91,8 @@
declarator: (identifier) @function)
(preproc_function_def
name: (identifier) @function.macro)
(preproc_arg) @function.macro
; TODO (preproc_arg) @embedded
(field_identifier) @property
(statement_identifier) @label
@ -71,7 +100,19 @@
(primitive_type) @type
(sized_type_specifier) @type
((identifier) @type
(#match? @type "^[A-Z]"))
((identifier) @constant
(match? @constant "^[A-Z][A-Z\\d_]+$"))
(#match? @constant "^[A-Z][A-Z0-9_]+$"))
(comment) @comment
;; Parameters
(parameter_list
(parameter_declaration) @parameter)
(preproc_params
(identifier)) @parameter
(ERROR) @error

View file

@ -17,7 +17,7 @@
(declaration
declarator: (identifier) @definition.var)
(enum_specifier
name: (*) @definition.type
name: (_) @definition.type
(enumerator_list
(enumerator name: (identifier) @definition.var)))
@ -31,8 +31,11 @@
(identifier) @reference
;; Scope
(for_statement) @scope
(if_statement) @scope
(while_statement) @scope
(translation_unit) @scope
(function_definition) @scope
[
(for_statement)
(if_statement)
(while_statement)
(translation_unit)
(function_definition)
(compound_statement) ; a block in curly braces
] @scope

103
queries/cpp/highlights.scm Normal file
View file

@ -0,0 +1,103 @@
((identifier) @field
(#match? @field "^_"))
((identifier) @field
(#match? @field "^m_"))
((identifier) @field
(#match? @field "_$"))
;(field_expression) @parameter ;; How to highlight this?
(template_function
name: (identifier) @function)
(template_method
name: (field_identifier) @method)
(template_function
name: (scoped_identifier
name: (identifier) @function))
(namespace_identifier) @constant
((namespace_identifier) @type
(#match? @type "^[A-Z]"))
((namespace_identifier) @constant
(#match? @constant "^[A-Z][A-Z_0-9]*$"))
(destructor_name
name: (_) @function)
(function_declarator
declarator: (scoped_identifier
name: (identifier) @function))
((function_declarator
declarator: (scoped_identifier
name: (identifier) @constructor))
(#match? @constructor "^[A-Z]"))
(call_expression
function: (scoped_identifier
name: (identifier) @function))
(call_expression
function: (field_expression
field: (field_identifier) @function))
((call_expression
function: (scoped_identifier
name: (identifier) @constructor))
(#match? @constructor "^[A-Z]"))
((call_expression
function: (field_expression
field: (field_identifier) @constructor))
(#match? @constructor "^[A-Z]"))
;; constructing a type in a intizializer list: Constructor (): **SuperType (1)**
((field_initializer
(field_identifier) @constructor
(argument_list))
(#match? @constructor "^[A-Z]"))
; Constants
(this) @constant.builtin
(nullptr) @constant
(true) @boolean
(false) @boolean
; Keywords
[
"try"
"catch"
"noexcept"
"throw"
] @exception
[
"class"
"constexpr"
"delete"
"explicit"
"final"
"friend"
"mutable"
"namespace"
"new"
"override"
"private"
"protected"
"public"
"template"
"typename"
"using"
"virtual"
(auto)
] @keyword
"::" @operator

51
queries/cpp/locals.scm Normal file
View file

@ -0,0 +1,51 @@
;; Class / struct defintions
(class_specifier) @scope
(struct_specifier) @scope
(reference_declarator
(identifier) @definition.var)
(struct_specifier
name: (type_identifier) @definition.type)
(struct_specifier
name: (scoped_type_identifier
name: (type_identifier) @definition.type))
(class_specifier
name: (type_identifier) @definition.type)
(class_specifier
name: (scoped_type_identifier
name: (type_identifier) @definition.type))
;; Function defintions
(template_function
name: (identifier) @definition.function) @scope
(template_method
name: (field_identifier) @definition.method) @scope
(template_function
name: (scoped_identifier
name: (identifier) @definition.function)) @scope
(function_declarator
declarator: (scoped_identifier
name: (type_identifier) @definition.function)) @scope
(field_declaration
declarator: (function_declarator
(field_identifier) @definition.method))
(lambda_expression) @scope
;; Control structures
(try_statement
body: (_) @scope)
(catch_clause) @scope
(destructor_name
name: (_) @constructor)

View file

@ -1,72 +1,91 @@
"@media" @keyword
"@import" @include
"@charset" @keyword
"@namespace" @keyword
"@supports" @keyword
"@keyframes" @keyword
(at_keyword) @keyword
(to) @keyword
(from) @keyword
(important) @keyword
[
"@media"
"@import"
"@charset"
"@namespace"
"@supports"
"@keyframes"
(at_keyword)
(to)
(from)
(important)
] @keyword
(comment) @comment
(tag_name) @type
(nesting_selector) @type
(universal_selector) @type
[
(tag_name)
(nesting_selector)
(universal_selector)
] @type
(function_name) @function
"~" @operator
">" @operator
"+" @operator
"-" @operator
"*" @operator
"/" @operator
"=" @operator
"^=" @operator
"|=" @operator
"~=" @operator
"$=" @operator
"*=" @operator
[
"~"
">"
"+"
"-"
"*"
"/"
"="
"^="
"|="
"~="
"$="
"*="
"and"
"or"
"not"
"only"
] @operator
"and" @operator
"or" @operator
"not" @operator
"only" @operator
(attribute_selector (plain_value) @string)
(pseudo_element_selector (tag_name) @property)
(pseudo_class_selector (class_name) @property)
(class_name) @property
(id_name) @property
(namespace_name) @property
(property_name) @property
(feature_name) @property
(attribute_name) @property
[
(class_name)
(id_name)
(namespace_name)
(property_name)
(feature_name)
(attribute_name)
] @property
((property_name) @type
(#match? @type "^--"))
(#match? @type "^--"))
((plain_value) @type
(#match? @type "^--"))
(#match? @type "^--"))
(string_value) @string
(color_value) @string
(identifier) @string
[
(string_value)
(color_value)
(identifier)
(unit)
] @string
(integer_value) @number
(float_value) @number
(unit) @string
[
(integer_value)
(float_value)
] @number
"#" @punctuation.delimiter
"," @punctuation.delimiter
"." @punctuation.delimiter
":" @punctuation.delimiter
"::" @punctuation.delimiter
";" @punctuation.delimiter
"{" @punctuation.bracket
")" @punctuation.bracket
"(" @punctuation.bracket
"}" @punctuation.bracket
[
"#"
","
"."
":"
"::"
";"
] @punctuation.delimiter
[
"{"
")"
"("
"}"
] @punctuation.bracket
(ERROR) @error

View file

@ -8,8 +8,9 @@
"=" @operator
"<" @punctuation.bracket
">" @punctuation.bracket
"</" @punctuation.bracket
"/>" @punctuation.bracket
[
"<"
">"
"</"
"/>"
] @punctuation.bracket

214
queries/java/highlights.scm Normal file
View file

@ -0,0 +1,214 @@
; CREDITS @maxbrunsfeld (maxbrunsfeld@gmail.com)
; Methods
(method_declaration
name: (identifier) @method)
(method_invocation
name: (identifier) @method)
(super) @function.builtin
; Parameters
(formal_parameter
name: (identifier) @parameter)
;; Lambda parameter
(inferred_parameters (identifier) @parameter) ; (x,y) -> ...
(lambda_expression
parameters: (identifier) @parameter) ; x -> ...
; Annotations
(annotation
name: (identifier) @attribute)
(marker_annotation
name: (identifier) @attribute)
; Operators
[
"@"
"+"
"?"
":"
"++"
"-"
"--"
"&"
"&&"
"|"
"||"
"!="
"=="
"*"
"/"
"%"
"<"
"<="
">"
">="
"="
"-="
"+="
"*="
"/="
"%="
"->"
"^"
"^="
"&="
"|="
"~"
">>"
">>>"
"<<"
"::"
] @operator
; Types
(interface_declaration
name: (identifier) @type)
(class_declaration
name: (identifier) @type)
(enum_declaration
name: (identifier) @type)
(constructor_declaration
name: (identifier) @type)
(type_identifier) @type
((field_access
object: (identifier) @type)
(#match? @type "^[A-Z]"))
((scoped_identifier
scope: (identifier) @type)
(#match? @type "^[A-Z]"))
[
(boolean_type)
(integral_type)
(floating_point_type)
(void_type)
] @type.builtin
; Variables
((identifier) @constant
(#match? @constant "^_*[A-Z][A-Z\d_]+"))
; Literals
[
(hex_integer_literal)
(decimal_integer_literal)
(octal_integer_literal)
(binary_integer_literal)
] @number
[
(decimal_floating_point_literal)
(hex_floating_point_literal)
] @float
(character_literal) @character
(string_literal) @string
(null_literal) @constant.builtin
(comment) @comment
[
(true)
(false)
] @boolean
; Keywords
[
"abstract"
"assert"
"break"
"catch"
"class"
"continue"
"default"
"enum"
"exports"
"extends"
"final"
"finally"
"implements"
"instanceof"
"interface"
"module"
"native"
"new"
"open"
"opens"
"package"
"private"
"protected"
"provides"
"public"
"requires"
"return"
"static"
"strictfp"
"synchronized"
"throw"
"throws"
"to"
"transient"
"transitive"
"try"
"uses"
"volatile"
"with"
] @keyword
; Conditionals
[
"if"
"else"
"switch"
"case"
] @conditional
;
[
"for"
"while"
"do"
] @repeat
; Includes
"import" @include
"package" @include
; Punctuation
[
";"
"."
","
] @punctuation.delimiter
[
"["
"]"
"{"
"}"
"("
")"
] @punctuation.bracket

10
queries/java/locals.scm Normal file
View file

@ -0,0 +1,10 @@
; CREDITS @maxbrunsfeld (maxbrunsfeld@gmail.com)
(class_declaration
name: (identifier) @name) @class
(method_declaration
name: (identifier) @name) @method
(method_invocation
name: (identifier) @name) @call

View file

@ -0,0 +1,190 @@
; Types
; Javascript
; Special identifiers
;--------------------
((identifier) @constant
(#match? @constant "^[A-Z_][A-Z\\d_]+$"))
((shorthand_property_identifier) @constant
(#match? @constant "^[A-Z_][A-Z\\d_]+$"))
((identifier) @constructor
(#match? @constructor "^[A-Z]"))
((identifier) @variable.builtin
(#match? @variable.builtin "^(arguments|module|console|window|document)$"))
((identifier) @function.builtin
(#eq? @function.builtin "require"))
; Function and method definitions
;--------------------------------
(function
name: (identifier) @function)
(function_declaration
name: (identifier) @function)
(method_definition
name: (property_identifier) @function.method)
(pair
key: (property_identifier) @function.method
value: (function))
(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))
(variable_declarator
name: (identifier) @function
value: (arrow_function))
(variable_declarator
name: (identifier) @function
value: (function))
(assignment_expression
left: (identifier) @function
right: (arrow_function))
(assignment_expression
left: (identifier) @function
right: (function))
; Function and method calls
;--------------------------
(call_expression
function: (identifier) @function)
(call_expression
function: (member_expression
property: (property_identifier) @function.method))
; Variables
;----------
(formal_parameters (identifier) @variable.parameter)
(identifier) @variable
; Properties
;-----------
(property_identifier) @property
; Literals
;---------
(this) @variable.builtin
(super) @variable.builtin
(true) @boolean
(false) @boolean
(null) @constant.builtin
(comment) @comment
(string) @string
(regex) @string.special
(template_string) @string
(number) @number
; Punctuation
;------------
(template_substitution
"${" @punctuation.special
"}" @punctuation.special) @embedded
";" @punctuation.delimiter
"." @punctuation.delimiter
"," @punctuation.delimiter
"--" @operator
"-" @operator
"-=" @operator
"&&" @operator
"+" @operator
"++" @operator
"+=" @operator
"<" @operator
"<<" @operator
"=" @operator
"==" @operator
"===" @operator
"=>" @operator
">" @operator
">>" @operator
"||" @operator
"??" @operator
"(" @punctuation.bracket
")" @punctuation.bracket
"[" @punctuation.bracket
"]" @punctuation.bracket
"{" @punctuation.bracket
"}" @punctuation.bracket
; Keywords
;----------
[
"if"
"else"
"switch"
"case"
"default"
] @conditional
[
"import"
"from"
"as"
] @include
[
"for"
"of"
"do"
"while"
"continue"
] @repeat
[
"async"
"await"
"break"
"catch"
"class"
"const"
"debugger"
"delete"
"export"
"extends"
"finally"
"function"
"get"
"in"
"instanceof"
"let"
"new"
"return"
"set"
"static"
"switch"
"target"
"throw"
"try"
"typeof"
"var"
"void"
"with"
"yield"
] @keyword

View file

@ -0,0 +1,38 @@
; Scopes
;-------
(statement_block) @scope
(function) @scope
(arrow_function) @scope
(function_declaration) @scope
(method_definition) @scope
; Definitions
;------------
(formal_parameters
(identifier) @definition)
(formal_parameters
(object_pattern
(identifier) @definition))
(formal_parameters
(object_pattern
(shorthand_property_identifier) @definition))
(formal_parameters
(array_pattern
(identifier) @definition))
(variable_declarator
name: (identifier) @definition)
(import_specifier
(identifier) @definition)
; References
;------------
(identifier) @reference

View file

@ -0,0 +1,13 @@
(true) @boolean
(false) @boolean
(null) @constant.builtin
(number) @number
(pair key: (string) @label)
(pair value: (string) @string)
(string_content (escape_sequence) @string.escape)
(ERROR) @error
"," @punctuation.delimiter
"[" @punctuation.bracket
"]" @punctuation.bracket
"{" @punctuation.bracket
"}" @punctuation.bracket

View file

@ -2,57 +2,70 @@
;;; Builtins
;; Keywords
"local" @keyword
"if" @conditional
"then" @conditional
"else" @conditional
"elseif" @conditional
"end" @keyword
"return" @keyword
"do" @repeat
"while" @repeat
"repeat" @repeat
"for" @repeat
(break_statement) @keyword
"goto" @keyword
[
"if"
"then"
"else"
"elseif"
] @conditional
[
"do"
"while"
"repeat"
"for"
"in"
] @repeat
[
"local"
"end"
"return"
(break_statement)
"goto"
] @keyword
;; Operators
"~=" @operator
"==" @operator
"<=" @operator
">=" @operator
"not" @operator
"and" @operator
"or" @operator
"<" @operator
">" @operator
[
"~="
"=="
"<="
">="
"not"
"and"
"or"
"<"
">"
"+"
"-"
"%"
"/"
"//"
"*"
"^"
"&"
"~"
"|"
">>"
"<<"
".."
"#"
] @operator
"+" @operator
"-" @operator
"%" @operator
"/" @operator
"//" @operator
"*" @operator
"^" @operator
"&" @operator
"~" @operator
"|" @operator
">>" @operator
"<<" @operator
".." @operator
"#" @operator
;; Constants
(false) @boolean
(true) @boolean
[
(false)
(true)
] @boolean
(nil) @constant.builtin
(spread) @constant ;; "..."
;; Nodes
(function "function" @function "end" @function)
(function_definition "function" @function "end" @function)
(local_function "function" @function "end" @function)
(table "{" @constructor "}" @constructor)
(_ "function" @function "end" @function) ;; Any node that has both funtion and end in it
(table ["{" "}"] @constructor)
(comment) @comment
(string) @string
(number) @number

View file

@ -12,6 +12,8 @@
(parameters (identifier) @definition.var)))
((function
(parameters (identifier) @definition.var)))
((function_definition
(parameters (identifier) @definition.var)))
;; Loops
((loop_expression

View file

@ -1,33 +1,38 @@
;; From tree-sitter-python licensed under MIT License
; Copyright (c) 2016 Max Brunsfeld
; Reset highlighing in f-string interpolations
(interpolation) @Normal
; Identifier naming conventions
((import_from_statement
name: (dotted_name
(identifier)) @type)
(match? @type "^[A-Z]"))
((identifier) @type
(match? @type "^[A-Z]"))
((identifier) @constant
(match? @constant "^[A-Z][A-Z_]*$"))
(match? @constant "^[A-Z][A-Z_0-9]*$"))
((identifier) @constant.builtin
(match? @constant.builtin "^__[a-zA-Z0-9_]*__$"))
; Function calls
(decorator) @function
((decorator (dotted_name (identifier) @function))
(match? @function "^([A-Z])@!.*$"))
(call
function: (identifier) @function)
(call
function: (attribute
attribute: (identifier) @method))
(call
function: (identifier) @function)
((call
function: (identifier) @constructor)
(match? @constructor "^[A-Z]"))
((call
(identifier) @constructor)
function: (attribute
attribute: (identifier) @constructor))
(match? @constructor "^[A-Z]"))
;; Builtin functions
@ -43,10 +48,9 @@
(function_definition
name: (identifier) @function)
(identifier) @variable
(attribute attribute: (identifier) @property)
(type (identifier) @type)
((call
((call
function: (identifier) @isinstance
arguments: (argument_list
(*)
@ -55,7 +59,7 @@
; Normal parameters
(parameters
(identifier) @parameter)
(identifier) @parameter)
; Default parameters
(keyword_argument
name: (identifier) @parameter)
@ -65,17 +69,16 @@
; Variadic parameters *args, **kwargs
(parameters
(list_splat ; *args
(identifier) @parameter))
(identifier) @parameter))
(parameters
(dictionary_splat ; **kwargs
(identifier) @parameter))
(identifier) @parameter))
; Literals
(none) @constant.builtin
(true) @boolean
(false) @boolean
[(true) (false)] @boolean
((identifier) @constant.builtin
(match? @constant.builtin "self"))
@ -84,126 +87,104 @@
(comment) @comment
(string) @string
(escape_sequence) @escape
(escape_sequence) @string.escape
; Tokens
[
"-"
"-="
":="
"!="
"*"
"**"
"**="
"*="
"/"
"//"
"//="
"/="
"&"
"%"
"%="
"^"
"+"
"+="
"<"
"<<"
"<="
"<>"
"="
"=="
">"
">="
">>"
"|"
"~"
"and"
"in"
"is"
"not"
"or"
] @operator
; Keywords
[
"assert"
"async"
"await"
"class"
"def"
"del"
"except"
"exec"
"finally"
"global"
"lambda"
"nonlocal"
"pass"
"print"
"raise"
"return"
"try"
"with"
"yield"
] @keyword
[ "as" "from" "import"] @include
[ "if" "elif" "else" ] @conditional
[ "for" "while" "break" "continue" ] @repeat
[ "(" ")" "[" "]" "{" "}"] @punctuation.bracket
(interpolation
"{" @punctuation.special
"}" @punctuation.special) @embedded
; Tokens
[ "," "." ":" ] @punctuation.delimiter
"-" @operator
"->" @operator
"-=" @operator
"!=" @operator
"*" @operator
"**" @operator
"**=" @operator
"*=" @operator
"/" @operator
"//" @operator
"//=" @operator
"/=" @operator
"&" @operator
"%" @operator
"%=" @operator
"^" @operator
"+" @operator
"+=" @operator
"<" @operator
"<<" @operator
"<=" @operator
"<>" @operator
"=" @operator
"==" @operator
">" @operator
">=" @operator
">>" @operator
"|" @operator
"~" @operator
"and" @operator
"in" @operator
"is" @operator
"not" @operator
"or" @operator
; Keywords
"as" @include
"assert" @keyword
"async" @keyword
"await" @keyword
"break" @repeat
"class" @keyword
"continue" @repeat
"def" @keyword
"del" @keyword
"elif" @conditional
"else" @conditional
"except" @keyword
"exec" @keyword
"finally" @keyword
"for" @repeat
"from" @include
"global" @keyword
"if" @conditional
"import" @include
"lambda" @keyword
"nonlocal" @keyword
"pass" @keyword
"print" @keyword
"raise" @keyword
"return" @keyword
"try" @keyword
"while" @repeat
"with" @keyword
"yield" @keyword
; Additions for nvim-treesitter
"(" @punctuation.bracket
")" @punctuation.bracket
"[" @punctuation.bracket
"]" @punctuation.bracket
"," @punctuation.delimiter
"." @punctuation.delimiter
":" @punctuation.delimiter
; Class definitions
(class_definition
name: (identifier) @type)
(class_definition
superclasses: (argument_list
superclasses: (argument_list
(identifier) @type))
(attribute
((attribute
attribute: (identifier) @field)
((attribute
attribute: (identifier) @constant)
(match? @constant "^[A-Z][A-Z_]*$"))
((attribute
attribute: (identifier) @type)
(match? @type "^[A-Z][a-z_]+"))
((attribute
object: (identifier) @type)
(match? @type "^[A-Z][a-z_]+"))
(class_definition
body: (block
(expression_statement
(assignment
left: (expression_list
(identifier) @field)))))
(match? @field "^([A-Z])@!.*$"))
((class_definition
body: (block
(expression_statement
(assignment
left: (expression_list
(identifier) @constant)))))
(match? @constant "^[A-Z][A-Z_]*$"))
(identifier) @field)))))
(match? @field "^([A-Z])@!.*$"))
;; Error
(ERROR) @error

View file

@ -30,12 +30,8 @@
; Function defines function and scope
(function_definition
name: (identifier) @definition.function) @scope
;; Should be extended to when syntax supported
;(function_definition
;name: (identifier) @definition.function
;body: (block (expression_statement (string) @definition.function.doc)?)) @scope
name: (identifier) @definition.function
body: (block (expression_statement (string) @definition.doc)?)) @scope
(class_definition

View file

@ -1,32 +1,41 @@
; Keywords
"alias" @keyword
"and" @keyword
"begin" @keyword
"break" @keyword
"case" @conditional
"class" @keyword
"def" @keyword
"do" @keyword
"else" @conditional
"elsif" @conditional
"end" @keyword
"ensure" @keyword
"for" @repeat
"if" @conditional
"in" @keyword
"module" @keyword
"next" @keyword
"or" @keyword
"rescue" @keyword
"retry" @keyword
"return" @keyword
"then" @keyword
"unless" @conditional
"until" @repeat
"when" @conditional
"while" @repeat
"yield" @keyword
[
"alias"
"and"
"begin"
"break"
"class"
"def"
"do"
"end"
"ensure"
"in"
"module"
"next"
"or"
"rescue"
"retry"
"return"
"then"
"yield"
] @keyword
[
"case"
"else"
"elsif"
"if"
"unless"
"when"
] @conditional
[
"for"
"until"
"while"
] @repeat
((identifier) @keyword
(#match? @keyword "^(private|protected|public)$"))
@ -39,32 +48,45 @@
"defined?" @function
(call
receiver: (constant) @constant)
[
receiver: (constant) @constant
method: [
(identifier)
(constant)
] @function
])
(method_call
receiver: (constant) @constant)
(call
method: (identifier) @function)
(method_call
method: (identifier) @function)
(call
method: (constant) @function)
(method_call
method: (constant) @function)
[
receiver: (constant) @constant
method: [
(identifier)
(constant)
] @function
])
; Function definitions
(alias (identifier) @function)
(setter (identifier) @function)
(method name: (identifier) @function)
(method name: (constant) @constant)
(method name: [
(identifier) @function
(constant) @constant
])
(singleton_method name: [
(identifier) @function
(constant) @constant
])
(class name: (constant) @constant)
(singleton_method name: (identifier) @function)
(singleton_method name: (constant) @constant)
; Identifiers
(class_variable) @label
(instance_variable) @label
[
(class_variable)
(instance_variable)
] @label
((identifier) @constant.builtin
(#match? @constant.builtin "^__(FILE|LINE|ENCODING)__$"))
@ -74,8 +96,10 @@
(constant) @constant
(self) @constant.builtin
(super) @constant.builtin
[
(self)
(super)
] @constant.builtin
(method_parameters (identifier) @parameter)
(lambda_parameters (identifier) @parameter)
@ -93,22 +117,31 @@
; Literals
(string) @string
(bare_string) @string
(bare_symbol) @constant
(subshell) @string
(heredoc_beginning) @constant
(heredoc_body) @string
(heredoc_end) @constant
(symbol) @constant
[
(string)
(bare_string)
(subshell)
(heredoc_body)
] @string
[
(bare_symbol)
(heredoc_beginning)
(heredoc_end)
(symbol)
] @constant
(pair key: (symbol) ":" @constant)
(regex) @string.regex
(escape_sequence) @string.escape
(integer) @number
(float) @float
(nil) @boolean
(true) @boolean
(false) @boolean
[
(nil)
(true)
(false)
] @boolean
(interpolation
"#{" @punctuation.bracket
@ -118,25 +151,31 @@
; Operators
"=" @operator
"=>" @operator
"->" @operator
"+" @operator
"-" @operator
"*" @operator
"/" @operator
[
"="
"=>"
"->"
"+"
"-"
"*"
"/"
] @operator
"," @punctuation.delimiter
";" @punctuation.delimiter
"." @punctuation.delimiter
[
","
";"
"."
] @punctuation.delimiter
"(" @punctuation.bracket
")" @punctuation.bracket
"[" @punctuation.bracket
"]" @punctuation.bracket
"{" @punctuation.bracket
"}" @punctuation.bracket
"%w(" @punctuation.bracket
"%i(" @punctuation.bracket
[
"("
")"
"["
"]"
"{"
"}"
"%w("
"%i("
] @punctuation.bracket
(ERROR) @error

View file

@ -24,8 +24,10 @@
((method) @scope
(set! scope-inherits false))
(block) @scope
(do_block) @scope
[
(block)
(do_block)
] @scope
(method_parameters (identifier) @definition.function)
(lambda_parameters (identifier) @definition.function)

View file

@ -0,0 +1,27 @@
[
"abstract"
"declare"
"enum"
"export"
"implements"
"interface"
"keyof"
"namespace"
"private"
"protected"
"public"
"type"
] @keyword
(readonly) @keyword
(type_identifier) @type
(predefined_type) @type.builtin
(type_arguments
"<" @punctuation.bracket
">" @punctuation.bracket)
; Variables
(required_parameter (identifier) @variable.parameter)
(optional_parameter (identifier) @variable.parameter)

View file

@ -0,0 +1,2 @@
(required_parameter (identifier) @definition)
(optional_parameter (identifier) @definition)