refactor: use newly introduced consolidated syntax

This commit is contained in:
TravonteD 2020-06-19 09:59:27 -04:00
parent 772aa4c169
commit 0f836e0602
5 changed files with 197 additions and 135 deletions

View file

@ -29,6 +29,7 @@ Here are some global advices :
- If not, you should consider installing the [tree-sitter cli](https://github.com/tree-sitter/tree-sitter/tree/master/cli), - If not, you should consider installing the [tree-sitter cli](https://github.com/tree-sitter/tree-sitter/tree/master/cli),
you should then be able to open a local playground using `tree-sitter build-wasm && tree-sitter web-ui` within the you should then be able to open a local playground using `tree-sitter build-wasm && tree-sitter web-ui` within the
parsers repo. parsers repo.
- An Example of somewhat complex highlight queries can be found in queries/ruby/highlights.scm (Maintained by @TravonteD)
### Highlights ### Highlights
@ -36,6 +37,7 @@ As languages differ quite a lot, here is a set of captures available to you when
One important thing to note is that many of these capture groups are not supported by `neovim` for now, and will not have any One important thing to note is that many of these capture groups are not supported by `neovim` for now, and will not have any
effect on highlighting. We will work on improving highlighting in the near future though. effect on highlighting. We will work on improving highlighting in the near future though.
#### Misc #### Misc
`@comment` `@comment`
`@error` for error `(ERROR)` nodes. `@error` for error `(ERROR)` nodes.

View file

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

View file

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

View file

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

View file

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