feat(package): hemar: add indexes to tree-sitter

This commit is contained in:
2025-11-28 10:29:59 +00:00
parent 4b4ea7a1d2
commit 48077aaccc
6 changed files with 724 additions and 400 deletions

View File

@@ -4,15 +4,16 @@ module.exports = grammar({
rules: {
source_file: $ => repeat($.element),
element: $ => choice($.interpolation, $.segment, $.text),
element: $ => choice($.interpolation, $.segment, $.text, $.actual_bracket),
interpolation: $ => seq("{[", $.path, "]}"),
segment: $ => seq($.for, repeat($.element), $.done),
for: $ => seq("{[", "for", $.string, "in", $.path, "]}"),
done: $ => seq("{[", "done", "]}"),
for: $ => seq("{[", "for", $.string, "in", $.path, "]}"),
done: $ => seq("{[", "done", "]}"),
actual_bracket: $ => seq("{[", "{[", "]}"),
//include: $ => seq("include", $.path),
//call: $ => seq("call", $.string, "in", $.language),
//call_end: $ => seq("end", $.string),
@@ -22,16 +23,34 @@ module.exports = grammar({
path: $ => choice(
".",
seq(
$.string,
repeat(seq(".", $.string)),
choice(
$.string,
$.index,
),
repeat(seq(".", choice(
$.string,
$.index,
))),
),
),
index: $ => seq(
'[',
choice(
/\d/,
/[1-9]\d*/,
/-[1-9]/,
/-[1-9]\d*/
),
']',
),
// anything but space
string: $ => choice(
// no whitespace, ], \, ., "
token(prec(-1, /[^] .\\"]+/)),
// no whitespace, [, ], {, }, \, ., "
token(prec(-1, /[^]\[{} \n\t\r.\\"]+/)),
// " ... " with "" = escaped "
// if you need json string rules (?:[^"\\\x00-\x1F]|\\["\\/bfnrt]|\\u[0-9A-Fa-f]{4})*
token(prec(-1, /"([^"]|"")*"/)),
),