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:
46
grammar.js
Normal file
46
grammar.js
Normal 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_.:]*/,
|
||||
)),
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user