Skip to content

Commit

Permalink
feat: include queries
Browse files Browse the repository at this point in the history
  • Loading branch information
ObserverOfTime committed Mar 6, 2024
1 parent 4aff2e3 commit 7c8d2f2
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 5 deletions.
6 changes: 6 additions & 0 deletions bindings/rust/lib.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"binding.gyp",
"types/dsl.d.ts",
"bindings/node/*",
"queries/*",
"queries/**",
"src/**"
],
"dependencies": {
Expand All @@ -41,6 +41,8 @@
{
"scope": "source.query",
"injection-regex": "^query$",
"highlights": "queries/query/highlights.scm",
"injections": "queries/query/injections.scm",
"file-types": [
"scm"
]
Expand Down
6 changes: 6 additions & 0 deletions queries/query/folds.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
(named_node)
(predicate)
(grouping)
(list)
] @fold
87 changes: 87 additions & 0 deletions queries/query/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
(string) @string

(escape_sequence) @string.escape

(capture
(identifier) @type)

(anonymous_node
(identifier) @string)

(predicate
name: (identifier) @function.call)

(named_node
name: (identifier) @variable)

(field_definition
name: (identifier) @property)

(negated_field
"!" @operator
(identifier) @property)

(comment) @comment @spell

(quantifier) @operator

(predicate_type) @punctuation.special

"." @operator

[
"["
"]"
"("
")"
] @punctuation.bracket

":" @punctuation.delimiter

[
"@"
"#"
] @punctuation.special

"_" @constant

((parameters
(identifier) @number)
(#match? @number "^[-+]?[0-9]+(.[0-9]+)?$"))

((program
.
(comment)*
.
(comment) @keyword.import)
(#lua-match? @keyword.import "^;+ *inherits *:"))

((program
.
(comment)*
.
(comment) @keyword.directive)
(#lua-match? @keyword.directive "^;+ *extends *$"))

((comment) @keyword.directive
(#lua-match? @keyword.directive "^;+%s*format%-ignore%s*$"))

((predicate
name: (identifier) @_name
parameters:
(parameters
(string
"\"" @string
"\"" @string) @string.regexp))
(#any-of? @_name "match" "not-match" "vim-match" "not-vim-match" "lua-match" "not-lua-match"))

((predicate
name: (identifier) @_name
parameters:
(parameters
(string
"\"" @string
"\"" @string) @string.regexp
.
(string) .))
(#any-of? @_name "gsub" "not-gsub"))
31 changes: 31 additions & 0 deletions queries/query/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
((predicate
name: (identifier) @_name
parameters:
(parameters
(string) @injection.content))
(#any-of? @_name "match" "not-match" "vim-match" "not-vim-match")
(#set! injection.language "regex")
(#offset! @injection.content 0 1 0 -1))

((predicate
name: (identifier) @_name
parameters:
(parameters
(string) @injection.content))
(#any-of? @_name "lua-match" "not-lua-match")
(#set! injection.language "luap")
(#offset! @injection.content 0 1 0 -1))

((predicate
name: (identifier) @_name
parameters:
(parameters
(string) @injection.content
.
(string) .))
(#any-of? @_name "gsub" "not-gsub")
(#set! injection.language "luap")
(#offset! @injection.content 0 1 0 -1))

((comment) @injection.content
(#set! injection.language "comment"))
6 changes: 2 additions & 4 deletions test/corpus/statements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,8 @@ Lists
Predicates
================================================================================

(
(identifier) @v
(#eq? @v "test" local)
)
((identifier) @v
(#eq? @v "test" local))

--------------------------------------------------------------------------------

Expand Down
51 changes: 51 additions & 0 deletions test/highlight/statements.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
(program)
; <- @punctuation.bracket
; ^ @variable
; ^ @punctuation.bracket

";"
; <- @string

(node _ @wildcard)
; ^ @punctuation.special
; ^ @type

name: (identifier)
; <- @property
; ^ @punctuation.delimiter

(program
name: (_))
; ^ @constant

(program
name: _)
; ^ @constant

(program
field: (identifier) @capture
!negated-field)
; ^ @operator
; ^ @property

(program
(identifier)+)
; ^ @operator

((node) [(node) "test"])
; ^ @punctuation.bracket
; ^ @punctuation.bracket

((identifier) @v
(#eq? @v "test" local))
; ^ @punctuation.special
; ^ @function.call
; ^ @punctuation.special
; ^ @type
; ^ @string
; ^ @punctuation.special

((comment) . (function_declaration))
; ^ @operator

; vim:ft=query:

0 comments on commit 7c8d2f2

Please sign in to comment.