Skip to content
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

[BUG] alter does not consume leading whitespace #246

Open
david-davies opened this issue Nov 26, 2024 · 0 comments · May be fixed by #223
Open

[BUG] alter does not consume leading whitespace #246

david-davies opened this issue Nov 26, 2024 · 0 comments · May be fixed by #223
Labels
bug Something isn't working

Comments

@david-davies
Copy link

Description

alter does not consume leading whitespace according to the new whitespace parser.

Reproduction Steps

This issue was originally found in gigaparsec, and I do not have scala installed, so this will be in haskell.
Assume the lexical description has whitespaceIsContextDependent = True, and the default whitespace parser does not consider newlines (\n) to be whitespace.
Then consider this expression parser:

spaceOrNewLine = Just (\c -> c == ' ' || c == '\n')

Expr = ExprNum Int | ...

expr = number 
  <|> ...
  <|> ("(" *> alter spaceOrNewLine expr <* ")")

Plain numbers can be preceded by only spaces, whereas a parenthesised expression allows for newlines.

Expected behavior

I would expect the following file to parse:

(
   2 )

and produce ExprInt 2.
However, we instead get the error:

Error: (line 1, column 2):
  unexpected newline
  expected parentheses
  >(
    ^
  >  2 )

This is confusing, as we have changed the definition of whitespace, but so far whitespace trailing "(" has only been consumed using the old definition.
I would expect any trailing whitespace according to the new definition be consumed also.

Additional context

Parsley Version: Gigaparsec 0.3.0.0
Scala Version: GHC 8.10-9.8

Suggested Fix

The defn of the alter combinator,

wsImpl.rollback(wsImpl.setDuring(whiteSpace(newSpace))(within))

should probably be changed to

wsImpl.rollback(wsImpl.setDuring(whiteSpace(newSpace))(whiteSpace *> within))

or whatever the scala syntax for *> is.

@david-davies david-davies added the bug Something isn't working label Nov 26, 2024
@j-mie6 j-mie6 linked a pull request Jan 4, 2025 that will close this issue
40 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant