hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit e056f10e534e4dc27a15bea49514bfdae553f420
parent 261cf7daff3f56b03c0829f19fad4039032fbd42
Author: Vlad-Stefan Harbuz <vlad@vlad.website>
Date:   Sat,  7 Dec 2024 23:13:05 +0000

regex: document and test split insertion

Signed-off-by: Vlad-Stefan Harbuz <vlad@vlad.website>

Diffstat:
Mregex/+test.ha | 2++
Mregex/regex.ha | 4++++
2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/regex/+test.ha b/regex/+test.ha @@ -412,6 +412,8 @@ fn run_rawreplace_case( (`^x(abc){,2}$`, "xabc", matchres::MATCH, 0, -1), (`^x(abc){,2}$`, "xabcabc", matchres::MATCH, 0, -1), (`^x(abc){,2}`, "xabcabcabc", matchres::MATCH, 0, 7), + (`^x(abc){,0}de`, "xde", matchres::MATCH, 0, -1), + (`^x(abc){,0}de`, "xe", matchres::NOMATCH, 0, -1), (`^x(abc){,2}$`, "xabcabcabc", matchres::NOMATCH, 0, -1), (`^x(abc){1,}$`, "xabc", matchres::MATCH, 0, -1), (`^x(abc){1,}$`, "xabcabc", matchres::MATCH, 0, -1), diff --git a/regex/regex.ha b/regex/regex.ha @@ -345,6 +345,10 @@ export fn compile(expr: str) (regex | error) = { yield rep_parts.0; }; if (can_skip) { + // len(insts) - 1 is the current last instruction + // len(insts) is the next instruction + // advance to len(insts) + 1 to make space for the `inst_split` + // advance to len(insts) + 2 to make space for the `inst_repeat` insert(insts[origin], len(insts) + 2: inst_split); origin += 1;