~sircmpwn/hare-dev

hare: regex: fix typo in error message v2 APPLIED

Max Schillinger: 2
 regex: fix typo in error message
 regex: implement whole-expression alternation

 3 files changed, 18 insertions(+), 5 deletions(-)
#1195860 alpine.yml failed
#1195861 freebsd.yml success
#1195862 openbsd.yml success
hare/patches: FAILED in 1m1s

[regex: fix typo in error message][0] v2 from [Max Schillinger][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/51016
[1]: mailto:max@mxsr.de

✓ #1195861 SUCCESS hare/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/1195861
✗ #1195860 FAILED  hare/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/1195860
✓ #1195862 SUCCESS hare/patches/openbsd.yml https://builds.sr.ht/~sircmpwn/job/1195862
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/hare-dev/patches/51016/mbox | git am -3
Learn more about email & git

[PATCH hare v2 1/2] regex: fix typo in error message Export this patch

Signed-off-by: Max Schillinger <max@mxsr.de>
---
 regex/regex.ha | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/regex/regex.ha b/regex/regex.ha
index 137c904d..84a55d5e 100644
--- a/regex/regex.ha
+++ b/regex/regex.ha
@@ -200,7 +200,7 @@ fn handle_bracket(
		const end_b = range_end as rune: u32;

		if (end_b < start_b) {
			return `Decending bracket expression range '[z-a]'`: error;
			return `Descending bracket expression range '[z-a]'`: error;
		};

		append(charsets[len(charsets) - 1],
-- 
2.44.0
Thanks!

to git@git.sr.ht:~sircmpwn/hare
  d1cf4089..bda2079c  master -> master

[PATCH hare v2 2/2] regex: implement whole-expression alternation Export this patch

When a pattern contains a `|` outside of a capture group, make this the
jump position of a whole-expression alternation.

Signed-off-by: Max Schillinger <max@mxsr.de>
---
 regex/+test.ha |  7 ++++---
 regex/regex.ha | 14 +++++++++++++-
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/regex/+test.ha b/regex/+test.ha
index ddecdff9..45600e0d 100644
--- a/regex/+test.ha
+++ b/regex/+test.ha
@@ -577,9 +577,10 @@ fn run_rawreplace_case(
		(`(a|ab)(bcd|c)(d|.*)`, "abcd", matchres::MATCH, 0, -1), // POSIX: (0,4)(0,2)(2,3)(3,4)
		(`(ab|a)(c|bcd)(d|.*)`, "abcd", matchres::MATCH, 0, -1), // POSIX: (0,4)(0,2)(2,3)(3,4)
		(`(ab|a)(bcd|c)(d|.*)`, "abcd", matchres::MATCH, 0, -1), // POSIX: (0,4)(0,2)(2,3)(3,4)
		// TODO: whole-expression alternation
		// (`ab|cd`, "abc", matchres::MATCH, 0, -1),
		// (`ab|cd`, "abcd", matchres::MATCH, 0, -1),
		// whole-expression alternation
		(`ab|cd`, "cd", matchres::MATCH, 0, 2),
		(`ab|cd`, "abc", matchres::MATCH, 0, 2),
		(`ab|cd`, "abcd", matchres::MATCH, 0, 2),
		// TODO: multiple alternation
		// (`a|b|c|d|e`, "e", matchres::MATCH, 0, -1),
		// (`(a|b|c|d|e)f`, "ef", matchres::MATCH, 0, -1),
diff --git a/regex/regex.ha b/regex/regex.ha
index 84a55d5e..d0140feb 100644
--- a/regex/regex.ha
+++ b/regex/regex.ha
@@ -300,7 +300,12 @@ export fn compile(expr: str) (regex | error) = {
			};
		case '|' =>
			append(insts, types::SIZE_MAX: inst_jump);
			const origin = find_last_groupstart(&insts)? + 1;
			const origin = match (find_last_groupstart(&insts)) {
			case error =>
				yield 0z;
			case let sz: size =>
				yield sz + 1;
			};
			const newinst = (len(insts) + 1): inst_split;
			insert(insts[origin], newinst);
			curr_alt_jump_idx = (len(insts) - 1): int;
@@ -394,6 +399,13 @@ export fn compile(expr: str) (regex | error) = {
		r_idx += 1;
	};

	// handle whole expression alternation
	if (curr_alt_jump_idx != -1) {
		assert(insts[curr_alt_jump_idx] is inst_jump);
		insts[curr_alt_jump_idx] = len(insts): inst_jump;
		curr_alt_jump_idx = -1;
	};

	append(insts, anchored: inst_match);

	return regex {
-- 
2.44.0
hare/patches: FAILED in 1m1s

[regex: fix typo in error message][0] v2 from [Max Schillinger][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/51016
[1]: mailto:max@mxsr.de

✓ #1195861 SUCCESS hare/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/1195861
✗ #1195860 FAILED  hare/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/1195860
✓ #1195862 SUCCESS hare/patches/openbsd.yml https://builds.sr.ht/~sircmpwn/job/1195862