osa1 / language-lua

Lua parser and pretty-printer
BSD 3-Clause "New" or "Revised" License
51 stars 17 forks source link

Ambiguous function call syntax is pretty-printed incorrectly #28

Closed glguy closed 8 years ago

glguy commented 8 years ago

Lua's grammar is ambiguous when it comes to parsing f()(f)(). Just following the grammar this could be either one statement or two. It'll probably be messy, but the pretty printer needs to know when the previous statement was a function call or if the previous statement ended in an expression that could be a prefix expression for a function call.

*Language.Lua> let Right x = parseText chunk "local x=f();(f)()" in pprint x
local x = f()

(f)()
*Language.Lua> let Right x = parseText chunk "f();(f)()" in pprint x
f()

(f)()
glguy commented 8 years ago

It occurs to me that we should simply always emit the ; for empty statements. It improves the round trip story and resolves a portion of this issue. (Manually generated syntax trees could still produce incorrect concrete syntax)