From c3fd7812ce15a9c9a49cae8e5b418f32a9a9d10b Mon Sep 17 00:00:00 2001 From: leaf corcoran Date: Tue, 1 Nov 2011 19:54:13 -0700 Subject: [PATCH] fixed with's dot chain from not parsing all types after first chain item --- moonscript/parse.lua | 16 ++++++---------- tests/inputs/with.moon | 5 +++++ tests/outputs/with.lua | 8 +++++++- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/moonscript/parse.lua b/moonscript/parse.lua index 32f9fa7..2be6469 100644 --- a/moonscript/parse.lua +++ b/moonscript/parse.lua @@ -365,14 +365,16 @@ local build_grammar = wrap(function() FnArgs = symx"(" * Ct(ExpList^-1) * sym")" + sym"!" * -P"=" * Ct"", + ChainTail = (ChainItem^1 * ColonSuffix^-1 + ColonSuffix), + -- a list of funcalls and indexs on a callable Chain = Callable * (ChainItem^1 * ColonSuffix^-1 + ColonSuffix) / mark"chain", -- shorthand dot call for use in with statement DotChain = - (sym"." * Cc(-1) * (_Name / mark"dot") * ChainItem^0) / mark"chain" + + (sym"." * Cc(-1) * (_Name / mark"dot") * ChainTail^-1) / mark"chain" + (sym"\\" * Cc(-1) * ( - (_Name * Invoke / mark"colon") * ChainItem^0 + + (_Name * Invoke / mark"colon") * ChainTail^-1 + (_Name / mark"colon_stub") )) / mark"chain", @@ -448,15 +450,9 @@ local build_grammar = wrap(function() local tree local args = {...} - local pass, err = pcall(function() + local pass, err = assert(pcall(function() tree = self._g:match(str, unpack(args)) - end) - - if not pass then - local line_no = pos_to_line(last_pos) - print("stopped at", line_no) - error(err) - end + end)) if not tree then local line_no = pos_to_line(last_pos) diff --git a/tests/inputs/with.moon b/tests/inputs/with.moon index 4d477bc..e9b35ac 100644 --- a/tests/inputs/with.moon +++ b/tests/inputs/with.moon @@ -31,3 +31,8 @@ x = { \okay! } +with foo + \prop"something".hello + .prop\send(one) + .prop\send one + diff --git a/tests/outputs/with.lua b/tests/outputs/with.lua index 5bcd3a0..a0af190 100644 --- a/tests/outputs/with.lua +++ b/tests/outputs/with.lua @@ -39,4 +39,10 @@ x = { return _with_0 end end)() -} \ No newline at end of file +} +do + local _with_0 = foo + local _ = _with_0:prop("something").hello + _with_0.prop:send(one) + _with_0.prop:send(one) +end \ No newline at end of file