rufus-lua-moon 0.2.6.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,639 +0,0 @@
1
-
2
- local util = require"moonscript.util"
3
-
4
- local lpeg = require"lpeg"
5
-
6
- local debug_grammar = false
7
-
8
- local data = require"moonscript.data"
9
- local types = require"moonscript.types"
10
-
11
- local ntype = types.ntype
12
-
13
- local trim = util.trim
14
-
15
- local getfenv = util.getfenv
16
- local setfenv = util.setfenv
17
- local unpack = util.unpack
18
-
19
- local Stack = data.Stack
20
-
21
- local function count_indent(str)
22
- local sum = 0
23
- for v in str:gmatch("[\t ]") do
24
- if v == ' ' then sum = sum + 1 end
25
- if v == '\t' then sum = sum + 4 end
26
- end
27
- return sum
28
- end
29
-
30
- local R, S, V, P = lpeg.R, lpeg.S, lpeg.V, lpeg.P
31
- local C, Ct, Cmt, Cg, Cb, Cc = lpeg.C, lpeg.Ct, lpeg.Cmt, lpeg.Cg, lpeg.Cb, lpeg.Cc
32
-
33
- lpeg.setmaxstack(10000)
34
-
35
- local White = S" \t\r\n"^0
36
- local _Space = S" \t"^0
37
- local Break = P"\r"^-1 * P"\n"
38
- local Stop = Break + -1
39
- local Indent = C(S"\t "^0) / count_indent
40
-
41
- local Comment = P"--" * (1 - S"\r\n")^0 * #Stop
42
- local Space = _Space * Comment^-1
43
- local SomeSpace = S" \t"^1 * Comment^-1
44
-
45
- local SpaceBreak = Space * Break
46
- local EmptyLine = SpaceBreak
47
-
48
- local AlphaNum = R("az", "AZ", "09", "__")
49
-
50
- local _Name = C(R("az", "AZ", "__") * AlphaNum^0)
51
- local Name = Space * _Name
52
-
53
- local Num = P"0x" * R("09", "af", "AF")^1 * (S"uU"^-1 * S"lL"^2)^-1 +
54
- R"09"^1 * (S"uU"^-1 * S"lL"^2) +
55
- (
56
- R"09"^1 * (P"." * R"09"^1)^-1 +
57
- P"." * R"09"^1
58
- ) * (S"eE" * P"-"^-1 * R"09"^1)^-1
59
-
60
- Num = Space * (Num / function(value) return {"number", value} end)
61
-
62
- local FactorOp = Space * C(S"+-")
63
- local TermOp = Space * C(S"*/%^")
64
-
65
- local Shebang = P"#!" * P(1 - Stop)^0
66
-
67
- -- can't have P(false) because it causes preceding patterns not to run
68
- local Cut = P(function() return false end)
69
-
70
- local function ensure(patt, finally)
71
- return patt * finally + finally * Cut
72
- end
73
-
74
- -- auto declare Proper variables with lpeg.V
75
- local function wrap_env(fn)
76
- local env = getfenv(fn)
77
- local wrap_name = V
78
-
79
- if debug_grammar then
80
- local indent = 0
81
- local indent_char = " "
82
-
83
- local function iprint(...)
84
- local args = {...}
85
- for i=1,#args do
86
- args[i] = tostring(args[i])
87
- end
88
-
89
- io.stdout:write(indent_char:rep(indent) .. table.concat(args, ", ") .. "\n")
90
- end
91
-
92
- wrap_name = function(name)
93
- local v = V(name)
94
- v = Cmt("", function()
95
- iprint("* " .. name)
96
- indent = indent + 1
97
- return true
98
- end) * Cmt(v, function(str, pos, ...)
99
- iprint(name, true)
100
- indent = indent - 1
101
- return true, ...
102
- end) + Cmt("", function()
103
- iprint(name, false)
104
- indent = indent - 1
105
- return false
106
- end)
107
- return v
108
- end
109
- end
110
-
111
- return setfenv(fn, setmetatable({}, {
112
- __index = function(self, name)
113
- local value = env[name]
114
- if value ~= nil then return value end
115
-
116
- if name:match"^[A-Z][A-Za-z0-9]*$" then
117
- local v = wrap_name(name)
118
- rawset(self, name, v)
119
- return v
120
- end
121
- error("unknown variable referenced: "..name)
122
- end
123
- }))
124
- end
125
-
126
- local function extract_line(str, start_pos)
127
- str = str:sub(start_pos)
128
- local m = str:match"^(.-)\n"
129
- if m then return m end
130
- return str:match"^.-$"
131
- end
132
-
133
- local function mark(name)
134
- return function(...)
135
- return {name, ...}
136
- end
137
- end
138
-
139
- local function insert_pos(pos, value)
140
- if type(value) == "table" then
141
- value[-1] = pos
142
- end
143
- return value
144
- end
145
-
146
- local function pos(patt)
147
- return (lpeg.Cp() * patt) / insert_pos
148
- end
149
-
150
- local function got(what)
151
- return Cmt("", function(str, pos, ...)
152
- local cap = {...}
153
- print("++ got "..what, "["..extract_line(str, pos).."]")
154
- return true
155
- end)
156
- end
157
-
158
- local function flatten_or_mark(name)
159
- return function(tbl)
160
- if #tbl == 1 then return tbl[1] end
161
- table.insert(tbl, 1, name)
162
- return tbl
163
- end
164
- end
165
-
166
- -- makes sure the last item in a chain is an index
167
- local _chain_assignable = { index = true, dot = true, slice = true }
168
-
169
- local function is_assignable(node)
170
- if node == "..." then
171
- return false
172
- end
173
-
174
- local t = ntype(node)
175
- return t == "ref" or t == "self" or t == "value" or t == "self_class" or
176
- t == "chain" and _chain_assignable[ntype(node[#node])] or
177
- t == "table"
178
- end
179
-
180
- local function check_assignable(str, pos, value)
181
- if is_assignable(value) then
182
- return true, value
183
- end
184
- return false
185
- end
186
-
187
- local flatten_explist = flatten_or_mark"explist"
188
- local function format_assign(lhs_exps, assign)
189
- if not assign then
190
- return flatten_explist(lhs_exps)
191
- end
192
-
193
- for _, assign_exp in ipairs(lhs_exps) do
194
- if not is_assignable(assign_exp) then
195
- error {assign_exp, "left hand expression is not assignable"}
196
- end
197
- end
198
-
199
- local t = ntype(assign)
200
- if t == "assign" then
201
- return {"assign", lhs_exps, unpack(assign, 2)}
202
- elseif t == "update" then
203
- return {"update", lhs_exps[1], unpack(assign, 2)}
204
- end
205
-
206
- error "unknown assign expression"
207
- end
208
-
209
- -- the if statement only takes a single lhs, so we wrap in table to git to
210
- -- "assign" tuple format
211
- local function format_single_assign(lhs, assign)
212
- if assign then
213
- return format_assign({lhs}, assign)
214
- end
215
- return lhs
216
- end
217
-
218
- local function sym(chars)
219
- return Space * chars
220
- end
221
-
222
- local function symx(chars)
223
- return chars
224
- end
225
-
226
- local function simple_string(delim, allow_interpolation)
227
- local inner = P('\\'..delim) + "\\\\" + (1 - P(delim))
228
- if allow_interpolation then
229
- local inter = symx"#{" * V"Exp" * sym"}"
230
- inner = (C((inner - inter)^1) + inter / mark"interpolate")^0
231
- else
232
- inner = C(inner^0)
233
- end
234
-
235
- return C(symx(delim)) *
236
- inner * sym(delim) / mark"string"
237
- end
238
-
239
- local function wrap_func_arg(value)
240
- return {"call", {value}}
241
- end
242
-
243
- -- DOCME
244
- local function flatten_func(callee, args)
245
- if #args == 0 then return callee end
246
-
247
- args = {"call", args}
248
- if ntype(callee) == "chain" then
249
- -- check for colon stub that needs arguments
250
- if ntype(callee[#callee]) == "colon_stub" then
251
- local stub = callee[#callee]
252
- stub[1] = "colon"
253
- table.insert(stub, args)
254
- else
255
- table.insert(callee, args)
256
- end
257
-
258
- return callee
259
- end
260
-
261
- return {"chain", callee, args}
262
- end
263
-
264
- local function flatten_string_chain(str, chain, args)
265
- if not chain then return str end
266
- return flatten_func({"chain", str, unpack(chain)}, args)
267
- end
268
-
269
- -- transforms a statement that has a line decorator
270
- local function wrap_decorator(stm, dec)
271
- if not dec then return stm end
272
- return { "decorated", stm, dec }
273
- end
274
-
275
- local function check_lua_string(str, pos, right, left)
276
- return #left == #right
277
- end
278
-
279
- -- :name in table literal
280
- local function self_assign(name)
281
- return {{"key_literal", name}, name}
282
- end
283
-
284
- local err_msg = "Failed to parse:%s\n [%d] >> %s"
285
-
286
- local build_grammar = wrap_env(function()
287
- local _indent = Stack(0) -- current indent
288
- local _do_stack = Stack(0)
289
-
290
- local last_pos = 0 -- used to know where to report error
291
- local function check_indent(str, pos, indent)
292
- last_pos = pos
293
- return _indent:top() == indent
294
- end
295
-
296
- local function advance_indent(str, pos, indent)
297
- local top = _indent:top()
298
- if top ~= -1 and indent > _indent:top() then
299
- _indent:push(indent)
300
- return true
301
- end
302
- end
303
-
304
- local function push_indent(str, pos, indent)
305
- _indent:push(indent)
306
- return true
307
- end
308
-
309
- local function pop_indent(str, pos)
310
- if not _indent:pop() then error("unexpected outdent") end
311
- return true
312
- end
313
-
314
-
315
- local function check_do(str, pos, do_node)
316
- local top = _do_stack:top()
317
- if top == nil or top then
318
- return true, do_node
319
- end
320
- return false
321
- end
322
-
323
- local function disable_do(str_pos)
324
- _do_stack:push(false)
325
- return true
326
- end
327
-
328
- local function pop_do(str, pos)
329
- if nil == _do_stack:pop() then error("unexpected do pop") end
330
- return true
331
- end
332
-
333
- local DisableDo = Cmt("", disable_do)
334
- local PopDo = Cmt("", pop_do)
335
-
336
- local keywords = {}
337
- local function key(chars)
338
- keywords[chars] = true
339
- return Space * chars * -AlphaNum
340
- end
341
-
342
- local function op(word)
343
- local patt = Space * C(word)
344
- if word:match("^%w*$") then
345
- keywords[word] = true
346
- patt = patt * -AlphaNum
347
- end
348
- return patt
349
- end
350
-
351
- -- make sure name is not a keyword
352
- local Name = Cmt(Name, function(str, pos, name)
353
- if keywords[name] then return false end
354
- return true
355
- end) / trim
356
-
357
- local SelfName = Space * "@" * (
358
- "@" * (_Name / mark"self_class" + Cc"self.__class") +
359
- _Name / mark"self" + Cc"self")
360
-
361
- local KeyName = SelfName + Space * _Name / mark"key_literal"
362
- local VarArg = Space * P"..." / trim
363
-
364
- local g = lpeg.P{
365
- File,
366
- File = Shebang^-1 * (Block + Ct""),
367
- Block = Ct(Line * (Break^1 * Line)^0),
368
- CheckIndent = Cmt(Indent, check_indent), -- validates line is in correct indent
369
- Line = (CheckIndent * Statement + Space * #Stop),
370
-
371
- Statement = pos(
372
- Import + While + With + For + ForEach + Switch + Return +
373
- Local + Export + BreakLoop +
374
- Ct(ExpList) * (Update + Assign)^-1 / format_assign
375
- ) * Space * ((
376
- -- statement decorators
377
- key"if" * Exp * (key"else" * Exp)^-1 * Space / mark"if" +
378
- key"unless" * Exp / mark"unless" +
379
- CompInner / mark"comprehension"
380
- ) * Space)^-1 / wrap_decorator,
381
-
382
- Body = Space^-1 * Break * EmptyLine^0 * InBlock + Ct(Statement), -- either a statement, or an indented block
383
-
384
- Advance = #Cmt(Indent, advance_indent), -- Advances the indent, gives back whitespace for CheckIndent
385
- PushIndent = Cmt(Indent, push_indent),
386
- PreventIndent = Cmt(Cc(-1), push_indent),
387
- PopIndent = Cmt("", pop_indent),
388
- InBlock = Advance * Block * PopIndent,
389
-
390
- Local = key"local" * ((op"*" + op"^") / mark"declare_glob" + Ct(NameList) / mark"declare_with_shadows"),
391
-
392
- Import = key"import" * Ct(ImportNameList) * SpaceBreak^0 * key"from" * Exp / mark"import",
393
- ImportName = (sym"\\" * Ct(Cc"colon_stub" * Name) + Name),
394
- ImportNameList = SpaceBreak^0 * ImportName * ((SpaceBreak^1 + sym"," * SpaceBreak^0) * ImportName)^0,
395
-
396
- BreakLoop = Ct(key"break"/trim) + Ct(key"continue"/trim),
397
-
398
- Return = key"return" * (ExpListLow/mark"explist" + C"") / mark"return",
399
-
400
- WithExp = Ct(ExpList) * Assign^-1 / format_assign,
401
- With = key"with" * DisableDo * ensure(WithExp, PopDo) * key"do"^-1 * Body / mark"with",
402
-
403
- Switch = key"switch" * DisableDo * ensure(Exp, PopDo) * key"do"^-1 * Space^-1 * Break * SwitchBlock / mark"switch",
404
-
405
- SwitchBlock = EmptyLine^0 * Advance * Ct(SwitchCase * (Break^1 * SwitchCase)^0 * (Break^1 * SwitchElse)^-1) * PopIndent,
406
- SwitchCase = key"when" * Ct(ExpList) * key"then"^-1 * Body / mark"case",
407
- SwitchElse = key"else" * Body / mark"else",
408
-
409
- IfCond = Exp * Assign^-1 / format_single_assign,
410
-
411
- If = key"if" * IfCond * key"then"^-1 * Body *
412
- ((Break * CheckIndent)^-1 * EmptyLine^0 * key"elseif" * pos(IfCond) * key"then"^-1 * Body / mark"elseif")^0 *
413
- ((Break * CheckIndent)^-1 * EmptyLine^0 * key"else" * Body / mark"else")^-1 / mark"if",
414
-
415
- Unless = key"unless" * IfCond * key"then"^-1 * Body *
416
- ((Break * CheckIndent)^-1 * EmptyLine^0 * key"else" * Body / mark"else")^-1 / mark"unless",
417
-
418
- While = key"while" * DisableDo * ensure(Exp, PopDo) * key"do"^-1 * Body / mark"while",
419
-
420
- For = key"for" * DisableDo * ensure(Name * sym"=" * Ct(Exp * sym"," * Exp * (sym"," * Exp)^-1), PopDo) *
421
- key"do"^-1 * Body / mark"for",
422
-
423
- ForEach = key"for" * Ct(AssignableNameList) * key"in" * DisableDo * ensure(Ct(sym"*" * Exp / mark"unpack" + ExpList), PopDo) * key"do"^-1 * Body / mark"foreach",
424
-
425
- Do = key"do" * Body / mark"do",
426
-
427
- Comprehension = sym"[" * Exp * CompInner * sym"]" / mark"comprehension",
428
-
429
- TblComprehension = sym"{" * Ct(Exp * (sym"," * Exp)^-1) * CompInner * sym"}" / mark"tblcomprehension",
430
-
431
- CompInner = Ct((CompForEach + CompFor) * CompClause^0),
432
- CompForEach = key"for" * Ct(NameList) * key"in" * (sym"*" * Exp / mark"unpack" + Exp) / mark"foreach",
433
- CompFor = key "for" * Name * sym"=" * Ct(Exp * sym"," * Exp * (sym"," * Exp)^-1) / mark"for",
434
- CompClause = CompFor + CompForEach + key"when" * Exp / mark"when",
435
-
436
- Assign = sym"=" * (Ct(With + If + Switch) + Ct(TableBlock + ExpListLow)) / mark"assign",
437
- Update = ((sym"..=" + sym"+=" + sym"-=" + sym"*=" + sym"/=" + sym"%=" + sym"or=" + sym"and=") / trim) * Exp / mark"update",
438
-
439
- -- we can ignore precedence for now
440
- OtherOps = op"or" + op"and" + op"<=" + op">=" + op"~=" + op"!=" + op"==" + op".." + op"<" + op">",
441
-
442
- Assignable = Cmt(DotChain + Chain, check_assignable) + Name + SelfName,
443
-
444
- Exp = Ct(Value * ((OtherOps + FactorOp + TermOp) * Value)^0) / flatten_or_mark"exp",
445
-
446
- -- Exp = Ct(Factor * (OtherOps * Factor)^0) / flatten_or_mark"exp",
447
- -- Factor = Ct(Term * (FactorOp * Term)^0) / flatten_or_mark"exp",
448
- -- Term = Ct(Value * (TermOp * Value)^0) / flatten_or_mark"exp",
449
-
450
- SimpleValue =
451
- If + Unless +
452
- Switch +
453
- With +
454
- ClassDecl +
455
- ForEach + For + While +
456
- Cmt(Do, check_do) +
457
- sym"-" * -SomeSpace * Exp / mark"minus" +
458
- sym"#" * Exp / mark"length" +
459
- key"not" * Exp / mark"not" +
460
- TblComprehension +
461
- TableLit +
462
- Comprehension +
463
- FunLit +
464
- Num,
465
-
466
- ChainValue = -- a function call or an object access
467
- StringChain +
468
- ((Chain + DotChain + Callable) * Ct(InvokeArgs^-1)) / flatten_func,
469
-
470
- Value = pos(
471
- SimpleValue +
472
- Ct(KeyValueList) / mark"table" +
473
- ChainValue),
474
-
475
- SliceValue = SimpleValue + ChainValue,
476
-
477
- StringChain = String *
478
- (Ct((ColonCall + ColonSuffix) * ChainTail^-1) * Ct(InvokeArgs^-1))^-1 / flatten_string_chain,
479
-
480
- String = Space * DoubleString + Space * SingleString + LuaString,
481
- SingleString = simple_string("'"),
482
- DoubleString = simple_string('"', true),
483
-
484
- LuaString = Cg(LuaStringOpen, "string_open") * Cb"string_open" * Break^-1 *
485
- C((1 - Cmt(C(LuaStringClose) * Cb"string_open", check_lua_string))^0) *
486
- LuaStringClose / mark"string",
487
-
488
- LuaStringOpen = sym"[" * P"="^0 * "[" / trim,
489
- LuaStringClose = "]" * P"="^0 * "]",
490
-
491
- Callable = pos(Name / mark"ref") + SelfName + VarArg + Parens / mark"parens",
492
- Parens = sym"(" * Exp * sym")",
493
-
494
- FnArgs = symx"(" * Ct(ExpList^-1) * sym")" + sym"!" * -P"=" * Ct"",
495
-
496
- ChainTail = ChainItem^1 * ColonSuffix^-1 + ColonSuffix,
497
-
498
- -- a list of funcalls and indexes on a callable
499
- Chain = Callable * ChainTail / mark"chain",
500
-
501
- -- shorthand dot call for use in with statement
502
- DotChain =
503
- (sym"." * Cc(-1) * (_Name / mark"dot") * ChainTail^-1) / mark"chain" +
504
- (sym"\\" * Cc(-1) * (
505
- (_Name * Invoke / mark"colon") * ChainTail^-1 +
506
- (_Name / mark"colon_stub")
507
- )) / mark"chain",
508
-
509
- ChainItem =
510
- Invoke +
511
- Slice +
512
- symx"[" * Exp/mark"index" * sym"]" +
513
- symx"." * _Name/mark"dot" +
514
- ColonCall,
515
-
516
- Slice = symx"[" * (SliceValue + Cc(1)) * sym"," * (SliceValue + Cc"") *
517
- (sym"," * SliceValue)^-1 *sym"]" / mark"slice",
518
-
519
- ColonCall = symx"\\" * (_Name * Invoke) / mark"colon",
520
- ColonSuffix = symx"\\" * _Name / mark"colon_stub",
521
-
522
- Invoke = FnArgs/mark"call" +
523
- SingleString / wrap_func_arg +
524
- DoubleString / wrap_func_arg,
525
-
526
- TableValue = KeyValue + Ct(Exp),
527
-
528
- TableLit = sym"{" * Ct(
529
- TableValueList^-1 * sym","^-1 *
530
- (SpaceBreak * TableLitLine * (sym","^-1 * SpaceBreak * TableLitLine)^0 * sym","^-1)^-1
531
- ) * White * sym"}" / mark"table",
532
-
533
- TableValueList = TableValue * (sym"," * TableValue)^0,
534
- TableLitLine = PushIndent * ((TableValueList * PopIndent) + (PopIndent * Cut)) + Space,
535
-
536
- -- the unbounded table
537
- TableBlockInner = Ct(KeyValueLine * (SpaceBreak^1 * KeyValueLine)^0),
538
- TableBlock = SpaceBreak^1 * Advance * ensure(TableBlockInner, PopIndent) / mark"table",
539
-
540
- ClassDecl = key"class" * -P":" * (Assignable + Cc(nil)) * (key"extends" * PreventIndent * ensure(Exp, PopIndent) + C"")^-1 * (ClassBlock + Ct("")) / mark"class",
541
-
542
- ClassBlock = SpaceBreak^1 * Advance *
543
- Ct(ClassLine * (SpaceBreak^1 * ClassLine)^0) * PopIndent,
544
- ClassLine = CheckIndent * ((
545
- KeyValueList / mark"props" +
546
- Statement / mark"stm" +
547
- Exp / mark"stm"
548
- ) * sym","^-1),
549
-
550
- Export = key"export" * (
551
- Cc"class" * ClassDecl +
552
- op"*" + op"^" +
553
- Ct(NameList) * (sym"=" * Ct(ExpListLow))^-1) / mark"export",
554
-
555
- KeyValue = (sym":" * -SomeSpace * Name) / self_assign + Ct((KeyName + sym"[" * Exp * sym"]" + DoubleString + SingleString) * symx":" * (Exp + TableBlock)),
556
- KeyValueList = KeyValue * (sym"," * KeyValue)^0,
557
- KeyValueLine = CheckIndent * KeyValueList * sym","^-1,
558
-
559
- FnArgsDef = sym"(" * Ct(FnArgDefList^-1) *
560
- (key"using" * Ct(NameList + Space * "nil") + Ct"") *
561
- sym")" + Ct"" * Ct"",
562
-
563
- FnArgDefList = FnArgDef * (sym"," * FnArgDef)^0 * (sym"," * Ct(VarArg))^0 + Ct(VarArg),
564
- FnArgDef = Ct((Name + SelfName) * (sym"=" * Exp)^-1),
565
-
566
- FunLit = FnArgsDef *
567
- (sym"->" * Cc"slim" + sym"=>" * Cc"fat") *
568
- (Body + Ct"") / mark"fndef",
569
-
570
- NameList = Name * (sym"," * Name)^0,
571
- NameOrDestructure = Name + TableLit,
572
- AssignableNameList = NameOrDestructure * (sym"," * NameOrDestructure)^0,
573
-
574
- ExpList = Exp * (sym"," * Exp)^0,
575
- ExpListLow = Exp * ((sym"," + sym";") * Exp)^0,
576
-
577
- InvokeArgs = -P"-" * (ExpList * (sym"," * (TableBlock + SpaceBreak * Advance * ArgBlock * TableBlock^-1) + TableBlock)^-1 + TableBlock),
578
- ArgBlock = ArgLine * (sym"," * SpaceBreak * ArgLine)^0 * PopIndent,
579
- ArgLine = CheckIndent * ExpList
580
- }
581
-
582
- return {
583
- _g = White * g * White * -1,
584
- match = function(self, str, ...)
585
-
586
- local pos_to_line = function(pos)
587
- return util.pos_to_line(str, pos)
588
- end
589
-
590
- local get_line = function(num)
591
- return util.get_line(str, num)
592
- end
593
-
594
- local tree
595
- local parse_args = {...}
596
-
597
- local pass, err = xpcall(function()
598
- tree = self._g:match(str, unpack(parse_args))
599
- end, function(err)
600
- return debug.traceback(err, 2)
601
- end)
602
-
603
- -- regular error, let it bubble up
604
- if type(err) == "string" then
605
- return nil, err
606
- end
607
-
608
- if not tree then
609
- local pos = last_pos
610
- local msg
611
-
612
- if err then
613
- local node
614
- node, msg = unpack(err)
615
- msg = msg and " " .. msg
616
- pos = node[-1]
617
- end
618
-
619
- local line_no = pos_to_line(pos)
620
- local line_str = get_line(line_no) or ""
621
-
622
- return nil, err_msg:format(msg or "", line_no, trim(line_str))
623
- end
624
- return tree
625
- end
626
- }
627
- end)
628
-
629
- return {
630
- extract_line = extract_line,
631
-
632
- -- parse a string
633
- -- returns tree, or nil and error message
634
- string = function (str)
635
- local g = build_grammar()
636
- return g:match(str)
637
- end
638
- }
639
-