pigpigyyy / Yuescript

A Moonscript dialect compiles to Lua.
http://yuescript.org
MIT License
443 stars 38 forks source link

Improve YueScript support to continue expression on newline #124

Open GokuHiki opened 1 year ago

GokuHiki commented 1 year ago

Currently YueScript only supports continue expression on newline if the operator is at the end of the line. This is helpful but for me I prefer to put the operator at the beginning of the line.

I hove YueScript can support continue expression on newline if the operator is at the beginning of the line. This is more consistent with the other languages, it's more readable and easier to comment out a expression clause for convenient.

exp = longExpMain
  or longExpA
  or longExpB
  or longExpC
  -- or longExpD
  --  easier to comment out when to experiment with code

Of course, I know I can put \ at the end of line but it just make code too ugly to look at and not readable. Thanks and regards!

pigpigyyy commented 1 year ago

There are now four valid cases conflicting with binary operators at the start of newlines.

do
  a = value
  <= f

x = do
  a = value
  < index >:abc

do
  a = value
  -1 |> f

do
  a = value
  ~x |> f

We can either support the new syntax without <=, <, - and ~ or force requiring a block indent to put these operators in newlines.

exp = longExpMain
          <= longExpA -- a same indent
          < longExpB -- required for
          ~ longExpC -- every expression
<= backcall
GokuHiki commented 1 year ago

YueScript is a programming language that is designed to easy readable with whitespaces significant so it would make sense to force requires a block indent with multiple lines expression. It is more consistent with the rest of the language that depends on indent whitespaces heavily. And it is sure more readable this way: when you see a block indent with an operator prefix, you know it belongs to a multiple lines expression.

By the way, if do this way, there are still conflicts with the current syntax, for example:

do
  a = b
    * c

Thanks and regards!