rufus-lua-moon 0.2.6.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +3 -0
  3. data/.travis.yml +9 -0
  4. data/FarMenu.ini +16 -0
  5. data/README.md +10 -4
  6. data/Rakefile +13 -0
  7. data/lib/rufus/lua/moon/version.rb +2 -2
  8. data/rufus-lua-moon.gemspec +5 -1
  9. data/test/chain.rb +6 -0
  10. data/test/compile.rb +12 -0
  11. data/test/path.rb +15 -0
  12. data/test/path27.moon +3 -0
  13. data/test/req.rb +17 -0
  14. data/test/ver.rb +23 -0
  15. data/vendor/{lua → leafo}/moon/all.moon +0 -0
  16. data/vendor/{lua → leafo}/moon/init.moon +0 -0
  17. data/vendor/{lua → leafo}/moonscript/base.lua +0 -0
  18. data/vendor/{lua → leafo}/moonscript/cmd/coverage.lua +0 -0
  19. data/vendor/{lua → leafo}/moonscript/cmd/lint.lua +118 -13
  20. data/vendor/{lua → leafo}/moonscript/cmd/moonc.lua +5 -12
  21. data/vendor/{lua → leafo}/moonscript/compile/statement.lua +1 -4
  22. data/vendor/{lua → leafo}/moonscript/compile/value.lua +2 -8
  23. data/vendor/{lua → leafo}/moonscript/compile.lua +21 -19
  24. data/vendor/{lua → leafo}/moonscript/data.lua +0 -0
  25. data/vendor/{lua → leafo}/moonscript/dump.lua +0 -0
  26. data/vendor/{lua → leafo}/moonscript/errors.lua +1 -1
  27. data/vendor/{lua → leafo}/moonscript/init.lua +0 -0
  28. data/vendor/{lua → leafo}/moonscript/line_tables.lua +0 -0
  29. data/vendor/leafo/moonscript/parse/env.lua +69 -0
  30. data/vendor/leafo/moonscript/parse/literals.lua +34 -0
  31. data/vendor/leafo/moonscript/parse/util.lua +267 -0
  32. data/vendor/leafo/moonscript/parse.lua +235 -0
  33. data/vendor/{lua → leafo}/moonscript/transform/destructure.lua +12 -18
  34. data/vendor/{lua → leafo}/moonscript/transform/names.lua +2 -8
  35. data/vendor/{lua → leafo}/moonscript/transform.lua +1 -4
  36. data/vendor/{lua → leafo}/moonscript/types.lua +2 -8
  37. data/vendor/{lua → leafo}/moonscript/util.lua +11 -5
  38. data/vendor/{lua → leafo}/moonscript/version.lua +1 -1
  39. metadata +71 -25
  40. data/vendor/lua/moonscript/parse.lua +0 -639
@@ -0,0 +1,34 @@
1
+ local safe_module
2
+ safe_module = require("moonscript.util").safe_module
3
+ local S, P, R, C
4
+ do
5
+ local _obj_0 = require("lpeg")
6
+ S, P, R, C = _obj_0.S, _obj_0.P, _obj_0.R, _obj_0.C
7
+ end
8
+ local White = S(" \t\r\n") ^ 0
9
+ local plain_space = S(" \t") ^ 0
10
+ local Break = P("\r") ^ -1 * P("\n")
11
+ local Stop = Break + -1
12
+ local Comment = P("--") * (1 - S("\r\n")) ^ 0 * #Stop
13
+ local Space = plain_space * Comment ^ -1
14
+ local SomeSpace = S(" \t") ^ 1 * Comment ^ -1
15
+ local SpaceBreak = Space * Break
16
+ local EmptyLine = SpaceBreak
17
+ local AlphaNum = R("az", "AZ", "09", "__")
18
+ local Name = C(R("az", "AZ", "__") * AlphaNum ^ 0)
19
+ local Num = P("0x") * R("09", "af", "AF") ^ 1 * (S("uU") ^ -1 * S("lL") ^ 2) ^ -1 + R("09") ^ 1 * (S("uU") ^ -1 * S("lL") ^ 2) + (R("09") ^ 1 * (P(".") * R("09") ^ 1) ^ -1 + P(".") * R("09") ^ 1) * (S("eE") * P("-") ^ -1 * R("09") ^ 1) ^ -1
20
+ local Shebang = P("#!") * P(1 - Stop) ^ 0
21
+ return safe_module("moonscript.parse.literals", {
22
+ White = White,
23
+ Break = Break,
24
+ Stop = Stop,
25
+ Comment = Comment,
26
+ Space = Space,
27
+ SomeSpace = SomeSpace,
28
+ SpaceBreak = SpaceBreak,
29
+ EmptyLine = EmptyLine,
30
+ AlphaNum = AlphaNum,
31
+ Name = Name,
32
+ Num = Num,
33
+ Shebang = Shebang
34
+ })
@@ -0,0 +1,267 @@
1
+ local unpack
2
+ unpack = require("moonscript.util").unpack
3
+ local P, C, S, Cp, Cmt, V
4
+ do
5
+ local _obj_0 = require("lpeg")
6
+ P, C, S, Cp, Cmt, V = _obj_0.P, _obj_0.C, _obj_0.S, _obj_0.Cp, _obj_0.Cmt, _obj_0.V
7
+ end
8
+ local ntype
9
+ ntype = require("moonscript.types").ntype
10
+ local Space
11
+ Space = require("moonscript.parse.literals").Space
12
+ local Indent = C(S("\t ") ^ 0) / function(str)
13
+ do
14
+ local sum = 0
15
+ for v in str:gmatch("[\t ]") do
16
+ local _exp_0 = v
17
+ if " " == _exp_0 then
18
+ sum = sum + 1
19
+ elseif "\t" == _exp_0 then
20
+ sum = sum + 4
21
+ end
22
+ end
23
+ return sum
24
+ end
25
+ end
26
+ local Cut = P(function()
27
+ return false
28
+ end)
29
+ local ensure
30
+ ensure = function(patt, finally)
31
+ return patt * finally + finally * Cut
32
+ end
33
+ local extract_line
34
+ extract_line = function(str, start_pos)
35
+ str = str:sub(start_pos)
36
+ do
37
+ local m = str:match("^(.-)\n")
38
+ if m then
39
+ return m
40
+ end
41
+ end
42
+ return str:match("^.-$")
43
+ end
44
+ local mark
45
+ mark = function(name)
46
+ return function(...)
47
+ return {
48
+ name,
49
+ ...
50
+ }
51
+ end
52
+ end
53
+ local pos
54
+ pos = function(patt)
55
+ return (Cp() * patt) / function(pos, value)
56
+ if type(value) == "table" then
57
+ value[-1] = pos
58
+ end
59
+ return value
60
+ end
61
+ end
62
+ local got
63
+ got = function(what)
64
+ return Cmt("", function(str, pos)
65
+ print("++ got " .. tostring(what), "[" .. tostring(extract_line(str, pos)) .. "]")
66
+ return true
67
+ end)
68
+ end
69
+ local flatten_or_mark
70
+ flatten_or_mark = function(name)
71
+ return function(tbl)
72
+ if #tbl == 1 then
73
+ return tbl[1]
74
+ end
75
+ table.insert(tbl, 1, name)
76
+ return tbl
77
+ end
78
+ end
79
+ local is_assignable
80
+ do
81
+ local chain_assignable = {
82
+ index = true,
83
+ dot = true,
84
+ slice = true
85
+ }
86
+ is_assignable = function(node)
87
+ if node == "..." then
88
+ return false
89
+ end
90
+ local _exp_0 = ntype(node)
91
+ if "ref" == _exp_0 or "self" == _exp_0 or "value" == _exp_0 or "self_class" == _exp_0 or "table" == _exp_0 then
92
+ return true
93
+ elseif "chain" == _exp_0 then
94
+ return chain_assignable[ntype(node[#node])]
95
+ else
96
+ return false
97
+ end
98
+ end
99
+ end
100
+ local check_assignable
101
+ check_assignable = function(str, pos, value)
102
+ if is_assignable(value) then
103
+ return true, value
104
+ else
105
+ return false
106
+ end
107
+ end
108
+ local format_assign
109
+ do
110
+ local flatten_explist = flatten_or_mark("explist")
111
+ format_assign = function(lhs_exps, assign)
112
+ if not (assign) then
113
+ return flatten_explist(lhs_exps)
114
+ end
115
+ for _index_0 = 1, #lhs_exps do
116
+ local assign_exp = lhs_exps[_index_0]
117
+ if not (is_assignable(assign_exp)) then
118
+ error({
119
+ assign_exp,
120
+ "left hand expression is not assignable"
121
+ })
122
+ end
123
+ end
124
+ local t = ntype(assign)
125
+ local _exp_0 = t
126
+ if "assign" == _exp_0 then
127
+ return {
128
+ "assign",
129
+ lhs_exps,
130
+ unpack(assign, 2)
131
+ }
132
+ elseif "update" == _exp_0 then
133
+ return {
134
+ "update",
135
+ lhs_exps[1],
136
+ unpack(assign, 2)
137
+ }
138
+ else
139
+ return error("unknown assign expression: " .. tostring(t))
140
+ end
141
+ end
142
+ end
143
+ local format_single_assign
144
+ format_single_assign = function(lhs, assign)
145
+ if assign then
146
+ return format_assign({
147
+ lhs
148
+ }, assign)
149
+ else
150
+ return lhs
151
+ end
152
+ end
153
+ local sym
154
+ sym = function(chars)
155
+ return Space * chars
156
+ end
157
+ local symx
158
+ symx = function(chars)
159
+ return chars
160
+ end
161
+ local simple_string
162
+ simple_string = function(delim, allow_interpolation)
163
+ local inner = P("\\" .. tostring(delim)) + "\\\\" + (1 - P(delim))
164
+ if allow_interpolation then
165
+ local interp = symx('#{') * V("Exp") * sym('}')
166
+ inner = (C((inner - interp) ^ 1) + interp / mark("interpolate")) ^ 0
167
+ else
168
+ inner = C(inner ^ 0)
169
+ end
170
+ return C(symx(delim)) * inner * sym(delim) / mark("string")
171
+ end
172
+ local wrap_func_arg
173
+ wrap_func_arg = function(value)
174
+ return {
175
+ "call",
176
+ {
177
+ value
178
+ }
179
+ }
180
+ end
181
+ local flatten_func
182
+ flatten_func = function(callee, args)
183
+ if #args == 0 then
184
+ return callee
185
+ end
186
+ args = {
187
+ "call",
188
+ args
189
+ }
190
+ if ntype(callee) == "chain" then
191
+ local stub = callee[#callee]
192
+ if ntype(stub) == "colon_stub" then
193
+ stub[1] = "colon"
194
+ table.insert(stub, args)
195
+ else
196
+ table.insert(callee, args)
197
+ end
198
+ return callee
199
+ end
200
+ return {
201
+ "chain",
202
+ callee,
203
+ args
204
+ }
205
+ end
206
+ local flatten_string_chain
207
+ flatten_string_chain = function(str, chain, args)
208
+ if not (chain) then
209
+ return str
210
+ end
211
+ return flatten_func({
212
+ "chain",
213
+ str,
214
+ unpack(chain)
215
+ }, args)
216
+ end
217
+ local wrap_decorator
218
+ wrap_decorator = function(stm, dec)
219
+ if not (dec) then
220
+ return stm
221
+ end
222
+ return {
223
+ "decorated",
224
+ stm,
225
+ dec
226
+ }
227
+ end
228
+ local check_lua_string
229
+ check_lua_string = function(str, pos, right, left)
230
+ return #left == #right
231
+ end
232
+ local self_assign
233
+ self_assign = function(name, pos)
234
+ return {
235
+ {
236
+ "key_literal",
237
+ name
238
+ },
239
+ {
240
+ "ref",
241
+ name,
242
+ [-1] = pos
243
+ }
244
+ }
245
+ end
246
+ return {
247
+ Indent = Indent,
248
+ Cut = Cut,
249
+ ensure = ensure,
250
+ extract_line = extract_line,
251
+ mark = mark,
252
+ pos = pos,
253
+ flatten_or_mark = flatten_or_mark,
254
+ is_assignable = is_assignable,
255
+ check_assignable = check_assignable,
256
+ format_assign = format_assign,
257
+ format_single_assign = format_single_assign,
258
+ sym = sym,
259
+ symx = symx,
260
+ simple_string = simple_string,
261
+ wrap_func_arg = wrap_func_arg,
262
+ flatten_func = flatten_func,
263
+ flatten_string_chain = flatten_string_chain,
264
+ wrap_decorator = wrap_decorator,
265
+ check_lua_string = check_lua_string,
266
+ self_assign = self_assign
267
+ }
@@ -0,0 +1,235 @@
1
+ local debug_grammar = false
2
+ local lpeg = require("lpeg")
3
+ lpeg.setmaxstack(10000)
4
+ local err_msg = "Failed to parse:%s\n [%d] >> %s"
5
+ local Stack
6
+ Stack = require("moonscript.data").Stack
7
+ local trim, pos_to_line, get_line
8
+ do
9
+ local _obj_0 = require("moonscript.util")
10
+ trim, pos_to_line, get_line = _obj_0.trim, _obj_0.pos_to_line, _obj_0.get_line
11
+ end
12
+ local unpack
13
+ unpack = require("moonscript.util").unpack
14
+ local wrap_env
15
+ wrap_env = require("moonscript.parse.env").wrap_env
16
+ local R, S, V, P, C, Ct, Cmt, Cg, Cb, Cc
17
+ R, S, V, P, C, Ct, Cmt, Cg, Cb, Cc = lpeg.R, lpeg.S, lpeg.V, lpeg.P, lpeg.C, lpeg.Ct, lpeg.Cmt, lpeg.Cg, lpeg.Cb, lpeg.Cc
18
+ local White, Break, Stop, Comment, Space, SomeSpace, SpaceBreak, EmptyLine, AlphaNum, Num, Shebang, _Name
19
+ do
20
+ local _obj_0 = require("moonscript.parse.literals")
21
+ White, Break, Stop, Comment, Space, SomeSpace, SpaceBreak, EmptyLine, AlphaNum, Num, Shebang, _Name = _obj_0.White, _obj_0.Break, _obj_0.Stop, _obj_0.Comment, _obj_0.Space, _obj_0.SomeSpace, _obj_0.SpaceBreak, _obj_0.EmptyLine, _obj_0.AlphaNum, _obj_0.Num, _obj_0.Shebang, _obj_0.Name
22
+ end
23
+ local SpaceName = Space * _Name
24
+ Num = Space * (Num / function(v)
25
+ return {
26
+ "number",
27
+ v
28
+ }
29
+ end)
30
+ local Indent, Cut, ensure, extract_line, mark, pos, flatten_or_mark, is_assignable, check_assignable, format_assign, format_single_assign, sym, symx, simple_string, wrap_func_arg, flatten_func, flatten_string_chain, wrap_decorator, check_lua_string, self_assign
31
+ do
32
+ local _obj_0 = require("moonscript.parse.util")
33
+ Indent, Cut, ensure, extract_line, mark, pos, flatten_or_mark, is_assignable, check_assignable, format_assign, format_single_assign, sym, symx, simple_string, wrap_func_arg, flatten_func, flatten_string_chain, wrap_decorator, check_lua_string, self_assign = _obj_0.Indent, _obj_0.Cut, _obj_0.ensure, _obj_0.extract_line, _obj_0.mark, _obj_0.pos, _obj_0.flatten_or_mark, _obj_0.is_assignable, _obj_0.check_assignable, _obj_0.format_assign, _obj_0.format_single_assign, _obj_0.sym, _obj_0.symx, _obj_0.simple_string, _obj_0.wrap_func_arg, _obj_0.flatten_func, _obj_0.flatten_string_chain, _obj_0.wrap_decorator, _obj_0.check_lua_string, _obj_0.self_assign
34
+ end
35
+ local build_grammar = wrap_env(debug_grammar, function()
36
+ local _indent = Stack(0)
37
+ local _do_stack = Stack(0)
38
+ local last_pos = 0
39
+ local check_indent
40
+ check_indent = function(str, pos, indent)
41
+ last_pos = pos
42
+ return _indent:top() == indent
43
+ end
44
+ local advance_indent
45
+ advance_indent = function(str, pos, indent)
46
+ local top = _indent:top()
47
+ if top ~= -1 and indent > top then
48
+ _indent:push(indent)
49
+ return true
50
+ end
51
+ end
52
+ local push_indent
53
+ push_indent = function(str, pos, indent)
54
+ _indent:push(indent)
55
+ return true
56
+ end
57
+ local pop_indent
58
+ pop_indent = function()
59
+ assert(_indent:pop(), "unexpected outdent")
60
+ return true
61
+ end
62
+ local check_do
63
+ check_do = function(str, pos, do_node)
64
+ local top = _do_stack:top()
65
+ if top == nil or top then
66
+ return true, do_node
67
+ end
68
+ return false
69
+ end
70
+ local disable_do
71
+ disable_do = function()
72
+ _do_stack:push(false)
73
+ return true
74
+ end
75
+ local pop_do
76
+ pop_do = function()
77
+ assert(_do_stack:pop() ~= nil, "unexpected do pop")
78
+ return true
79
+ end
80
+ local DisableDo = Cmt("", disable_do)
81
+ local PopDo = Cmt("", pop_do)
82
+ local keywords = { }
83
+ local key
84
+ key = function(chars)
85
+ keywords[chars] = true
86
+ return Space * chars * -AlphaNum
87
+ end
88
+ local op
89
+ op = function(chars)
90
+ local patt = Space * C(chars)
91
+ if chars:match("^%w*$") then
92
+ keywords[chars] = true
93
+ patt = patt * -AlphaNum
94
+ end
95
+ return patt
96
+ end
97
+ local Name = Cmt(SpaceName, function(str, pos, name)
98
+ if keywords[name] then
99
+ return false
100
+ end
101
+ return true
102
+ end) / trim
103
+ local SelfName = Space * "@" * ("@" * (_Name / mark("self_class") + Cc("self.__class")) + _Name / mark("self") + Cc("self"))
104
+ local KeyName = SelfName + Space * _Name / mark("key_literal")
105
+ local VarArg = Space * P("...") / trim
106
+ local g = P({
107
+ File,
108
+ File = Shebang ^ -1 * (Block + Ct("")),
109
+ Block = Ct(Line * (Break ^ 1 * Line) ^ 0),
110
+ CheckIndent = Cmt(Indent, check_indent),
111
+ Line = (CheckIndent * Statement + Space * #Stop),
112
+ Statement = pos(Import + While + With + For + ForEach + Switch + Return + Local + Export + BreakLoop + Ct(ExpList) * (Update + Assign) ^ -1 / format_assign) * Space * ((key("if") * Exp * (key("else") * Exp) ^ -1 * Space / mark("if") + key("unless") * Exp / mark("unless") + CompInner / mark("comprehension")) * Space) ^ -1 / wrap_decorator,
113
+ Body = Space ^ -1 * Break * EmptyLine ^ 0 * InBlock + Ct(Statement),
114
+ Advance = #Cmt(Indent, advance_indent),
115
+ PushIndent = Cmt(Indent, push_indent),
116
+ PreventIndent = Cmt(Cc(-1), push_indent),
117
+ PopIndent = Cmt("", pop_indent),
118
+ InBlock = Advance * Block * PopIndent,
119
+ Local = key("local") * ((op("*") + op("^")) / mark("declare_glob") + Ct(NameList) / mark("declare_with_shadows")),
120
+ Import = key("import") * Ct(ImportNameList) * SpaceBreak ^ 0 * key("from") * Exp / mark("import"),
121
+ ImportName = (sym("\\") * Ct(Cc("colon_stub") * Name) + Name),
122
+ ImportNameList = SpaceBreak ^ 0 * ImportName * ((SpaceBreak ^ 1 + sym(",") * SpaceBreak ^ 0) * ImportName) ^ 0,
123
+ BreakLoop = Ct(key("break") / trim) + Ct(key("continue") / trim),
124
+ Return = key("return") * (ExpListLow / mark("explist") + C("")) / mark("return"),
125
+ WithExp = Ct(ExpList) * Assign ^ -1 / format_assign,
126
+ With = key("with") * DisableDo * ensure(WithExp, PopDo) * key("do") ^ -1 * Body / mark("with"),
127
+ Switch = key("switch") * DisableDo * ensure(Exp, PopDo) * key("do") ^ -1 * Space ^ -1 * Break * SwitchBlock / mark("switch"),
128
+ SwitchBlock = EmptyLine ^ 0 * Advance * Ct(SwitchCase * (Break ^ 1 * SwitchCase) ^ 0 * (Break ^ 1 * SwitchElse) ^ -1) * PopIndent,
129
+ SwitchCase = key("when") * Ct(ExpList) * key("then") ^ -1 * Body / mark("case"),
130
+ SwitchElse = key("else") * Body / mark("else"),
131
+ IfCond = Exp * Assign ^ -1 / format_single_assign,
132
+ If = key("if") * IfCond * key("then") ^ -1 * Body * ((Break * CheckIndent) ^ -1 * EmptyLine ^ 0 * key("elseif") * pos(IfCond) * key("then") ^ -1 * Body / mark("elseif")) ^ 0 * ((Break * CheckIndent) ^ -1 * EmptyLine ^ 0 * key("else") * Body / mark("else")) ^ -1 / mark("if"),
133
+ Unless = key("unless") * IfCond * key("then") ^ -1 * Body * ((Break * CheckIndent) ^ -1 * EmptyLine ^ 0 * key("else") * Body / mark("else")) ^ -1 / mark("unless"),
134
+ While = key("while") * DisableDo * ensure(Exp, PopDo) * key("do") ^ -1 * Body / mark("while"),
135
+ For = key("for") * DisableDo * ensure(Name * sym("=") * Ct(Exp * sym(",") * Exp * (sym(",") * Exp) ^ -1), PopDo) * key("do") ^ -1 * Body / mark("for"),
136
+ ForEach = key("for") * Ct(AssignableNameList) * key("in") * DisableDo * ensure(Ct(sym("*") * Exp / mark("unpack") + ExpList), PopDo) * key("do") ^ -1 * Body / mark("foreach"),
137
+ Do = key("do") * Body / mark("do"),
138
+ Comprehension = sym("[") * Exp * CompInner * sym("]") / mark("comprehension"),
139
+ TblComprehension = sym("{") * Ct(Exp * (sym(",") * Exp) ^ -1) * CompInner * sym("}") / mark("tblcomprehension"),
140
+ CompInner = Ct((CompForEach + CompFor) * CompClause ^ 0),
141
+ CompForEach = key("for") * Ct(NameList) * key("in") * (sym("*") * Exp / mark("unpack") + Exp) / mark("foreach"),
142
+ CompFor = key("for" * Name * sym("=") * Ct(Exp * sym(",") * Exp * (sym(",") * Exp) ^ -1) / mark("for")),
143
+ CompClause = CompFor + CompForEach + key("when") * Exp / mark("when"),
144
+ Assign = sym("=") * (Ct(With + If + Switch) + Ct(TableBlock + ExpListLow)) / mark("assign"),
145
+ Update = ((sym("..=") + sym("+=") + sym("-=") + sym("*=") + sym("/=") + sym("%=") + sym("or=") + sym("and=")) / trim) * Exp / mark("update"),
146
+ CharOperators = Space * C(S("+-*/%^><")),
147
+ WordOperators = op("or") + op("and") + op("<=") + op(">=") + op("~=") + op("!=") + op("==") + op(".."),
148
+ BinaryOperator = (WordOperators + CharOperators) * SpaceBreak ^ 0,
149
+ Assignable = Cmt(DotChain + Chain, check_assignable) + Name + SelfName,
150
+ Exp = Ct(Value * (BinaryOperator * Value) ^ 0) / flatten_or_mark("exp"),
151
+ SimpleValue = If + Unless + Switch + With + ClassDecl + ForEach + For + While + Cmt(Do, check_do) + sym("-") * -SomeSpace * Exp / mark("minus") + sym("#") * Exp / mark("length") + key("not") * Exp / mark("not") + TblComprehension + TableLit + Comprehension + FunLit + Num,
152
+ ChainValue = StringChain + ((Chain + DotChain + Callable) * Ct(InvokeArgs ^ -1)) / flatten_func,
153
+ Value = pos(SimpleValue + Ct(KeyValueList) / mark("table") + ChainValue),
154
+ SliceValue = SimpleValue + ChainValue,
155
+ StringChain = String * (Ct((ColonCall + ColonSuffix) * ChainTail ^ -1) * Ct(InvokeArgs ^ -1)) ^ -1 / flatten_string_chain,
156
+ String = Space * DoubleString + Space * SingleString + LuaString,
157
+ SingleString = simple_string("'"),
158
+ DoubleString = simple_string('"', true),
159
+ LuaString = Cg(LuaStringOpen, "string_open") * Cb("string_open") * Break ^ -1 * C((1 - Cmt(C(LuaStringClose) * Cb("string_open"), check_lua_string)) ^ 0) * LuaStringClose / mark("string"),
160
+ LuaStringOpen = sym("[") * P("=") ^ 0 * "[" / trim,
161
+ LuaStringClose = "]" * P("=") ^ 0 * "]",
162
+ Callable = pos(Name / mark("ref")) + SelfName + VarArg + Parens / mark("parens"),
163
+ Parens = sym("(") * SpaceBreak ^ 0 * Exp * SpaceBreak ^ 0 * sym(")"),
164
+ FnArgs = symx("(") * SpaceBreak ^ 0 * Ct(ExpList ^ -1) * SpaceBreak ^ 0 * sym(")") + sym("!") * -P("=") * Ct(""),
165
+ ChainTail = ChainItem ^ 1 * ColonSuffix ^ -1 + ColonSuffix,
166
+ Chain = Callable * ChainTail / mark("chain"),
167
+ DotChain = (sym(".") * Cc(-1) * (_Name / mark("dot")) * ChainTail ^ -1) / mark("chain") + (sym("\\") * Cc(-1) * ((_Name * Invoke / mark("colon")) * ChainTail ^ -1 + (_Name / mark("colon_stub")))) / mark("chain"),
168
+ ChainItem = Invoke + Slice + symx("[") * Exp / mark("index") * sym("]") + symx(".") * _Name / mark("dot") + ColonCall,
169
+ Slice = symx("[") * (SliceValue + Cc(1)) * sym(",") * (SliceValue + Cc("")) * (sym(",") * SliceValue) ^ -1 * sym("]") / mark("slice"),
170
+ ColonCall = symx("\\") * (_Name * Invoke) / mark("colon"),
171
+ ColonSuffix = symx("\\") * _Name / mark("colon_stub"),
172
+ Invoke = FnArgs / mark("call") + SingleString / wrap_func_arg + DoubleString / wrap_func_arg,
173
+ TableValue = KeyValue + Ct(Exp),
174
+ TableLit = sym("{") * Ct(TableValueList ^ -1 * sym(",") ^ -1 * (SpaceBreak * TableLitLine * (sym(",") ^ -1 * SpaceBreak * TableLitLine) ^ 0 * sym(",") ^ -1) ^ -1) * White * sym("}") / mark("table"),
175
+ TableValueList = TableValue * (sym(",") * TableValue) ^ 0,
176
+ TableLitLine = PushIndent * ((TableValueList * PopIndent) + (PopIndent * Cut)) + Space,
177
+ TableBlockInner = Ct(KeyValueLine * (SpaceBreak ^ 1 * KeyValueLine) ^ 0),
178
+ TableBlock = SpaceBreak ^ 1 * Advance * ensure(TableBlockInner, PopIndent) / mark("table"),
179
+ ClassDecl = key("class") * -P(":") * (Assignable + Cc(nil)) * (key("extends") * PreventIndent * ensure(Exp, PopIndent) + C("")) ^ -1 * (ClassBlock + Ct("")) / mark("class"),
180
+ ClassBlock = SpaceBreak ^ 1 * Advance * Ct(ClassLine * (SpaceBreak ^ 1 * ClassLine) ^ 0) * PopIndent,
181
+ ClassLine = CheckIndent * ((KeyValueList / mark("props") + Statement / mark("stm") + Exp / mark("stm")) * sym(",") ^ -1),
182
+ Export = key("export") * (Cc("class") * ClassDecl + op("*") + op("^") + Ct(NameList) * (sym("=") * Ct(ExpListLow)) ^ -1) / mark("export"),
183
+ KeyValue = (sym(":") * -SomeSpace * Name * lpeg.Cp()) / self_assign + Ct((KeyName + sym("[") * Exp * sym("]") + DoubleString + SingleString) * symx(":") * (Exp + TableBlock + SpaceBreak ^ 1 * Exp)),
184
+ KeyValueList = KeyValue * (sym(",") * KeyValue) ^ 0,
185
+ KeyValueLine = CheckIndent * KeyValueList * sym(",") ^ -1,
186
+ FnArgsDef = sym("(") * Ct(FnArgDefList ^ -1) * (key("using") * Ct(NameList + Space * "nil") + Ct("")) * sym(")") + Ct("") * Ct(""),
187
+ FnArgDefList = FnArgDef * (sym(",") * FnArgDef) ^ 0 * (sym(",") * Ct(VarArg)) ^ 0 + Ct(VarArg),
188
+ FnArgDef = Ct((Name + SelfName) * (sym("=") * Exp) ^ -1),
189
+ FunLit = FnArgsDef * (sym("->") * Cc("slim") + sym("=>") * Cc("fat")) * (Body + Ct("")) / mark("fndef"),
190
+ NameList = Name * (sym(",") * Name) ^ 0,
191
+ NameOrDestructure = Name + TableLit,
192
+ AssignableNameList = NameOrDestructure * (sym(",") * NameOrDestructure) ^ 0,
193
+ ExpList = Exp * (sym(",") * Exp) ^ 0,
194
+ ExpListLow = Exp * ((sym(",") + sym(";")) * Exp) ^ 0,
195
+ InvokeArgs = -P("-") * (ExpList * (sym(",") * (TableBlock + SpaceBreak * Advance * ArgBlock * TableBlock ^ -1) + TableBlock) ^ -1 + TableBlock),
196
+ ArgBlock = ArgLine * (sym(",") * SpaceBreak * ArgLine) ^ 0 * PopIndent,
197
+ ArgLine = CheckIndent * ExpList
198
+ })
199
+ local file_grammar = White * g * White * -1
200
+ return {
201
+ match = function(self, str)
202
+ local tree
203
+ local _, err = xpcall((function()
204
+ tree = file_grammar:match(str)
205
+ end), function(err)
206
+ return debug.traceback(err, 2)
207
+ end)
208
+ if type(err) == "string" then
209
+ return nil, err
210
+ end
211
+ if not (tree) then
212
+ local msg
213
+ pos = last_pos
214
+ if err then
215
+ local node
216
+ node, msg = unpack(err)
217
+ if msg then
218
+ msg = " " .. msg
219
+ end
220
+ pos = node[-1]
221
+ end
222
+ local line_no = pos_to_line(str, pos)
223
+ local line_str = get_line(str, line_no) or ""
224
+ return nil, err_msg:format(msg or "", line_no, trim(line_str))
225
+ end
226
+ return tree
227
+ end
228
+ }
229
+ end)
230
+ return {
231
+ extract_line = extract_line,
232
+ string = function(str)
233
+ return build_grammar():match(str)
234
+ end
235
+ }
@@ -4,25 +4,13 @@ do
4
4
  ntype, mtype, build = _obj_0.ntype, _obj_0.mtype, _obj_0.build
5
5
  end
6
6
  local NameProxy
7
- do
8
- local _obj_0 = require("moonscript.transform.names")
9
- NameProxy = _obj_0.NameProxy
10
- end
7
+ NameProxy = require("moonscript.transform.names").NameProxy
11
8
  local insert
12
- do
13
- local _obj_0 = table
14
- insert = _obj_0.insert
15
- end
9
+ insert = table.insert
16
10
  local unpack
17
- do
18
- local _obj_0 = require("moonscript.util")
19
- unpack = _obj_0.unpack
20
- end
11
+ unpack = require("moonscript.util").unpack
21
12
  local user_error
22
- do
23
- local _obj_0 = require("moonscript.errors")
24
- user_error = _obj_0.user_error
25
- end
13
+ user_error = require("moonscript.errors").user_error
26
14
  local join
27
15
  join = function(...)
28
16
  do
@@ -124,7 +112,7 @@ build_assign = function(scope, destruct_literal, receiver)
124
112
  values
125
113
  }
126
114
  local obj
127
- if scope:is_local(receiver) then
115
+ if scope:is_local(receiver) or #extracted_names == 1 then
128
116
  obj = receiver
129
117
  else
130
118
  do
@@ -143,7 +131,13 @@ build_assign = function(scope, destruct_literal, receiver)
143
131
  for _index_0 = 1, #extracted_names do
144
132
  local tuple = extracted_names[_index_0]
145
133
  insert(names, tuple[1])
146
- insert(values, NameProxy.chain(obj, unpack(tuple[2])))
134
+ local chain
135
+ if obj then
136
+ chain = NameProxy.chain(obj, unpack(tuple[2]))
137
+ else
138
+ chain = "nil"
139
+ end
140
+ insert(values, chain)
147
141
  end
148
142
  return build.group({
149
143
  {
@@ -1,13 +1,7 @@
1
1
  local build
2
- do
3
- local _obj_0 = require("moonscript.types")
4
- build = _obj_0.build
5
- end
2
+ build = require("moonscript.types").build
6
3
  local unpack
7
- do
8
- local _obj_0 = require("moonscript.util")
9
- unpack = _obj_0.unpack
10
- end
4
+ unpack = require("moonscript.util").unpack
11
5
  local LocalName
12
6
  do
13
7
  local _base_0 = {
@@ -6,10 +6,7 @@ reversed, unpack = util.reversed, util.unpack
6
6
  local ntype, mtype, build, smart_node, is_slice, value_is_singular
7
7
  ntype, mtype, build, smart_node, is_slice, value_is_singular = types.ntype, types.mtype, types.build, types.smart_node, types.is_slice, types.value_is_singular
8
8
  local insert
9
- do
10
- local _obj_0 = table
11
- insert = _obj_0.insert
12
- end
9
+ insert = table.insert
13
10
  local NameProxy, LocalName
14
11
  do
15
12
  local _obj_0 = require("moonscript.transform.names")
@@ -1,14 +1,8 @@
1
1
  local util = require("moonscript.util")
2
2
  local Set
3
- do
4
- local _obj_0 = require("moonscript.data")
5
- Set = _obj_0.Set
6
- end
3
+ Set = require("moonscript.data").Set
7
4
  local insert
8
- do
9
- local _obj_0 = table
10
- insert = _obj_0.insert
11
- end
5
+ insert = table.insert
12
6
  local unpack
13
7
  unpack = util.unpack
14
8
  local manual_return = Set({
@@ -1,8 +1,5 @@
1
1
  local concat
2
- do
3
- local _obj_0 = table
4
- concat = _obj_0.concat
5
- end
2
+ concat = table.concat
6
3
  local unpack = unpack or table.unpack
7
4
  local type = type
8
5
  local moon = {
@@ -199,6 +196,14 @@ get_options = function(...)
199
196
  return { }, ...
200
197
  end
201
198
  end
199
+ local safe_module
200
+ safe_module = function(name, tbl)
201
+ return setmetatable(tbl, {
202
+ __index = function(self, key)
203
+ return error("Attempted to import non-existent `" .. tostring(key) .. "` from " .. tostring(name))
204
+ end
205
+ })
206
+ end
202
207
  return {
203
208
  moon = moon,
204
209
  pos_to_line = pos_to_line,
@@ -212,5 +217,6 @@ return {
212
217
  getfenv = getfenv,
213
218
  setfenv = setfenv,
214
219
  get_options = get_options,
215
- unpack = unpack
220
+ unpack = unpack,
221
+ safe_module = safe_module
216
222
  }
@@ -1,4 +1,4 @@
1
- local version = "0.2.6"
1
+ local version = "0.3.0"
2
2
  return {
3
3
  version = version,
4
4
  print_version = function()