feat(package): hemar: tree sitter grammar
This commit is contained in:
41
package/hemar/grammar/tree-sitter/grammar.js
Normal file
41
package/hemar/grammar/tree-sitter/grammar.js
Normal file
@@ -0,0 +1,41 @@
|
||||
module.exports = grammar({
|
||||
name: "mytempl",
|
||||
|
||||
rules: {
|
||||
source_file: $ => repeat($.element),
|
||||
|
||||
element: $ => choice($.interpolation, $.segment, $.text),
|
||||
|
||||
interpolation: $ => seq("{[", $.path, "]}"),
|
||||
|
||||
segment: $ => seq($.for, repeat($.element), $.done),
|
||||
|
||||
|
||||
for: $ => seq("{[", "for", $.string, "in", $.path, "]}"),
|
||||
done: $ => seq("{[", "done", "]}"),
|
||||
//include: $ => seq("include", $.path),
|
||||
//call: $ => seq("call", $.string, "in", $.language),
|
||||
//call_end: $ => seq("end", $.string),
|
||||
//standalone_call: $ => seq("call", $.string, "end"),
|
||||
//language: $ => choice("dash", "plpgsql"),
|
||||
|
||||
path: $ => choice(
|
||||
".",
|
||||
seq(
|
||||
$.string,
|
||||
repeat(seq(".", $.string)),
|
||||
),
|
||||
),
|
||||
|
||||
// anything but space
|
||||
string: $ => choice(
|
||||
// no whitespace, ], \, ., "
|
||||
token(prec(-1, /[^] .\\"]+/)),
|
||||
// " ... " with "" = escaped "
|
||||
token(prec(-1, /"([^"]|"")*"/)),
|
||||
),
|
||||
|
||||
// anything but {[
|
||||
text: $ => token(prec(-1, /(?:\{[^\[]|[^{])+/)),
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user