Skip to content

Parsers.rep() hides failures #146

@gzoller

Description

@gzoller

I noticed an issue reported here in stackoverflow: here

Curious, I looked up the code for rep() and noticed this simple one-liner:

def rep[T](p: => Parser[T]): Parser[List[T]] = rep1(p) | success(List())

Hmm. This looks like it repeats but upon a failure just returns success(List()), which seems to match my observed behavior. Am I reading this correctly?

If so... then this hides the failure. If in 'p' I've returned a failure, the associated message is swallowed, and my calling program has no idea whether 1) parsing fully succeeded or 2) parsing partially succeeded, and if #2 then why it failed.

Are there circumstances when swallowing the failure is a desirable thing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions