Open refi64 opened 1 year ago
It is a syntax precedence problem. To support syntax like:
readFile "example.txt"
|> extract language, {}
|> parse language
|> emit
|> render
|> print
The multiline pipes are parsed as statements instead of parts of an expression for the moment. So that the newline characters are breaking the expression in the end of function call argument. If we make pipe syntax a higher precedence, the example codes above will be parsed as:
readFile("example.txt" |> extract(language, {} |> parse(language |> emit |> render |> print))
So we have to carefully write every bracket for the right multiline pipes parsing that way.
readFile("example.txt")
|> extract(language, {})
|> parse(language)
|> emit
|> render
|> print
That makes sense, but I feel like the indentation is what makes this weirder? Like I'd certainly expect that behavior from, say:
f
* a
|> b
which is closer to the example you gave in terms of indentation. The weird part in the original example to me is that it's reaching across multiple levels of indentation.
In the current Yuescript compiler the orignal code:
f
* a
|> b
is just seen as:
[expression][newline character]
[advanced indentation][pipe expression]
And there is no rule to tell different [advanced indentation] levels should have different meanings.
Right now, if I compile this code:
the resulting Lua is:
This is the opposite of what I'd expect: based on the indentation, I would've thought it would be parsed as
f({ a|> b })
, notf({ a }) |> b
. If I use an explicit slash:then it compiles like I'd expect:
I'm not sure if this is intentional? But it was certainly rather confusing :sweat_smile: