Initial tree-sitter grammar for Dgraph DQL

Skeleton grammar supporting blocks, comments, strings, numbers,
and identifiers. Full DQL keyword support planned for Phase 2.
This commit is contained in:
2026-02-04 15:17:47 +03:00
commit f249538fdd
13 changed files with 1623 additions and 0 deletions

46
grammar.js Normal file
View File

@@ -0,0 +1,46 @@
/// <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_.:]*/,
)),
},
});