Skip to content

lookAhead consumes input on failure #73

Closed
@chtenb

Description

@chtenb

Describe the bug

-- | Read ahead without consuming input.
lookAhead :: forall a. Parser a -> Parser a
lookAhead (Parser p) = Parser \s ->
  case p s of
    Right { result } -> Right { result, suffix: s }
    left -> left

As you can see from the definition the suffix is "reset" to s in case of success, but in case of error the error is passed on as is, meaning the PosString at the failure is propagated.

Expected behavior
I would expect the function to do what its documentation suggests: to not consume any input. Or if this is really not intended I would expect the documentation to be correct and not misleading.

Additional context
This cost me quite some debugging time :) I'm currently working around it by using try $ lookAhead everywhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugSomething that should function correctly isn't.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions