irregex icon indicating copy to clipboard operation
irregex copied to clipboard

Unexpected result for sre->string

Open graywolf opened this issue 1 year ago • 2 comments

This does not seem to be correct:

3> (sre->string '(* (/ "AZ09")))
"[]*"

I would have expected something like "[A-Z0-9]*".

graywolf avatar Nov 05 '23 21:11 graywolf

It looks like there's some confusion over what a cset is, exactly. It's a vector, but cset->string expects a list. And doesn't crash or complain, just ignores anything non-pair assuming it's the end of the list.

It can be fixed fairly easily by calling vector->list on the ls argument, but I'm not sure that's the best way. Converting to a cset and back drops the original input, so you get something like (sre->string '(~ ("XYZ"))) => "[\x00-W\\[-�\x00-�]" when printing it. I think it'd be nicer to keep closer to the original input (so the output would be "[^XYZ]"), so maybe we should skip the cset conversion here and roll a different implementation just for converting to strings?

sjamaan avatar Nov 06 '23 09:11 sjamaan

Yes, that code is not well tested because I never used it :sweat_smile:

It already has handling to print complemented sets prettily but that code is also wrong.

ashinn avatar Nov 07 '23 03:11 ashinn