peg: repeat1-related parsers handle repeated ignores#3171
peg: repeat1-related parsers handle repeated ignores#3171olus2000 wants to merge 1 commit intofactor:masterfrom
Conversation
|
Interesting! Was going to merge it, wanted to think about it for a moment. |
|
Of course, what I implemented is definitely not the correct solution. If you'd prefer another behavior I'm happy to hear it, especially for the question of The usecase this comes from is lexing a language where comments are allowed between any two tokens. I wanted a way to never include the comments in the tokens in the first place instead of filtering them out after parsing. |
|
I don't have a problem with repeat1 returning an empty output, since the name repeat1 describes what it parses, not what the output is. If the parser it takes doesn't return an output, then I don't think it's a terrible surprise for a user that repeat1 doesn't have anything to pass back. |
Current behavior of
repeat0,repeat1and related parsers is to pass anyignorevalues generated by the encapsulated parsers in the resulting AST.This pull request changes this behavior to be similar to the
seqfamily of parsers which will excludeignores from their output.Note that the behavior I implemented considers a
repeat1parser which successfully matched its enclosing parser but got onlyignores a successful match nevertheless, creating a case whererepeat1may produce an empty sequence AST. In my opinion if the content ofrepeat1matched the wholerepeat1should be a success, no matter what the resulting AST is.