mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
more tables
This commit is contained in:
parent
66b20ef1ce
commit
1cb205608a
@ -124,12 +124,16 @@ local compiler_index = {
|
||||
self:indent(1)
|
||||
local item_values = {}
|
||||
for _, item in ipairs(items) do
|
||||
local key = self:value(item[1])
|
||||
if type(item[1]) ~= "string" then
|
||||
key = ("[%s]"):format(key)
|
||||
end
|
||||
if #item == 1 then
|
||||
table.insert(item_values, self:value(item[1]))
|
||||
else
|
||||
local key = self:value(item[1])
|
||||
if type(item[1]) ~= "string" then
|
||||
key = ("[%s]"):format(key)
|
||||
end
|
||||
|
||||
table.insert(item_values, key.." = "..self:value(item[2]))
|
||||
table.insert(item_values, key.." = "..self:value(item[2]))
|
||||
end
|
||||
end
|
||||
local i = self:ichar()
|
||||
self:indent(-1)
|
||||
|
@ -23,7 +23,7 @@ local function count_indent(str)
|
||||
end
|
||||
|
||||
local R, S, V, P = lpeg.R, lpeg.S, lpeg.V, lpeg.P
|
||||
local C, Ct, Cmt, Cg, Cb = lpeg.C, lpeg.Ct, lpeg.Cmt, lpeg.Cg, lpeg.Cb
|
||||
local C, Ct, Cmt, Cg, Cb, Cc = lpeg.C, lpeg.Ct, lpeg.Cmt, lpeg.Cg, lpeg.Cb, lpeg.Cc
|
||||
|
||||
local White = S" \t\n"^0
|
||||
local _Space = S" \t"^0
|
||||
@ -193,7 +193,9 @@ local build_grammar = wrap(function()
|
||||
Exp = Ct(Term * (FactorOp * Term)^0) / flatten_or_mark"exp",
|
||||
Term = Ct(Value * (TermOp * Value)^0) / flatten_or_mark"exp",
|
||||
|
||||
Value = Assign + FunLit + String + (Chain + Callable) * Ct(ExpList^0) / flatten_func + Num,
|
||||
Value = TableLit + Ct(KeyValueList) / mark"table" +
|
||||
Assign + FunLit + String +
|
||||
(Chain + Callable) * Ct(ExpList^0) / flatten_func + Num,
|
||||
|
||||
String = Space * DoubleString + Space * SingleString + LuaString,
|
||||
SingleString = simple_string("'"),
|
||||
@ -216,14 +218,19 @@ local build_grammar = wrap(function()
|
||||
symx"[" * Exp/mark"index" * sym"]"
|
||||
)^1 / mark"chain",
|
||||
|
||||
TableLit = sym"{" * Ct(ExpList^-1) * sym"}" / mark"list",
|
||||
TableValue = KeyValue + Ct(Exp),
|
||||
|
||||
TableBlockInner = Ct(KeyValueList * (Break^1 * KeyValueList)^0),
|
||||
TableLit = sym"{" * White *
|
||||
Ct((TableValue * ((sym"," + Break) * White * TableValue)^0)^-1) * sym","^-1 *
|
||||
White * sym"}" / mark"table",
|
||||
|
||||
TableBlockInner = Ct(KeyValueLine * (Break^1 * KeyValueLine)^0),
|
||||
|
||||
TableBlock = Break * #Cmt(Indent, advance_indent) * TableBlockInner * OutBlock / mark"table",
|
||||
|
||||
KeyValue = Ct((Name + sym"[" * Exp * sym"]") * symx":" * (Exp + TableBlock)),
|
||||
KeyValueList = Cmt(Indent, check_indent) * KeyValue * (sym"," * KeyValue)^0 * sym","^-1,
|
||||
KeyValueList = KeyValue * (sym"," * KeyValue)^0,
|
||||
KeyValueLine = Cmt(Indent, check_indent) * KeyValueList * sym","^-1,
|
||||
|
||||
FunLit = (sym"(" * Ct(NameList^-1) * sym")" + Ct("")) * sym"->" * (Body + Ct"") / mark"fndef",
|
||||
|
||||
|
@ -29,3 +29,42 @@ fwip =
|
||||
fruit: basket
|
||||
nuts: day
|
||||
|
||||
|
||||
frick = hello: "world"
|
||||
|
||||
frack, best = hello: "world", rice: 3434, "what"
|
||||
|
||||
ya = { 1,2,3, key: 100, 343, "hello", umm: 232 }
|
||||
|
||||
|
||||
x = { 1,2,
|
||||
4343, 343 ,343 }
|
||||
|
||||
|
||||
g, p = {
|
||||
1,2, nowy: "yes", 3,4,
|
||||
hey: 232, another: "day"
|
||||
}, 234
|
||||
|
||||
annother = {
|
||||
1,2,3
|
||||
3,4,5
|
||||
6,7,8
|
||||
}
|
||||
|
||||
yeah = {
|
||||
[232]: 3434, "helo"
|
||||
ice: "cake"
|
||||
}
|
||||
|
||||
-- confusing stuff...
|
||||
whatabout = {
|
||||
hello world, another
|
||||
what, about, now
|
||||
|
||||
hello"world", yeah
|
||||
hello "world", yeah
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -22,3 +22,51 @@ local fwip = {
|
||||
fruit = basket,
|
||||
nuts = day
|
||||
}
|
||||
local frick = { hello = "world" }
|
||||
local frack, best = { hello = "world", rice = 3434 }, "what"
|
||||
local ya = {
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
key = 100,
|
||||
343,
|
||||
"hello",
|
||||
umm = 232
|
||||
}
|
||||
local x = {
|
||||
1,
|
||||
2,
|
||||
4343,
|
||||
343,
|
||||
343
|
||||
}
|
||||
local g, p = {
|
||||
1,
|
||||
2,
|
||||
nowy = "yes",
|
||||
3,
|
||||
4,
|
||||
hey = 232,
|
||||
another = "day"
|
||||
}, 234
|
||||
local annother = {
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
8
|
||||
}
|
||||
local yeah = { [232] = 3434, "helo", ice = "cake" }
|
||||
local whatabout = {
|
||||
hello(world, another),
|
||||
what,
|
||||
about,
|
||||
now,
|
||||
hello("world"),
|
||||
yeah,
|
||||
hello("world", yeah)
|
||||
}
|
Loading…
Reference in New Issue
Block a user