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

Parser fails on operator after newline without indentation, with bad message #5551

Open
runarorama opened this issue Jan 21, 2025 · 0 comments
Labels

Comments

@runarorama
Copy link
Contributor

runarorama commented Jan 21, 2025

If you write

x = 
  [1,2,3]
  |> List.map increment

This results in an error:

  I got confused here:
  
      3 |   |> List.map increment
  
  
  I was surprised to find a |> here.
  I was expecting one of these instead:
  
  * bang
  * binding
  * do
  * false
  * force
  * handle
  * if
  * lambda
  * let
  * pattern
  * quote
  * termLink
  * true
  * tuple
  * typeLink

This error message doesn't highlight the issue properly, which is that it parsed a virtual semicolon followed by an expression that begins with an operator.

The parser could give a better error message like:

  I was surprised to find a |> here, as an expression can't begin with an operator.
  Add indentation if this line is supposed to be part of the expression on the previous line.

Better yet, we should just handle this as a special rule. Don't parse a virtual semicolon if the next line is at the same indentation and begins with an operator. Possibly also don't parse a virtual semicolon if the line ends with an operator and the next line is at the same indentation.

@runarorama runarorama added the bug label Jan 21, 2025
@runarorama runarorama changed the title Lexer fails on operator after newline without indentation, with bad message Parser fails on operator after newline without indentation, with bad message Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant