feat(jsonnet): update parser and queries

This commit is contained in:
Jeroen Op 't Eynde 2023-08-25 19:55:22 +02:00 committed by GitHub
parent bae2c1824f
commit 4d41d9bfb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 110 additions and 54 deletions

10
queries/jsonnet/folds.scm Normal file
View file

@ -0,0 +1,10 @@
[
(field)
(object)
(array)
(parenthesis)
(bind)
; (params)
; (args)
; (conditional)
] @fold

View file

@ -1,21 +1,61 @@
(id) @variable
(comment) @comment
; Literals
(null) @constant.builtin
(string) @string
(number) @number
[ [
(true) (true)
(false) (false)
] @boolean ] @boolean
(comment) @comment ; Keywords
(id) @variable "for" @repeat
(import) @include "in" @keyword.operator
(null) @constant.builtin "function" @keyword.function
(number) @number
(string) @string
(fieldname (id) @field) [
(fieldaccess "if"
last: (id) @field) "then"
(fieldaccess_super "else"
(id) @field) ] @conditional
[
(local)
(tailstrict)
"function"
] @keyword
[
"assert"
"error"
] @exception
[
(dollar)
(self)
(super)
] @variable.builtin
((id) @variable.builtin
(#eq? @variable.builtin "std"))
; Operators
[
(multiplicative)
(additive)
(bitshift)
(comparison)
(equality)
(bitand)
(bitxor)
(bitor)
(and)
(or)
(unaryop)
] @operator
; Punctuation
[ [
"[" "["
"]" "]"
@ -30,63 +70,52 @@
"," ","
";" ";"
":" ":"
"::"
":::"
] @punctuation.delimiter ] @punctuation.delimiter
; Nested field inheritance
("+" @punctuation.delimiter [":" "::" ":::"])
"=" @operator
(unaryop) @operator
(binary
operator: (_) @operator)
"for" @repeat
"function" @keyword.function
"in" @keyword.operator
[ [
(local) "::"
(tailstrict) ":::"
"assert" ] @punctuation.special
] @keyword
(field
(fieldname) "+" @punctuation.special)
; Imports
[ [
"else" (import)
"if" (importstr)
"then" ] @include
] @conditional
"error" @exception ; Fields
[ (fieldname (id) @field)
(dollar) (fieldname (string (string_content) @field))
(self)
(super)
] @variable.builtin
((id) @variable.builtin
(#eq? @variable.builtin "std"))
; Function declaration ; Functions
(field
function: (fieldname (id) @function))
(field
function: (fieldname
(string (string_content) @function)))
(param (param
identifier: (id) @parameter) identifier: (id) @parameter)
(field
(fieldname (id) @function) (bind (id) @variable.local)
[(anonymous_function) (params)]) (bind function: (id) @function)
(bind
function: (id) @function)
; Function call ; Function call
(functioncall (id) @function.call)
(functioncall (functioncall
(fieldaccess (fieldaccess
last: (id) @function.call)) last: (id) @function.call)?
(functioncall
(fieldaccess_super (fieldaccess_super
(id) @function.call)) (id) @function.call)?
(named_argument (id) @parameter) (id)? @function.call
"("
(args
(named_argument
(id) @parameter
))?
")")
; ERROR
(ERROR) @error (ERROR) @error

View file

@ -0,0 +1,17 @@
(parenthesis) @scope
(anonymous_function) @scope
(object) @scope
(field) @scope
(local_bind) @scope
(field
function: (fieldname (id) @definition.function)
(#set! "definition.function.scope" "parent"))
(bind (id) @definition.var)
(bind function: (id) @definition.function)
(param (id) @definition.parameter)
(id) @reference
;(fieldname (id) (#is-not? local)) ; (#is-not?) not supported yet