Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty string is not equivalent to :VOID, signals error in CREATE-SCANNER in some cases #42

Open
tshatrov opened this issue Jan 2, 2021 · 0 comments

Comments

@tshatrov
Copy link

tshatrov commented Jan 2, 2021

I often have to generate regexes dynamically. For this the tree syntax of CL-PPCRE is the most optimal solution. However I have discovered a strange corner case. In the documentation it says that

The symbol :VOID is equivalent to the empty string.

However in practice the empty string "" and :VOID have different behavior in some cases.

Consider two parse trees: (:sequence "" "a") and (:sequence :void "a"). Logically both are supposed to match "a". However

(ppcre:create-scanner '(:sequence "" "a"))

results in an error:

Invalid index 0 for (SIMPLE-ARRAY CHARACTER (0)), should be a non-negative integer below 0.
   [Condition of type SB-INT:INVALID-ARRAY-INDEX-ERROR]

The version with :void works just fine. Also if the empty string is not the first item of a sequence, it also works.

However if :sequence is replaced by :alternation, empty string causes an error in any position!

This behavior makes it harder to create dynamic regex trees, since I need to check if a string is empty and replace it with :void to avoid the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant