mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-12 16:30:02 -04:00
feat: add HelixQL parser
Add parser, queries, and tests for HelixQL (helix-db.com), a SQL-like query language for HelixDB.
This commit is contained in:
parent
2979e048b3
commit
e34111256b
5 changed files with 402 additions and 0 deletions
1
SUPPORTED_LANGUAGES.md
generated
1
SUPPORTED_LANGUAGES.md
generated
|
|
@ -123,6 +123,7 @@ ecma (queries only)[^ecma] | unstable | `HFIJL` | @steelsojka
|
||||||
[haskell_persistent](https://github.com/MercuryTechnologies/tree-sitter-haskell-persistent) | unstable | `HF ` | @lykahb
|
[haskell_persistent](https://github.com/MercuryTechnologies/tree-sitter-haskell-persistent) | unstable | `HF ` | @lykahb
|
||||||
[hcl](https://github.com/tree-sitter-grammars/tree-sitter-hcl) | unstable | `HFIJ ` | @MichaHoffmann
|
[hcl](https://github.com/tree-sitter-grammars/tree-sitter-hcl) | unstable | `HFIJ ` | @MichaHoffmann
|
||||||
[heex](https://github.com/connorlay/tree-sitter-heex) | unstable | `HFIJL` | @connorlay
|
[heex](https://github.com/connorlay/tree-sitter-heex) | unstable | `HFIJL` | @connorlay
|
||||||
|
[helixql](https://github.com/benwoodward/tree-sitter-helixql) | unsupported | `HF ` | @benwoodward
|
||||||
[helm](https://github.com/ngalaiko/tree-sitter-go-template) | unstable | `HF JL` | @qvalentin
|
[helm](https://github.com/ngalaiko/tree-sitter-go-template) | unstable | `HF JL` | @qvalentin
|
||||||
[hjson](https://github.com/winston0410/tree-sitter-hjson) | unstable | `HFIJL` | @winston0410
|
[hjson](https://github.com/winston0410/tree-sitter-hjson) | unstable | `HFIJL` | @winston0410
|
||||||
[hlsl](https://github.com/tree-sitter-grammars/tree-sitter-hlsl) | unstable | `HFIJL` | @theHamsta
|
[hlsl](https://github.com/tree-sitter-grammars/tree-sitter-hlsl) | unstable | `HFIJL` | @theHamsta
|
||||||
|
|
|
||||||
|
|
@ -912,6 +912,14 @@ return {
|
||||||
maintainers = { '@qvalentin' },
|
maintainers = { '@qvalentin' },
|
||||||
tier = 2,
|
tier = 2,
|
||||||
},
|
},
|
||||||
|
helixql = {
|
||||||
|
install_info = {
|
||||||
|
branch = 'main',
|
||||||
|
url = 'https://github.com/benwoodward/tree-sitter-helixql',
|
||||||
|
},
|
||||||
|
maintainers = { '@benwoodward' },
|
||||||
|
tier = 4,
|
||||||
|
},
|
||||||
hjson = {
|
hjson = {
|
||||||
install_info = {
|
install_info = {
|
||||||
revision = '02fa3b79b3ff9a296066da6277adfc3f26cbc9e0',
|
revision = '02fa3b79b3ff9a296066da6277adfc3f26cbc9e0',
|
||||||
|
|
|
||||||
12
runtime/queries/helixql/folds.scm
Normal file
12
runtime/queries/helixql/folds.scm
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
; =============================================================================
|
||||||
|
; HelixQL Folds for Neovim Tree-sitter
|
||||||
|
; =============================================================================
|
||||||
|
[
|
||||||
|
(node_def)
|
||||||
|
(edge_def)
|
||||||
|
(vector_def)
|
||||||
|
(query_def)
|
||||||
|
(for_loop)
|
||||||
|
(object_step)
|
||||||
|
(create_field)
|
||||||
|
] @fold
|
||||||
259
runtime/queries/helixql/highlights.scm
Normal file
259
runtime/queries/helixql/highlights.scm
Normal file
|
|
@ -0,0 +1,259 @@
|
||||||
|
; =============================================================================
|
||||||
|
; HelixQL Syntax Highlighting for Neovim Tree-sitter
|
||||||
|
; =============================================================================
|
||||||
|
; NOTE: In tree-sitter queries, later patterns override earlier ones.
|
||||||
|
; Put general patterns first, then specific overrides after.
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
; Comments
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
(comment) @comment @spell
|
||||||
|
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
; Literals
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
(string_literal) @string
|
||||||
|
|
||||||
|
(integer) @number
|
||||||
|
|
||||||
|
(float) @number.float
|
||||||
|
|
||||||
|
(boolean) @boolean
|
||||||
|
|
||||||
|
(none) @constant.builtin
|
||||||
|
|
||||||
|
(now) @constant.builtin
|
||||||
|
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
; Generic identifiers
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
(identifier) @variable
|
||||||
|
|
||||||
|
(identifier_upper) @type
|
||||||
|
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
; Keywords
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
[
|
||||||
|
"QUERY"
|
||||||
|
"RETURN"
|
||||||
|
"FOR"
|
||||||
|
"IN"
|
||||||
|
] @keyword
|
||||||
|
|
||||||
|
; Node type keywords (wrapped in their own rules)
|
||||||
|
(index) @keyword
|
||||||
|
|
||||||
|
(default) @keyword
|
||||||
|
|
||||||
|
(count) @keyword
|
||||||
|
|
||||||
|
(ID) @constant.builtin
|
||||||
|
|
||||||
|
; Keywords inside node types
|
||||||
|
(where_step
|
||||||
|
"WHERE" @keyword)
|
||||||
|
|
||||||
|
(range_step
|
||||||
|
"RANGE" @keyword)
|
||||||
|
|
||||||
|
(update
|
||||||
|
"UPDATE" @keyword)
|
||||||
|
|
||||||
|
(drop
|
||||||
|
"DROP" @keyword)
|
||||||
|
|
||||||
|
(exists
|
||||||
|
"EXISTS" @keyword)
|
||||||
|
|
||||||
|
; Boolean and logical operators
|
||||||
|
(and
|
||||||
|
"AND" @keyword.operator)
|
||||||
|
|
||||||
|
(or
|
||||||
|
"OR" @keyword.operator)
|
||||||
|
|
||||||
|
(GT
|
||||||
|
"GT" @keyword.operator)
|
||||||
|
|
||||||
|
(GTE
|
||||||
|
"GTE" @keyword.operator)
|
||||||
|
|
||||||
|
(LT
|
||||||
|
"LT" @keyword.operator)
|
||||||
|
|
||||||
|
(LTE
|
||||||
|
"LTE" @keyword.operator)
|
||||||
|
|
||||||
|
(EQ
|
||||||
|
"EQ" @keyword.operator)
|
||||||
|
|
||||||
|
(NEQ
|
||||||
|
"NEQ" @keyword.operator)
|
||||||
|
|
||||||
|
; Creation operation keywords
|
||||||
|
(AddN
|
||||||
|
"AddN" @function.builtin)
|
||||||
|
|
||||||
|
(AddE
|
||||||
|
"AddE" @function.builtin)
|
||||||
|
|
||||||
|
(AddV
|
||||||
|
"AddV" @function.builtin)
|
||||||
|
|
||||||
|
(BatchAddV
|
||||||
|
"BatchAddV" @function.builtin)
|
||||||
|
|
||||||
|
(search_vector
|
||||||
|
"SearchV" @function.builtin)
|
||||||
|
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
; Schema definition keywords
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
[
|
||||||
|
"N::"
|
||||||
|
"E::"
|
||||||
|
"V::"
|
||||||
|
] @keyword.directive
|
||||||
|
|
||||||
|
[
|
||||||
|
"From:"
|
||||||
|
"To:"
|
||||||
|
"Properties"
|
||||||
|
] @keyword.modifier
|
||||||
|
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
; Graph traversal methods
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
(out_e
|
||||||
|
"OutE" @function.method)
|
||||||
|
|
||||||
|
(in_e
|
||||||
|
"InE" @function.method)
|
||||||
|
|
||||||
|
(from_n) @function.method
|
||||||
|
|
||||||
|
(to_n) @function.method
|
||||||
|
|
||||||
|
(out
|
||||||
|
"Out" @function.method)
|
||||||
|
|
||||||
|
(in_nodes
|
||||||
|
"In" @function.method)
|
||||||
|
|
||||||
|
(shortest_path
|
||||||
|
"ShortestPath" @function.method)
|
||||||
|
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
; Start nodes - highlight N, E, V as keywords
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
(start_node
|
||||||
|
"N" @keyword)
|
||||||
|
|
||||||
|
(start_edge
|
||||||
|
"E" @keyword)
|
||||||
|
|
||||||
|
(start_vector
|
||||||
|
"V" @keyword)
|
||||||
|
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
; Types
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
(named_type) @type.builtin
|
||||||
|
|
||||||
|
(date_type) @type.builtin
|
||||||
|
|
||||||
|
(ID_TYPE) @type.builtin
|
||||||
|
|
||||||
|
; Type arguments in angle brackets
|
||||||
|
(type_args
|
||||||
|
(identifier_upper) @type)
|
||||||
|
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
; Specific identifier patterns (override generic rules)
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
; Query/function names
|
||||||
|
(query_def
|
||||||
|
name: (identifier) @function)
|
||||||
|
|
||||||
|
; Schema definition names
|
||||||
|
(node_def
|
||||||
|
name: (identifier_upper) @type.definition)
|
||||||
|
|
||||||
|
(edge_def
|
||||||
|
name: (identifier_upper) @type.definition)
|
||||||
|
|
||||||
|
(vector_def
|
||||||
|
name: (identifier_upper) @type.definition)
|
||||||
|
|
||||||
|
; Parameter names in function signatures
|
||||||
|
(param_def
|
||||||
|
name: (identifier) @variable.parameter)
|
||||||
|
|
||||||
|
; Field names in schema definitions
|
||||||
|
(field_def
|
||||||
|
name: (identifier) @property)
|
||||||
|
|
||||||
|
; Property keys in object creation
|
||||||
|
(new_field
|
||||||
|
key: (identifier) @property)
|
||||||
|
|
||||||
|
; Property keys in updates
|
||||||
|
(update_field
|
||||||
|
key: (identifier) @property)
|
||||||
|
|
||||||
|
; Property keys in object mapping (left of :)
|
||||||
|
(mapping_field
|
||||||
|
(identifier) @property
|
||||||
|
":")
|
||||||
|
|
||||||
|
; Object access field
|
||||||
|
(object_access
|
||||||
|
field: (identifier) @property)
|
||||||
|
|
||||||
|
; Variable assignment targets (left of <-)
|
||||||
|
(get_stmt
|
||||||
|
variable: (identifier) @variable)
|
||||||
|
|
||||||
|
; For loop iterable
|
||||||
|
(for_loop
|
||||||
|
iterable: (identifier) @variable)
|
||||||
|
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
; Operators
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
[
|
||||||
|
"<-"
|
||||||
|
"=>"
|
||||||
|
"::"
|
||||||
|
"."
|
||||||
|
".."
|
||||||
|
"!"
|
||||||
|
] @operator
|
||||||
|
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
; Punctuation
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
[
|
||||||
|
":"
|
||||||
|
","
|
||||||
|
] @punctuation.delimiter
|
||||||
|
|
||||||
|
[
|
||||||
|
"("
|
||||||
|
")"
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
"["
|
||||||
|
"]"
|
||||||
|
"<"
|
||||||
|
">"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
"|" @punctuation.special
|
||||||
|
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
; Special patterns
|
||||||
|
; -----------------------------------------------------------------------------
|
||||||
|
; Anonymous traversal underscore
|
||||||
|
(anonymous_traversal
|
||||||
|
"_" @variable.builtin)
|
||||||
122
tests/query/highlights/helixql/test.hx
Normal file
122
tests/query/highlights/helixql/test.hx
Normal file
|
|
@ -0,0 +1,122 @@
|
||||||
|
// Schema definitions
|
||||||
|
// <- @comment
|
||||||
|
N::User {
|
||||||
|
// <- @keyword.directive
|
||||||
|
// ^ @type.definition
|
||||||
|
INDEX id: ID,
|
||||||
|
//^ @keyword
|
||||||
|
// ^ @type.builtin
|
||||||
|
name: String,
|
||||||
|
//^ @property
|
||||||
|
// ^ @type.builtin
|
||||||
|
email: String,
|
||||||
|
age: I32,
|
||||||
|
// ^ @type.builtin
|
||||||
|
created_at: Date DEFAULT NOW
|
||||||
|
// ^ @type.builtin
|
||||||
|
// ^ @keyword
|
||||||
|
// ^ @constant.builtin
|
||||||
|
}
|
||||||
|
|
||||||
|
E::Follows {
|
||||||
|
// <- @keyword.directive
|
||||||
|
From: User,
|
||||||
|
//^ @keyword.modifier
|
||||||
|
To: User,
|
||||||
|
//^ @keyword.modifier
|
||||||
|
Properties: {
|
||||||
|
//^ @keyword.modifier
|
||||||
|
since: Date
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
V::UserEmbedding {
|
||||||
|
// <- @keyword.directive
|
||||||
|
user_id: ID,
|
||||||
|
embedding: [F32]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simple query
|
||||||
|
QUERY getUser(userId: ID) =>
|
||||||
|
// <- @keyword
|
||||||
|
// ^ @function
|
||||||
|
// ^ @variable.parameter
|
||||||
|
user <- N<User>(userId)
|
||||||
|
//^ @variable
|
||||||
|
// ^ @operator
|
||||||
|
// ^ @keyword
|
||||||
|
// ^ @type
|
||||||
|
RETURN user
|
||||||
|
//^ @keyword
|
||||||
|
|
||||||
|
// Query with traversal
|
||||||
|
QUERY getFollowers(userId: ID) =>
|
||||||
|
user <- N<User>(userId)
|
||||||
|
followers <- user::InE<Follows>::FromN
|
||||||
|
// ^ @function.method
|
||||||
|
// ^ @function.method
|
||||||
|
RETURN followers
|
||||||
|
|
||||||
|
// Query with filtering
|
||||||
|
QUERY getAdults(minAge: I32) =>
|
||||||
|
users <- N<User>::WHERE(_::age::GTE(minAge))
|
||||||
|
// ^ @keyword
|
||||||
|
// ^ @variable.builtin
|
||||||
|
// ^ @keyword.operator
|
||||||
|
RETURN users
|
||||||
|
|
||||||
|
// Query with object return
|
||||||
|
QUERY getUserStats(userId: ID) =>
|
||||||
|
user <- N<User>(userId)
|
||||||
|
followCount <- user::OutE<Follows>::COUNT
|
||||||
|
// ^ @keyword
|
||||||
|
RETURN {
|
||||||
|
userId: userId,
|
||||||
|
// ^ @property
|
||||||
|
followCount: followCount
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query with AddN
|
||||||
|
QUERY createUser(name: String, email: String) =>
|
||||||
|
user <- AddN<User>({
|
||||||
|
// ^ @function.builtin
|
||||||
|
name: name,
|
||||||
|
email: email
|
||||||
|
})
|
||||||
|
RETURN user
|
||||||
|
|
||||||
|
// Query with AddE
|
||||||
|
QUERY followUser(fromId: ID, toId: ID) =>
|
||||||
|
from <- N<User>(fromId)
|
||||||
|
to <- N<User>(toId)
|
||||||
|
AddE<Follows>::From(from::ID)::To(to::ID)
|
||||||
|
//^ @function.builtin
|
||||||
|
RETURN from
|
||||||
|
|
||||||
|
// Query with FOR loop
|
||||||
|
QUERY createMultipleUsers(names: [String]) =>
|
||||||
|
FOR name IN names {
|
||||||
|
//^ @keyword
|
||||||
|
// ^ @keyword
|
||||||
|
user <- AddN<User>({name: name})
|
||||||
|
}
|
||||||
|
RETURN NONE
|
||||||
|
// ^ @constant.builtin
|
||||||
|
|
||||||
|
// Vector search
|
||||||
|
QUERY findSimilar(embedding: [F32], limit: I32) =>
|
||||||
|
results <- SearchV<UserEmbedding>(embedding, limit)
|
||||||
|
// ^ @function.builtin
|
||||||
|
RETURN results
|
||||||
|
|
||||||
|
// Literals
|
||||||
|
QUERY testLiterals() =>
|
||||||
|
str <- "hello world"
|
||||||
|
// ^ @string
|
||||||
|
num <- 42
|
||||||
|
// ^ @number
|
||||||
|
flt <- 3.14
|
||||||
|
// ^ @number.float
|
||||||
|
b <- true
|
||||||
|
// ^ @boolean
|
||||||
|
RETURN NONE
|
||||||
Loading…
Add table
Add a link
Reference in a new issue