mighty-gerbils / gerbil

Gerbil Scheme
https://cons.io
GNU Lesser General Public License v2.1
1.14k stars 112 forks source link

pregexp on empty strings #1065

Closed leahneukirchen closed 7 months ago

leahneukirchen commented 7 months ago

This fails:

> (pregexp-match "x" "" 0)
*** ERROR IN std/pregexp#pregexp-match-positions__% -- 
*** ERROR IN "pregexp/pregexp.scm"@708.39 [ContractViolation]: contract violation
--- irritants: 'pregexp "start index: out of range" 0 

It's probably too strict?

vyzo commented 7 months ago

yes indeed

leahneukirchen commented 7 months ago

I'm also not entirely sure the end must be within the string length, it mostly makes code more complex?

vyzo commented 7 months ago

yeah we can relax the contract. Care for a pr?

fare commented 7 months ago

My understanding is that in pregexp.scm line 706, we only need (<= 0 start str-len) and if the start is same as str-len that just means empty (sub)string which is allowed to match some regexps.