Skip to content

v0.8.0

Latest

Choose a tag to compare

@leafo leafo released this 22 Oct 20:54
· 2 commits to master since this release
v0.8.0

New parser

The LPeg parser has been replaced. The grammar is defined in moonscript/parse/grammar.moon and compiled by pgen into a native C module, moonscript.parse.native. A pure Lua version of the same grammar is included as moonscript.parse.slow, a drop-in replacement for the native module.

Parsing is around 5x faster:

Interpreter LPeg parser New parser Speedup
Lua 5.1.5 0.947s 0.180s 5.3x
LuaJIT 2.1 0.817s 0.141s 5.8x

(Parse time for a 405 file, 58,296 line corpus, best of 5 passes.)

The parser produces the same syntax trees as the LPeg grammar. Other changes:

  • Parse error messages have a new format: <message> at line <n>, column <m>: followed by the offending line and a ^ marker, replacing Failed to parse: [<n>] >> <line>. Anything matching on the old error text will need updating.
  • moonscript.parse no longer exports build_grammar and extract_line, and the moonscript.parse.util, moonscript.parse.literals and moonscript.parse.env modules have been removed.
  • The MOONSCRIPT_PARSER environment variable is no longer used.
  • Note: LPeg is still a dependency: moonscript.errors and bin/moon-tags use it for parsing unrelated to MoonScript source.

New Features

  • moonc --correlate writes output where the line numbers of the generated Lua match the line numbers of the source, as closely as possible, so errors and stack traces point at the right line without a rewriter. The option is also available as correlate: true in the compile options to moonscript.base functions like to_lua and loadstring. (#312)
  • moonc - (read from stdin) can now be combined with other flags, such as --lint, -o, -T, -X, --transform and --correlate. It can't be used with --watch or --output-to.

Changes

  • Compile errors use the same format as the new parse errors: failed to compile: <message> at line <n>, column <m>: followed by the offending line and a ^ marker, replacing Compile error: <message> and [<n>] >> <line>.
  • The moonscript.cmd.args module has been removed.

Bug Fixes

  • Anonymous classes store false instead of nil in the name slot of the syntax tree, which fixes unpack dropping the trailing class fields on Lua 5.5.
  • The native parser's callback modules are loaded before the parser module.

Binaries

  • The static binaries embed precompiled bytecode for MoonScript's modules, which speeds up startup.