lua: strip capture parens in patterns so (%a+) matches (captures not returned yet)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-24 23:23:02 +00:00
parent e670e914e7
commit f89e50aa4d
2 changed files with 30 additions and 4 deletions

View File

@@ -828,6 +828,31 @@
;; Top-level find: return (start-index-0based . end-index) or nil on no match.
;; If pat starts with ^, anchor to init. Otherwise scan.
(define
lua-pat-strip-captures
(fn (pat)
(let ((out "") (i 0))
(begin
(define
sc-loop
(fn ()
(when (< i (len pat))
(let ((c (char-at pat i)))
(cond
((= c "%")
(begin
(set! out (str out c))
(when (< (+ i 1) (len pat))
(set! out (str out (char-at pat (+ i 1)))))
(set! i (+ i 2))
(sc-loop)))
((or (= c "(") (= c ")"))
(begin (set! i (+ i 1)) (sc-loop)))
(else
(begin (set! out (str out c)) (set! i (+ i 1)) (sc-loop))))))))
(sc-loop)
out))))
(define
lua-pat-find
(fn (pat s init)
@@ -959,7 +984,7 @@
(+ start-i0 idx 1)
(+ start-i0 idx (len pat))))))))
(else
(let ((r (lua-pat-find pat s start-i0)))
(let ((r (lua-pat-find (lua-pat-strip-captures pat) s start-i0)))
(cond
((= r nil) nil)
(else (list (quote lua-multi) (+ (first r) 1) (nth r 1)))))))))))
@@ -974,7 +999,7 @@
((< init 0) (let ((v (+ (len s) init))) (if (< v 0) 0 v)))
((= init 0) 0)
(else (- init 1)))))
(let ((r (lua-pat-find pat s start-i0)))
(let ((r (lua-pat-find (lua-pat-strip-captures pat) s start-i0)))
(cond
((= r nil) nil)
(else (substring s (first r) (nth r 1)))))))))
@@ -988,7 +1013,7 @@
(cond
((> pos (len s)) nil)
(else
(let ((r (lua-pat-find pat s pos)))
(let ((r (lua-pat-find (lua-pat-strip-captures pat) s pos)))
(cond
((= r nil) (begin (set! pos (+ (len s) 1)) nil))
(else
@@ -1014,7 +1039,7 @@
gsub-loop
(fn ()
(when (and (not done) (<= pos (len s)))
(let ((r (lua-pat-find pat s pos)))
(let ((r (lua-pat-find (lua-pat-strip-captures pat) s pos)))
(cond
((= r nil)
(begin

View File

@@ -82,6 +82,7 @@ Each item: implement → tests → tick box → update progress log.
_Newest first. Agent appends on every commit._
- 2026-04-24: lua: scoreboard iteration — `lua-pat-strip-captures` helper lets patterns with `(...)` capture parens at least match (captures themselves aren't returned yet — match returns whole match). Unblocks common Lua pattern idioms like `(%a+)=(%d+)`. Scoreboard unchanged.
- 2026-04-24: lua: scoreboard iteration — extended pattern engine to `string.match`/`gmatch`/`gsub`. `gsub` now supports string/function/table replacement modes. 381/381 green (+6 pattern tests).
- 2026-04-24: lua: scoreboard iteration — **Lua pattern engine (minimal)** for `string.find`. Supports character classes (`%d`/`%a`/`%s`/`%w`/`%p`/`%l`/`%u`/`%c`/`%x` + complements), `.` any, `^`/`$` anchors, quantifiers `*`/`+`/`-`/`?`, literal chars, `%%`. Added `plain` arg pathway. match/gmatch/gsub still literal. Scoreboard unchanged (pattern-using tests still hit other issues downstream).
- 2026-04-24: lua: scoreboard iteration — `package.cpath`/`config`/`loaders`/`searchers`/`searchpath` stubs. attrib.lua moves from #9 (checking `package.cpath` is a string) to "module 'C' not found" — test requires filesystem-based module loading, not tractable. Most remaining failures need Lua pattern matching (pm.lua/strings.lua), env tracking (locals.lua/events.lua), or filesystem (attrib.lua).