Multi-line comment support
Issue #127 should disappear with this. If DelayedLine ever becomes implemented some changes will be necessary, but until then everything should work nicely.
Also added multiline support to the parser.
I get this error when trying to run moonc after your patch. Here's a similar issue with that popped up with lpeg 0.12: https://github.com/mascarenhas/cosmo/issues/5
bin/moonc moon/ moonscript/
lua: ./moonscript/parse.lua:395: bad argument #2 to '__div' (invalid replacement value)
stack traceback:
[C]: in function '__div'
./moonscript/parse.lua:395: in function 'build_grammar'
./moonscript/parse.lua:658: in function 'string'
bin/moonc:121: in function 'compile_file'
bin/moonc:169: in function 'compile_and_write'
bin/moonc:402: in main chunk
[C]: in ?
Makefile:12: recipe for target 'compile' failed
make: *** [compile] Error 1
The error message refers to this line:
Comment = P"--" * (V"NoSpaceLuaString" / 0 * Space^-1 + (1 - S"\r\n")^0 * #Stop),
And mentions a "bad argument 2 to _div" which I guess refers to the 0 which I placed there so that all captures made by the LuaString rule would be dropped (otherwise the compiler thinks it found a "string" line decorator if the comment was at the end a line). This behavior is documented on the official lpeg page and works fine for me using a fresh lpeg v0.12 from LuaRocks. I do not know why it does not work for you, but since Cmt() also drops the captures made by the enclosed pattern, I modified the grammar to use that function instead.
What's the status on merging this @leafo?
The line number fix was manually merged in. The multiline comment was not. I've been lingering on adding it because it makes parsing about 20% slower if I remember correctly. I wanted to take some time to see if is a more efficient implementation.
Any update on this?
It would be pretty nice to have multi-line comments: what sort of % performance hit would be acceptable?