Use plurals for item, listelem, and caption
This commit is contained in:
parent
0ba38e041e
commit
f9b29ba6e3
@ -45,9 +45,12 @@ all attributes are lowercase.
|
||||
While I try to reduce backwards incompatibilities, sometimes they are necessary
|
||||
to either fix bugs in formspec_ast or for implementing new formspec features.
|
||||
|
||||
### February 2022
|
||||
#### February 2022
|
||||
|
||||
- The value of scrollbars is now a number instead of a string.
|
||||
- The `item`, `listelem`, and `caption` fields are now `items`, `listelems`,
|
||||
and `captions`. The old names still work when unparsing formspecs for now
|
||||
but are no longer used when parsing formspecs.
|
||||
|
||||
#### March 2021
|
||||
|
||||
|
11
core.lua
11
core.lua
@ -240,7 +240,7 @@ types['...'] = function(elems, obj, res)
|
||||
t[k] = v
|
||||
end
|
||||
end
|
||||
res[obj[1] .. 's'] = t
|
||||
res[obj[1]] = t
|
||||
elseif type(obj[2]) == 'string' then
|
||||
res[obj[1]] = val
|
||||
else
|
||||
@ -361,16 +361,21 @@ function formspec_ast.parse(fs, custom_handlers)
|
||||
end
|
||||
|
||||
-- Unparsing
|
||||
local compat_keys = {listelems = "listelem", items = "item",
|
||||
captions = "caption"}
|
||||
local function unparse_ellipsis(elem, obj1, res, inner)
|
||||
if obj1[2] == 'table' then
|
||||
local value = elem[obj1[1] .. 's']
|
||||
local value = elem[obj1[1]]
|
||||
assert(type(value) == 'table', 'Invalid AST!')
|
||||
for k, v in pairs(value) do
|
||||
table.insert(res, tostring(k) .. '=' .. tostring(v))
|
||||
end
|
||||
elseif type(obj1[2]) == 'string' then
|
||||
local value = elem[obj1[1]]
|
||||
if value == nil then return end
|
||||
if value == nil then
|
||||
value = elem[compat_keys[obj1[1]]]
|
||||
if value == nil then return end
|
||||
end
|
||||
for _, v in ipairs(value) do
|
||||
table.insert(res, tostring(v))
|
||||
end
|
||||
|
10
elements.lua
10
elements.lua
@ -44,17 +44,17 @@ a[37] = {"default", "string"}
|
||||
a[38] = {a[4], a[3], a[21], a[35], a[37]}
|
||||
a[39] = {{a[4], a[35]}}
|
||||
a[40] = {a[4], a[3], a[19], a[21], a[35]}
|
||||
a[41] = {{{"listelem", "string"}, "..."}}
|
||||
a[41] = {{{"listelems", "string"}, "..."}}
|
||||
a[42] = {"selected_idx", "number"}
|
||||
a[43] = {"transparent", "boolean"}
|
||||
a[44] = {{{"caption", "string"}, "..."}}
|
||||
a[44] = {{{"captions", "string"}, "..."}}
|
||||
a[45] = {"current_tab", "string"}
|
||||
a[46] = {"draw_border", "boolean"}
|
||||
a[47] = {{{"item", "string"}, "..."}}
|
||||
a[47] = {{{"items", "string"}, "..."}}
|
||||
a[48] = {"index_event", "boolean"}
|
||||
a[49] = {{"opt", "table"}, "..."}
|
||||
a[49] = {{"opts", "table"}, "..."}
|
||||
a[50] = {{a[49]}}
|
||||
a[51] = {{"prop", "table"}, "..."}
|
||||
a[51] = {{"props", "table"}, "..."}
|
||||
a[52] = {a[21]}
|
||||
a[53] = {{{{{"selectors", "string"}, "..."}}, a[51]}, {a[52], a[51]}}
|
||||
return {["formspec_version"] = {{{"version", "number"}}}, ["size"] = {{a[3]}, {{a[1], a[2], {"fixed_size", "boolean"}}}}, ["position"] = a[5], ["anchor"] = a[5], ["padding"] = a[5], ["no_prepend"] = a[7], ["real_coordinates"] = {{{"bool", "boolean"}}}, ["container"] = a[5], ["container_end"] = a[7], ["scroll_container"] = {{a[4], a[3], a[8], a[9], {"scroll_factor", "number"}}, {a[4], a[3], a[8], a[9]}}, ["scroll_container_end"] = a[7], ["list"] = {{a[10], a[11], a[4], a[3], {"starting_item_index", "number"}}, {a[10], a[11], a[4], a[3]}}, ["listring"] = {{a[10], a[11]}, a[6]}, ["listcolors"] = {{a[12], a[13], a[14], {"tooltip_bgcolor", "string"}, {"tooltip_fontcolor", "string"}}, {a[12], a[13], a[14]}, {a[12], a[13]}}, ["tooltip"] = {{a[4], a[3], a[15], a[16], a[17]}, {a[4], a[3], a[15], a[16]}, {a[18], a[15], a[16], a[17]}, {a[4], a[3], a[15]}, {a[18], a[15], a[16]}, {a[18], a[15]}}, ["image"] = {a[20]}, ["animated_image"] = {{a[4], a[3], a[21], a[19], a[22], a[23], {"frame_start", "number"}}, {a[4], a[3], a[21], a[19], a[22], a[23]}}, ["model"] = {{a[4], a[3], a[21], a[24], a[25], a[26], a[27], a[28], a[29], {"animation_speed", "number"}}, {a[4], a[3], a[21], a[24], a[25], a[26], a[27], a[28], a[29]}, {a[4], a[3], a[21], a[24], a[25], a[26], a[27], a[28]}, {a[4], a[3], a[21], a[24], a[25], a[26], a[27]}, {a[4], a[3], a[21], a[24], a[25], a[26]}, {a[4], a[3], a[21], a[24], a[25]}}, ["item_image"] = {{a[4], a[3], a[30]}}, ["bgcolor"] = {{a[16], a[31], {"fbgcolor", "string"}}, {a[16], a[31]}, {a[16]}}, ["background"] = {{a[4], a[3], a[19], a[32]}, a[20]}, ["background9"] = {{a[4], a[3], a[19], a[32], {a[33], a[34], {"middle_x2", "number"}, {"middle_y2", "number"}}}, {a[4], a[3], a[19], a[32], {a[33], a[34]}}, {a[4], a[3], a[19], a[32], {a[33]}}}, ["pwdfield"] = a[36], ["field"] = {a[38], {a[21], a[35], a[37]}}, ["field_close_on_enter"] = {{a[21], {"close_on_enter", "boolean"}}}, ["textarea"] = {a[38]}, ["label"] = a[39], ["hypertext"] = {{a[4], a[3], a[21], {"text", "string"}}}, ["vertlabel"] = a[39], ["button"] = a[36], ["image_button"] = {{a[4], a[3], a[19], a[21], a[35], {"noclip", "boolean"}, {"drawborder", "boolean"}, {"pressed_texture_name", "string"}}, a[40]}, ["item_image_button"] = {{a[4], a[3], a[30], a[21], a[35]}}, ["button_exit"] = a[36], ["image_button_exit"] = {a[40]}, ["textlist"] = {{a[4], a[3], a[21], a[41], a[42], a[43]}, {a[4], a[3], a[21], a[41], a[42]}, {a[4], a[3], a[21], a[41]}}, ["tabheader"] = {{a[4], a[2], a[21], a[44], a[45], a[43], a[46]}, {a[4], a[3], a[21], a[44], a[45], a[43], a[46]}, {a[4], a[21], a[44], a[45], a[43], a[46]}, {a[4], a[2], a[21], a[44], a[45], a[43]}, {a[4], a[3], a[21], a[44], a[45], a[43]}, {a[4], a[21], a[44], a[45], a[43]}, {a[4], a[2], a[21], a[44], a[45]}, {a[4], a[3], a[21], a[44], a[45]}, {a[4], a[21], a[44], a[45]}}, ["box"] = {{a[4], a[3], {"color", "string"}}}, ["dropdown"] = {{a[4], a[3], a[21], a[47], a[42], a[48]}, {a[4], a[1], a[21], a[47], a[42], a[48]}, {a[4], a[3], a[21], a[47], a[42]}, {a[4], a[1], a[21], a[47], a[42]}}, ["checkbox"] = {{a[4], a[21], a[35], {"selected", "boolean"}}, {a[4], a[21], a[35]}}, ["scrollbar"] = {{a[4], a[3], a[9], a[21], {"value", "number"}}}, ["scrollbaroptions"] = a[50], ["table"] = {{a[4], a[3], a[21], {{{"cells", "string"}, "..."}}, a[42]}}, ["tableoptions"] = a[50], ["tablecolumns"] = {{{{{"type", "string"}, a[49]}, "..."}}}, ["style"] = a[53], ["style_type"] = a[53], ["set_focus"] = {{a[21], {"force", "boolean"}}, a[52]}}
|
||||
|
@ -111,7 +111,7 @@ dropdown:
|
||||
- - [w, number]
|
||||
- [h, number]
|
||||
- [name, string]
|
||||
- - - [item, string]
|
||||
- - - [items, string]
|
||||
- '...'
|
||||
- [selected_idx, number]
|
||||
- [index_event, boolean]
|
||||
@ -119,7 +119,7 @@ dropdown:
|
||||
- [y, number]
|
||||
- [w, number]
|
||||
- [name, string]
|
||||
- - - [item, string]
|
||||
- - - [items, string]
|
||||
- '...'
|
||||
- [selected_idx, number]
|
||||
- [index_event, boolean]
|
||||
@ -128,14 +128,14 @@ dropdown:
|
||||
- - [w, number]
|
||||
- [h, number]
|
||||
- [name, string]
|
||||
- - - [item, string]
|
||||
- - - [items, string]
|
||||
- '...'
|
||||
- [selected_idx, number]
|
||||
- - - [x, number]
|
||||
- [y, number]
|
||||
- [w, number]
|
||||
- [name, string]
|
||||
- - - [item, string]
|
||||
- - - [items, string]
|
||||
- '...'
|
||||
- [selected_idx, number]
|
||||
field:
|
||||
@ -353,7 +353,7 @@ scrollbar:
|
||||
- [name, string]
|
||||
- [value, number]
|
||||
scrollbaroptions:
|
||||
- - - [opt, table]
|
||||
- - - [opts, table]
|
||||
- '...'
|
||||
set_focus:
|
||||
- - [name, string]
|
||||
@ -368,25 +368,25 @@ size:
|
||||
style:
|
||||
- - - - [selectors, string]
|
||||
- '...'
|
||||
- - [prop, table]
|
||||
- - [props, table]
|
||||
- '...'
|
||||
- - - [name, string]
|
||||
- - [prop, table]
|
||||
- - [props, table]
|
||||
- '...'
|
||||
style_type:
|
||||
- - - - [selectors, string]
|
||||
- '...'
|
||||
- - [prop, table]
|
||||
- - [props, table]
|
||||
- '...'
|
||||
- - - [name, string]
|
||||
- - [prop, table]
|
||||
- - [props, table]
|
||||
- '...'
|
||||
tabheader:
|
||||
- - - [x, number]
|
||||
- [y, number]
|
||||
- [h, number]
|
||||
- [name, string]
|
||||
- - - [caption, string]
|
||||
- - - [captions, string]
|
||||
- '...'
|
||||
- [current_tab, string]
|
||||
- [transparent, boolean]
|
||||
@ -396,7 +396,7 @@ tabheader:
|
||||
- - [w, number]
|
||||
- [h, number]
|
||||
- [name, string]
|
||||
- - - [caption, string]
|
||||
- - - [captions, string]
|
||||
- '...'
|
||||
- [current_tab, string]
|
||||
- [transparent, boolean]
|
||||
@ -404,7 +404,7 @@ tabheader:
|
||||
- - - [x, number]
|
||||
- [y, number]
|
||||
- [name, string]
|
||||
- - - [caption, string]
|
||||
- - - [captions, string]
|
||||
- '...'
|
||||
- [current_tab, string]
|
||||
- [transparent, boolean]
|
||||
@ -413,7 +413,7 @@ tabheader:
|
||||
- [y, number]
|
||||
- [h, number]
|
||||
- [name, string]
|
||||
- - - [caption, string]
|
||||
- - - [captions, string]
|
||||
- '...'
|
||||
- [current_tab, string]
|
||||
- [transparent, boolean]
|
||||
@ -422,14 +422,14 @@ tabheader:
|
||||
- - [w, number]
|
||||
- [h, number]
|
||||
- [name, string]
|
||||
- - - [caption, string]
|
||||
- - - [captions, string]
|
||||
- '...'
|
||||
- [current_tab, string]
|
||||
- [transparent, boolean]
|
||||
- - - [x, number]
|
||||
- [y, number]
|
||||
- [name, string]
|
||||
- - - [caption, string]
|
||||
- - - [captions, string]
|
||||
- '...'
|
||||
- [current_tab, string]
|
||||
- [transparent, boolean]
|
||||
@ -437,7 +437,7 @@ tabheader:
|
||||
- [y, number]
|
||||
- [h, number]
|
||||
- [name, string]
|
||||
- - - [caption, string]
|
||||
- - - [captions, string]
|
||||
- '...'
|
||||
- [current_tab, string]
|
||||
- - - [x, number]
|
||||
@ -445,13 +445,13 @@ tabheader:
|
||||
- - [w, number]
|
||||
- [h, number]
|
||||
- [name, string]
|
||||
- - - [caption, string]
|
||||
- - - [captions, string]
|
||||
- '...'
|
||||
- [current_tab, string]
|
||||
- - - [x, number]
|
||||
- [y, number]
|
||||
- [name, string]
|
||||
- - - [caption, string]
|
||||
- - - [captions, string]
|
||||
- '...'
|
||||
- [current_tab, string]
|
||||
table:
|
||||
@ -465,11 +465,11 @@ table:
|
||||
- [selected_idx, number]
|
||||
tablecolumns:
|
||||
- - - - [type, string]
|
||||
- - [opt, table]
|
||||
- - [opts, table]
|
||||
- '...'
|
||||
- '...'
|
||||
tableoptions:
|
||||
- - - [opt, table]
|
||||
- - - [opts, table]
|
||||
- '...'
|
||||
textarea:
|
||||
- - - [x, number]
|
||||
@ -485,7 +485,7 @@ textlist:
|
||||
- - [w, number]
|
||||
- [h, number]
|
||||
- [name, string]
|
||||
- - - [listelem, string]
|
||||
- - - [listelems, string]
|
||||
- '...'
|
||||
- [selected_idx, number]
|
||||
- [transparent, boolean]
|
||||
@ -494,7 +494,7 @@ textlist:
|
||||
- - [w, number]
|
||||
- [h, number]
|
||||
- [name, string]
|
||||
- - - [listelem, string]
|
||||
- - - [listelems, string]
|
||||
- '...'
|
||||
- [selected_idx, number]
|
||||
- - - [x, number]
|
||||
@ -502,7 +502,7 @@ textlist:
|
||||
- - [w, number]
|
||||
- [h, number]
|
||||
- [name, string]
|
||||
- - - [listelem, string]
|
||||
- - - [listelems, string]
|
||||
- '...'
|
||||
tooltip:
|
||||
- - - [x, number]
|
||||
|
@ -21,7 +21,7 @@ _known = _make_known(
|
||||
'noclip', 'drawborder', 'selected', 'force', 'close_on_enter',
|
||||
'continuous', 'mouse_control', 'index_event'),
|
||||
fullscreen=('fullscreen',),
|
||||
table=('param', 'opt', 'prop'),
|
||||
table=('params', 'opts', 'props'),
|
||||
null=('',),
|
||||
)
|
||||
|
||||
@ -69,7 +69,7 @@ def _fix_param(param):
|
||||
else:
|
||||
while res and _get_name(res[-1]) == name:
|
||||
res.pop()
|
||||
res.append((_fix_param(name), '...'))
|
||||
res.append((_fix_param(name + 's'), '...'))
|
||||
break
|
||||
|
||||
return res
|
||||
|
35
tests.lua
35
tests.lua
@ -192,7 +192,7 @@ test_parse_unparse(fs, {
|
||||
y = 0,
|
||||
w = 1,
|
||||
name = "test",
|
||||
item = {"abc", "def", "ghi", "jkl"},
|
||||
items = {"abc", "def", "ghi", "jkl"},
|
||||
selected_idx = 2,
|
||||
},
|
||||
{
|
||||
@ -201,7 +201,7 @@ test_parse_unparse(fs, {
|
||||
y = 0,
|
||||
w = 1,
|
||||
name = "test",
|
||||
item = {"abc", "def", "ghi", "jkl"},
|
||||
items = {"abc", "def", "ghi", "jkl"},
|
||||
selected_idx = 2,
|
||||
index_event = true,
|
||||
},
|
||||
@ -371,6 +371,37 @@ test_parse('style[name,name2;bgcolor=blue;textcolor=yellow]', {
|
||||
},
|
||||
})
|
||||
|
||||
-- Test item/items compatibility
|
||||
assert_equal(
|
||||
'dropdown[0,0;1,2;test;abc,def,ghi,jkl;2;true]',
|
||||
assert(formspec_ast.unparse({
|
||||
{
|
||||
type = "dropdown",
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 1,
|
||||
h = 2,
|
||||
name = "test",
|
||||
items = {"abc", "def", "ghi", "jkl"},
|
||||
selected_idx = 2,
|
||||
index_event = true,
|
||||
},
|
||||
})),
|
||||
assert(formspec_ast.unparse({
|
||||
{
|
||||
type = "dropdown",
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 1,
|
||||
h = 2,
|
||||
name = "test",
|
||||
item = {"abc", "def", "ghi", "jkl"},
|
||||
selected_idx = 2,
|
||||
index_event = true,
|
||||
},
|
||||
}))
|
||||
)
|
||||
|
||||
-- Ensure the style[] unparse compatibility works correctly
|
||||
assert_equal(
|
||||
'style_type[test;abc=def]',
|
||||
|
Loading…
Reference in New Issue
Block a user