unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.8k stars 271 forks source link

Peculiar whitespace sensitivity #1775

Open mitchellwrosen opened 3 years ago

mitchellwrosen commented 3 years ago

Hi, I'm not exactly sure if this is a bug, but I observed some odd parse errors when trying to lay out some code:

First, a valid expression.

parseEcl : '{Parser} ()
parseEcl _ =
  or 
    '(theString "amb") 
    '(or '(theString "blu") '(theString "brn"))

If I move the arguments to the second or to a new line, it works.

parseEcl : '{Parser} ()
parseEcl _ =
  or 
    '(theString "amb") 
    '(or 
    '(theString "blu") '(theString "brn"))

Indenting the arguments by a single space produces this error.

parseEcl : '{Parser} ()
parseEcl _ =
  or 
    '(theString "amb") 
    '(or 
     '(theString "blu") '(theString "brn"))

  /Users/mitchell/scratch.u:59:7:
  unexpected <virtual semicolon>
  expecting [, bang, false, handle, if, let, quote, termLink, true, tuple, or typeLink
     59 |      '(theString "blu") '(theString "brn"))

A second space yields a different error.

parseEcl : '{Parser} ()
parseEcl _ =
  or 
    '(theString "amb") 
    '(or 
      '(theString "blu") '(theString "brn"))

  /Users/mitchell/scratch.u:59:7:
  unexpected '
     59 |       '(theString "blu") '(theString "brn"))

And finally, with three or more spaces the expression becomes valid again.

parseEcl : '{Parser} ()
parseEcl _ =
  or 
    '(theString "amb") 
    '(or 
       '(theString "blu") '(theString "brn"))
aryairani commented 4 months ago

This does strike me as a bug