-
Notifications
You must be signed in to change notification settings - Fork 235
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
PEG look
rule sometimes produces captures, despite documentation otherwise
#1554
Comments
I interpret that to mean that the first argument The example posted uses What do you think? Is that interpretation off? Update: I think it is off (^^; [1] It is true that the word "can" is used in the description:
but I think the intent was to exclude possibilities other than integers. |
Sorry, I think I've confused things by using an integer and single quote in my example. This is equivalent and also produces a capture:
Produces: If I specify a non-zero offset, it also produces a capture:
Produces: These modifications still match, but don't produce any captures:
|
I agree there is a discrepancy between the documentation and the behavior, at least for: (peg/match '(* "a" (> 1 (capture "c"))) "abc") If I had to guess, I would say that one intent for stating that [1] May be part of the idea was to not have to use |
I don't know when it was decided that lookahead should not produce captures, but in most cases they do. We should fix the docs here. The bug here is actually in the behavior of Consider the code: (peg/match '(any (> '1)) "abc") without the termination check, this peg would capture an infinite number of However, I would argue that there is no need for this termination check at all for the There are a number of fixes to this, but this is a strange interaction between |
optionals. This fixes some undesirable interplay between lookaheads and looping (repeating) rules where lookaheads caused the loop to immediately terminate _and_ discard any captures. This change adds an exception if there is a 0-width match at the first iteration of the loop, in which case captures will be kept, although the loop will still be terminated (any further iteration of the loop would possibly cause an infinite loop). This allows optionals to work as expected when combined with lookahead. There is also a question of whether or not optional should be implemented as separate rule rather than as `(between 0 1 subrule)`.
@edsrzf Thanks for making this issue. In addition to its value related to helping to improve Janet, it surfaced some bugs in my understanding and own code (^^; I have an idea for modifying the documentation of In addition to trying to address:
I've tried to make some changes that might reduce confusion (though may be it was just me!). |
The PEG
look
rule documentation states "patt will not produce captures". However it does sometimes produce captures. For example:Result:
@["b"]
However sometimes it doesn't:
Result:
@[]
I think it would be pretty useful if
look
consistently produced captures, but either way I think the behavior and documentation should be consistent. (If we do decide to produce captures, please also consider #1553.)The text was updated successfully, but these errors were encountered: