Skeleton grammar supporting blocks, comments, strings, numbers, and identifiers. Full DQL keyword support planned for Phase 2.
47 lines
911 B
JavaScript
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_.:]*/,
|
|
)),
|
|
},
|
|
});
|