more tables

This commit is contained in:
leaf corcoran 2011-05-22 22:12:21 -07:00
parent 66b20ef1ce
commit 1cb205608a
4 changed files with 108 additions and 10 deletions

View File

@ -124,12 +124,16 @@ local compiler_index = {
self:indent(1) self:indent(1)
local item_values = {} local item_values = {}
for _, item in ipairs(items) do for _, item in ipairs(items) do
local key = self:value(item[1]) if #item == 1 then
if type(item[1]) ~= "string" then table.insert(item_values, self:value(item[1]))
key = ("[%s]"):format(key) else
end 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 end
local i = self:ichar() local i = self:ichar()
self:indent(-1) self:indent(-1)

View File

@ -23,7 +23,7 @@ local function count_indent(str)
end end
local R, S, V, P = lpeg.R, lpeg.S, lpeg.V, lpeg.P 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 White = S" \t\n"^0
local _Space = S" \t"^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", Exp = Ct(Term * (FactorOp * Term)^0) / flatten_or_mark"exp",
Term = Ct(Value * (TermOp * Value)^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, String = Space * DoubleString + Space * SingleString + LuaString,
SingleString = simple_string("'"), SingleString = simple_string("'"),
@ -216,14 +218,19 @@ local build_grammar = wrap(function()
symx"[" * Exp/mark"index" * sym"]" symx"[" * Exp/mark"index" * sym"]"
)^1 / mark"chain", )^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", TableBlock = Break * #Cmt(Indent, advance_indent) * TableBlockInner * OutBlock / mark"table",
KeyValue = Ct((Name + sym"[" * Exp * sym"]") * symx":" * (Exp + TableBlock)), 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", FunLit = (sym"(" * Ct(NameList^-1) * sym")" + Ct("")) * sym"->" * (Body + Ct"") / mark"fndef",

View File

@ -29,3 +29,42 @@ fwip =
fruit: basket fruit: basket
nuts: day 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
}

View File

@ -21,4 +21,52 @@ local fwip = {
what = yo("momma", "yeah"), what = yo("momma", "yeah"),
fruit = basket, fruit = basket,
nuts = day 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)
} }