MoonScript v0.2.2 is released
leafo.net
leafo.net
Any thoughts of letting the 'do' keyword support coffeescript-style 'do' semantics as well? Invoking a multi-line anonymous function is currently a bit impractical, and allowing do to invoke a single function parameter would make that a lot nicer, and allow for capturing variable's in a closure more easily. Example from the coffeescript docs:
for filename in list
do (filename) ->
fs.readFile filename, (err, contents) ->
compile filename, contents.toString()
[1] http://www.codingspellbook.com/http://moonscript.org/compiler/#14
Here I create 10 functions closed on the loop value. Then I loop over them and call them all. In JavaScript this would print 10 10 times, but in Lua we get the 1 through 10.
Keep up the good work!
I've been working on a source translator, sort of like coffeescript for VimL [1], and I can't imagine writing the parser myself instead a BNF grammar (but please correct me if I'm wrong, I only took a cursory look at the src)
It's a great library, I highly recommend it.
I've assembled a few parsers using various tools, and I must say PEGs are my favorite. They are very flexible and performance is comparable. (even CoffeeScript 2.0 is being written with a PEG.)
You can check out the guts of the parser here: https://github.com/leafo/moonscript/blob/master/moonscript/p...
If I get it right, MoonScript aims at doing the same for Lua. The difference is that (1) Lua ecosystem isn't nearly as unavoidable as JS' and (2) Although some design decisions in Lua aren't consensual, the one thing you cannot call the language is "messy". IMO, Lua's main drawback is that by being so flexible and lacking an interventionist benevolent dictator, it doesn't grow standard coding practices, as Python does. Of course, creating alternative syntaxes isn't likely to improve the matter.
But in the end, it's fun to write compilers, and this is a perfectly legitimate reason to write one.
MoonScript also gets rid of a lot of the more verbose parts of lua, and replaces them with CoffeeScript-like versions. For example: shorter anonymous function syntax, syntactically significant whitespace, default local variables.