1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-27 16:49:31 +00:00

Preserve tags in choices children

This commit is contained in:
Étienne Fildadut 2021-04-12 01:58:10 +02:00
parent b9c6d1d704
commit 5c3e9d2c5d
5 changed files with 134 additions and 30 deletions

View file

@ -9,7 +9,7 @@ local function format_text(t, prefix)
for _, l in ipairs(t) do
r = r .. prefix
local tags = ""
for k, v in ipairs(l.tags) do
for k, v in pairs(l.tags) do
tags = tags .. ("[%q]=%q"):format(k, v)
end
if tags ~= "" then
@ -39,6 +39,17 @@ local function compare(a, b)
end
end
local function write_result(filebase, result)
local o = assert(io.open(filebase..".lua", "w"))
o:write(ser(result))
o:write("\n--[[\n")
for _, v in ipairs(result) do
o:write(inspect(v).."\n")
end
o:write("]]--")
o:close()
end
-- parse args
local args = {}
local i=1
@ -163,15 +174,8 @@ else
table.insert(result, { "error", err })
end
if args.write then
local o = assert(io.open(filebase..".lua", "w"))
o:write(ser(result))
o:write("\n--[[\n")
for _, v in ipairs(result) do
o:write(inspect(v).."\n")
end
o:write("]]--")
o:close()
if args["write-all"] then
write_result(filebase, result)
else
local o, e = loadfile(filebase..".lua")
if o then
@ -188,7 +192,10 @@ else
success = success + 1
end
else
if not args.silent then
if args["write-new"] and e:match("No such file") then
write_result(filebase, result)
print("Written result file for "..filebase)
elseif not args.silent then
print("> "..namespace)
print(e)
print("result was:")

View file

@ -0,0 +1,16 @@
$ f
# 42
> a
b
~ f
> c
~ choose(1)
# "k":"v"
~ f
> d
~ choose(1)
e
f

View file

@ -0,0 +1,69 @@
local _={}
_[26]={}
_[25]={k="v"}
_[24]={42,k="v"}
_[23]={}
_[22]={42}
_[21]={tags=_[26],data="f"}
_[20]={tags=_[25],data="e"}
_[19]={tags=_[24],data="b"}
_[18]={tags=_[25],data="d"}
_[17]={tags=_[24],data="a"}
_[16]={tags=_[22],data="b"}
_[15]={tags=_[23],data="c"}
_[14]={tags=_[22],data="a"}
_[13]={_[21]}
_[12]={_[20]}
_[11]={_[19]}
_[10]={_[17],_[18]}
_[9]={_[16]}
_[8]={_[14],_[15]}
_[7]={"return"}
_[6]={"text",_[13]}
_[5]={"text",_[12]}
_[4]={"text",_[11]}
_[3]={"choice",_[10]}
_[2]={"text",_[9]}
_[1]={"choice",_[8]}
return {_[1],_[2],_[3],_[4],_[5],_[6],_[7]}
--[[
{ "choice", { {
data = "a",
tags = { 42 }
}, {
data = "c",
tags = {}
} } }
{ "text", { {
data = "b",
tags = { 42 }
} } }
{ "choice", { {
data = "a",
tags = { 42,
k = "v"
}
}, {
data = "d",
tags = {
k = "v"
}
} } }
{ "text", { {
data = "b",
tags = { 42,
k = "v"
}
} } }
{ "text", { {
data = "e",
tags = {
k = "v"
}
} } }
{ "text", { {
data = "f",
tags = {}
} } }
{ "return" }
]]--