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
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
[gren](https://github.com/MaeBrooks/tree-sitter-gren) | unstable | `H  J ` | | @MaeBrooks
[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
[hack](https://github.com/slackhq/tree-sitter-hack) | unstable | `H  J ` | |
[hare](https://github.com/tree-sitter-grammars/tree-sitter-hare) | unstable | `HFIJL` | | @amaanq

View File

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

View File

@@ -48,6 +48,17 @@
(#offset! @injection.content 0 1 0 -1)
(#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
function: (identifier) @_name
(#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"))