feat(groq): add parser and queries (#8008)

This commit is contained in:
Alan Russell 2025-07-18 17:04:42 +01:00 committed by GitHub
parent a5edb0a274
commit 61ec748ef7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 142 additions and 0 deletions

View file

@ -117,6 +117,7 @@ ecma (queries only)[^ecma] | unstable | `HFIJL` | | @steelsojka
[graphql](https://github.com/bkegley/tree-sitter-graphql) | unstable | `H IJ ` | | @bkegley [graphql](https://github.com/bkegley/tree-sitter-graphql) | unstable | `H IJ ` | | @bkegley
[gren](https://github.com/MaeBrooks/tree-sitter-gren) | unstable | `H  J ` | | @MaeBrooks [gren](https://github.com/MaeBrooks/tree-sitter-gren) | unstable | `H  J ` | | @MaeBrooks
[groovy](https://github.com/murtaza64/tree-sitter-groovy) | unstable | `HFIJL` | | @murtaza64 [groovy](https://github.com/murtaza64/tree-sitter-groovy) | unstable | `HFIJL` | | @murtaza64
[groq](https://github.com/ajrussellaudio/tree-sitter-groq) | unstable | `HFIJ ` | | @ajrussellaudio
[gstlaunch](https://github.com/tree-sitter-grammars/tree-sitter-gstlaunch) | unstable | `H    ` | | @theHamsta [gstlaunch](https://github.com/tree-sitter-grammars/tree-sitter-gstlaunch) | unstable | `H    ` | | @theHamsta
[hack](https://github.com/slackhq/tree-sitter-hack) | unstable | `H  J ` | | [hack](https://github.com/slackhq/tree-sitter-hack) | unstable | `H  J ` | |
[hare](https://github.com/tree-sitter-grammars/tree-sitter-hare) | unstable | `HFIJL` | | @amaanq [hare](https://github.com/tree-sitter-grammars/tree-sitter-hare) | unstable | `HFIJL` | | @amaanq

View file

@ -857,6 +857,14 @@ return {
maintainers = { '@murtaza64' }, maintainers = { '@murtaza64' },
tier = 2, tier = 2,
}, },
groq = {
install_info = {
revision = '9959049ddeb4416101653a071ee923ba9f7a5cb1',
url = 'https://github.com/ajrussellaudio/tree-sitter-groq',
},
maintainers = { '@ajrussellaudio' },
tier = 2,
},
gstlaunch = { gstlaunch = {
install_info = { install_info = {
revision = '549aef253fd38a53995cda1bf55c501174372bf7', revision = '549aef253fd38a53995cda1bf55c501174372bf7',

View file

@ -48,6 +48,17 @@
(#offset! @injection.content 0 1 0 -1) (#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children)) (#set! injection.include-children))
; Sanity CMS GROQ query
; defineQuery(`...`)
(call_expression
function: (identifier) @_name
(#eq? @_name "defineQuery")
arguments: (arguments
(template_string) @injection.content)
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children)
(#set! injection.language "groq"))
(call_expression (call_expression
function: (identifier) @_name function: (identifier) @_name
(#eq? @_name "gql") (#eq? @_name "gql")

View file

@ -0,0 +1,5 @@
[
(object)
(projection)
(array)
] @fold

View file

@ -0,0 +1,104 @@
; Keywords
[
"select"
"asc"
"desc"
] @keyword
[
"in"
"match"
] @keyword.operator
; Operators
[
"=="
"!="
">"
">="
"<"
"<="
"&&"
"||"
"!"
"+"
"-"
"*"
"/"
"%"
"**"
".."
"..."
"=>"
"->"
"|"
] @operator
; Punctuation
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
[
","
":"
"."
] @punctuation.delimiter
; Literals
(string) @string
(number) @number
[
(true)
(false)
] @boolean
; Special references
[
(null)
(star)
(parent)
(this)
] @constant.builtin
; Identifiers
(identifier) @variable
; Parameters
(parameter
"$" @variable.parameter
(identifier) @variable.parameter)
; Function calls
(function_call
(identifier) @function)
(order_function
"order" @function.builtin)
; Comments
(comment) @comment @spell
; String keys in projections/objects
(pair
(literal
(string) @property))
; Highlight field names in projections
(projection
(identifier) @property)
; Built-in functions (essential GROQ functions)
(function_call
(identifier) @function.builtin
(#any-of? @function.builtin
"count" "length" "defined" "references" "now" "dateTime" "coalesce" "unique" "max" "min" "sum"
"avg" "round" "floor" "ceil" "abs" "sqrt" "upper" "lower" "string" "number" "boolean" "array"
"object" "type" "global" "sanity" "path" "delta" "after" "before"))

View file

@ -0,0 +1,11 @@
[
(object)
(projection)
] @indent.begin
[
"{"
"}"
] @indent.branch
"}" @indent.end

View file

@ -0,0 +1,2 @@
((comment) @injection.content
(#set! injection.language "comment"))