Skip to content

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

Open
@runarorama

Description

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.

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions