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, /"([^"]|"")*"/)),
),

View File

@@ -1,8 +1,8 @@
(interpolation) @keyword
(segment) @keyword
(interpolation) @keyword
(segment) @keyword
(for "for" @keyword)
(for "in" @keyword)
(for "for" @keyword)
(for "in" @keyword)
(done "done" @keyword)
(path) @field

View File

@@ -23,6 +23,10 @@
{
"type": "SYMBOL",
"name": "text"
},
{
"type": "SYMBOL",
"name": "actual_bracket"
}
]
},
@@ -109,6 +113,23 @@
}
]
},
"actual_bracket": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{["
},
{
"type": "STRING",
"value": "{["
},
{
"type": "STRING",
"value": "]}"
}
]
},
"path": {
"type": "CHOICE",
"members": [
@@ -120,8 +141,17 @@
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "string"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "SYMBOL",
"name": "index"
}
]
},
{
"type": "REPEAT",
@@ -133,8 +163,17 @@
"value": "."
},
{
"type": "SYMBOL",
"name": "string"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "SYMBOL",
"name": "index"
}
]
}
]
}
@@ -143,6 +182,40 @@
}
]
},
"index": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "\\d"
},
{
"type": "PATTERN",
"value": "[1-9]\\d*"
},
{
"type": "PATTERN",
"value": "-[1-9]"
},
{
"type": "PATTERN",
"value": "-[1-9]\\d*"
}
]
},
{
"type": "STRING",
"value": "]"
}
]
},
"string": {
"type": "CHOICE",
"members": [
@@ -153,7 +226,7 @@
"value": -1,
"content": {
"type": "PATTERN",
"value": "[^] .\\\\\"]+"
"value": "[^]\\[{} \\n\\t\\r.\\\\\"]+"
}
}
},

View File

@@ -1,4 +1,9 @@
[
{
"type": "actual_bracket",
"named": true,
"fields": {}
},
{
"type": "done",
"named": true,
@@ -12,6 +17,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "actual_bracket",
"named": true
},
{
"type": "interpolation",
"named": true
@@ -46,6 +55,11 @@
]
}
},
{
"type": "index",
"named": true,
"fields": {}
},
{
"type": "interpolation",
"named": true,
@@ -69,6 +83,10 @@
"multiple": true,
"required": false,
"types": [
{
"type": "index",
"named": true
},
{
"type": "string",
"named": true
@@ -124,6 +142,14 @@
"type": ".",
"named": false
},
{
"type": "[",
"named": false
},
{
"type": "]",
"named": false
},
{
"type": "]}",
"named": false

File diff suppressed because it is too large Load Diff

View File

@@ -112,3 +112,25 @@ segment with text
(element
(text))
(done))))
==================
brace
==================
{[ {[ ]}
---
(source_file
(element
(actual_bracket)))
==================
indexes
==================
{[ [1].[0].[12].[-2].[-3] ]}
---
(source_file
(element
(interpolation
(path
(index)
(index)
(index)
(index)
(index))))))