Files
zed-tree-sitter-dql/grammar.js
idchlife f249538fdd Initial tree-sitter grammar for Dgraph DQL
Skeleton grammar supporting blocks, comments, strings, numbers,
and identifiers. Full DQL keyword support planned for Phase 2.
2026-02-04 15:17:47 +03:00

47 lines
911 B
JavaScript

/// <reference types="tree-sitter-cli/dsl" />
// @ts-check
module.exports = grammar({
name: "dql",
extras: ($) => [/\s/, $.comment],
rules: {
source_file: ($) => repeat($._definition),
_definition: ($) => choice($.block, $.identifier, $.string, $.number),
block: ($) =>
prec(1, seq(
optional(field("name", $.identifier)),
"{",
repeat($._definition),
"}"
)),
comment: ($) => token(seq("#", /.*/)),
string: ($) =>
token(
seq(
'"',
repeat(
choice(
/[^"\\]/,
seq("\\", /./),
)
),
'"'
)
),
number: ($) => token(choice(/\d+\.\d+/, /\d+/)),
identifier: ($) => token(choice(
seq("@", /[a-zA-Z_][a-zA-Z0-9_.:]*/),
seq("$", /[a-zA-Z_][a-zA-Z0-9_]*/),
/[a-zA-Z_][a-zA-Z0-9_.:]*/,
)),
},
});