PCRE2Project / pcre2

PCRE2 development is now based here.
Other
918 stars 191 forks source link

(Maybe) remove handling of quantifiers after OP_FAIL #541

Closed NWilson closed 3 days ago

NWilson commented 4 weeks ago

I am leaving a TODO in pcre2_compile.c

In the PR #511 Zoltan changed the parser so it doesn't emit OP_FAIL anymore for empty character classes. Hence (according to the comments at least) it should no longer be possible for an OP_FAIL to have a following quantifier. The code to handle this could be removed.

Or, if I'm wrong, then the TODO can be removed, and the comments updated to explain why OP_FAIL can have a quantifier after.

zherczeg commented 4 weeks ago

We might need to emit empty xclasses inside eclasses (the execution part already supports this), which could also handle the nothing match cases. This could save some space.

NWilson commented 4 weeks ago

Yes, I was thinking that in some ways, it would be nice to have a nothing-match opcode, to model []. But after constant-folding, we shouldn't end up with any inside an ECLASS. foo && nothing → nothing, foo -- nothing → foo, etc. So the only "nothing" that can remain would be if the entire ECLASS matched nothing, in which case it wouldn't need to be wrapped in an ECLASS.

NWilson commented 3 weeks ago

The line of code that needs changing is tagged with this URL:

https://github.com/PCRE2Project/pcre2/issues/541

I won't be brave and make the change myself, because I don't understand OP_FAIL well enough. There's just a tiny loose end for someone else (hopefully) to tie up.