Repository navigation
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, replacingFailed to parse: [<n>] >> <line>. Anything matching on the old error text will need updating. moonscript.parseno longer exportsbuild_grammarandextract_line, and themoonscript.parse.util,moonscript.parse.literalsandmoonscript.parse.envmodules have been removed.- The
MOONSCRIPT_PARSERenvironment variable is no longer used. - Note: LPeg is still a dependency:
moonscript.errorsandbin/moon-tagsuse it for parsing unrelated to MoonScript source.
New Features
moonc --correlatewrites 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 ascorrelate: truein the compile options tomoonscript.basefunctions liketo_luaandloadstring. (#312)moonc -(read from stdin) can now be combined with other flags, such as--lint,-o,-T,-X,--transformand--correlate. It can't be used with--watchor--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, replacingCompile error: <message>and[<n>] >> <line>. - The
moonscript.cmd.argsmodule has been removed.
Bug Fixes
- Anonymous classes store
falseinstead ofnilin the name slot of the syntax tree, which fixesunpackdropping 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.