Repository navigation
Various pcre-printing fixups - #547
Merged
Merged
Conversation
This is implicit in the pcre syntax. But exists none the less.
`a{1}{2}` would be a syntax error, and `a*?` or whatever other kind of bewildering syntax pcre has is not what we mean.
The goal here is to emit pcre syntax, this is pcre syntax. Don't look at me like that.
This avoids the syntax "leak" problem around local flags within a group. But does give us a possibly separate bug, where I think we might drop flags at the top level. I'm not sure. I'll think about that separately. I like that this means I don't need to pass group0 all the way through the recursion though.
`x(?![\x00-\xff])a|b|cy` is strictly worse than the input of `x[^abc]y` but these are independent issues.
Always with the off by ones. This and fencepost errors. This was visible e.g. before: ``` ; ./build/bin/re -bpl dot '[A-z]' | grep A-Z S0 -> S1 [ weight = 3, label = <[A-Z\-z]> ]; ``` where `[` should be present after `Z` but is missing. That's two ranges, that the `\` is not escaped is due to the dot syntax for `<...>` labels. Don't be distracted by the `[...]` syntax for the class, that's coincidental. after: ``` ; ./build/bin/re -bpl dot '[A-z]' | grep A-Z S0 -> S1 [ weight = 3, label = <[A-Z[-z]> ]; ```
…e where possible. I'm surprised I didn't make this already. But then I try to avoid things that sometimes succeed. I'm not sure. Maybe we could use this during AST -> NFA compilation and skip some work there by recurring through the tree here instead, sort of like lookahead, but recursively. for literals.
This is roughly the same idea as for the labels on the FSM dot output, except instead of populating a bitmap from a set of edges, here we're recuring through subtrees. And here we also have the possibility that some things are not expressible, so we have to fall through to those too.
… of `ast_expr_charset()`. I figure it has to be here for sake of AST_EXPR_SUBTRACT, otherwise I end up implementing the same thing twice when recurring in the caller. While I'm here I've made an attempt to fill out the other cases for expr nodes, even though we don't construct them. These are best effort; it's always okay to decline to construct a bitmap here. There's some complication around nullable children of alts here, I have tried to explain it in comments. I'm pretty sure we need both places.
This is one of those pay-off commits where the prior run of work all comes together. I love this stuff.
This gives stuff like: ``` ; ./build/bin/re -br pcre -l pcre -i '[M-Za-z]' [a-z] ``` which is lovely. but I have not attempted to address nested flags yet: ``` ; ./build/bin/re -br pcre -l pcre '(?:(?i)[M-Za-z])' [A-Za-z] ```
This is by demogran's theorem for the same conditions with `continue;` above. This really isn't clear, because the `||` in the top loop is spelled out as two consecutive blocks, and the structure for both doesn't correspond. I'm trying to fix the bug here, and I'll see if I can rephrase it later. This is what my "awful" comment is about...
… for charset output. This was just too offensive to stand. It's still more awkward than I'd like, but at least it doesn't have the internal structural mismatch between two loops now.
…literal children. This gets us: ``` ; re -br pcre -l pcre '(?i)(?:x|(?-i)((?i)[ab]))' (?i)[abx] ``` which I think is pretty cool.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
re -l pcrerenders out the AST to pcre syntax.Previously that was only a rough approximation. This PR is a pass at making it correct.
It's probably still not correct. But still.
Several essentially unrelated improvements here, especially around the bitmap construction.
As good an example as any: