mirror of
https://github.com/Oreolek/ink-instead.git
synced 2024-06-26 03:50:45 +03:00
glue test
This commit is contained in:
parent
f978875905
commit
29b40f7a96
|
@ -6,18 +6,21 @@ We arrived into London at 9.45pm exactly.
|
||||||
-> hurry_outside
|
-> hurry_outside
|
||||||
|
|
||||||
* "Monsieur, let us savour this moment!"[] I declared.
|
* "Monsieur, let us savour this moment!"[] I declared.
|
||||||
My master clouted me firmly around the head and dragged me out of the door.
|
My master clouted me firmly around the head
|
||||||
|
** A
|
||||||
|
**B
|
||||||
|
and dragged me out of the door. <>
|
||||||
-> dragged_outside
|
-> dragged_outside
|
||||||
|
|
||||||
* [We hurried home] -> hurry_outside
|
* [We hurried home] -> hurry_outside
|
||||||
|
|
||||||
|
|
||||||
=== hurry_outside ===
|
=== hurry_outside ===
|
||||||
We hurried home to Savile Row -> as_fast_as_we_could
|
We hurried home to Savile Row -> as_fast_as_we_could
|
||||||
|
|
||||||
|
|
||||||
=== dragged_outside ===
|
=== dragged_outside ===
|
||||||
He insisted that we hurried home to Savile Row
|
He insisted that we hurried <> home to Savile Row
|
||||||
-> as_fast_as_we_could
|
-> as_fast_as_we_could
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ local commOL = sp * '//' * sp * (1-nl)^0 * wh
|
||||||
local commML = sp * '/*' * wh * (P(1)-'*/')^0 * '*/' * wh
|
local commML = sp * '/*' * wh * (P(1)-'*/')^0 * '*/' * wh
|
||||||
local comm = commOL + commML + todo
|
local comm = commOL + commML + todo
|
||||||
|
|
||||||
local glue = P'<>'/'glue' *wh
|
local glue = P'<>'/'glue' *wh -- FIXME do not consume spaces after glue
|
||||||
|
|
||||||
local divertSym = '->' *wh
|
local divertSym = '->' *wh
|
||||||
local divertEndSym = C('END') *wh
|
local divertEndSym = C('END') *wh
|
||||||
|
|
|
@ -1,25 +1,26 @@
|
||||||
require('util') -- XXX
|
require('util') -- XXX
|
||||||
|
|
||||||
local is = function (what, node)
|
local is = function (what, node)
|
||||||
return node ~= nil and type(node) == "table" and node[1] == what
|
return node ~= nil
|
||||||
|
and (type(node) == "table" and node[1] == what)
|
||||||
|
or (type(node) == "string" and node == what)
|
||||||
end
|
end
|
||||||
|
|
||||||
local getPara = function (node)
|
local getPara = function (node)
|
||||||
if is('para', node) then return node[2] end
|
if is('para', node) then return node[2] end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
return function (tree)
|
return function (tree)
|
||||||
print(to_string(tree))
|
--print(to_string(tree))
|
||||||
local s = {}
|
local s = {}
|
||||||
|
|
||||||
local pointer = 1
|
local pointer = nil
|
||||||
local tab = tree
|
local tab = {}
|
||||||
|
|
||||||
local knots = {}
|
local knots = {}
|
||||||
|
|
||||||
local process = function ()
|
local process = function ()
|
||||||
for i, v in ipairs(tree) do
|
for _, v in ipairs(tree) do
|
||||||
if is('knot', v) then
|
if is('knot', v) then
|
||||||
knots[v[2]] = v
|
knots[v[2]] = v
|
||||||
end
|
end
|
||||||
|
@ -55,12 +56,31 @@ return function (tree)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local step = function ()
|
||||||
|
pointer = pointer + 1
|
||||||
|
update()
|
||||||
|
return tab[pointer]
|
||||||
|
end
|
||||||
|
|
||||||
|
local stepTo = function (table, pos)
|
||||||
|
tab = table
|
||||||
|
pointer = pos
|
||||||
|
update()
|
||||||
|
return tab[pointer]
|
||||||
|
end
|
||||||
|
|
||||||
s.canContinue = nil
|
s.canContinue = nil
|
||||||
|
|
||||||
s.continue = function()
|
s.continue = function()
|
||||||
local res = getPara(tab[pointer])
|
local res = getPara(tab[pointer])
|
||||||
pointer = pointer + 1
|
local next = step()
|
||||||
update()
|
|
||||||
|
if is('glue', next) then
|
||||||
|
step()
|
||||||
|
res = res .. s.continue()
|
||||||
|
end
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -70,16 +90,14 @@ return function (tree)
|
||||||
s.currentChoices = {}
|
s.currentChoices = {}
|
||||||
local choice = tab[pointer]
|
local choice = tab[pointer]
|
||||||
local option = choice[1 + index]
|
local option = choice[1 + index]
|
||||||
tab = option
|
stepTo(option, 5)
|
||||||
pointer = 5
|
|
||||||
update()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
s.choosePathString = function(knotName) end
|
s.choosePathString = function(knotName) end
|
||||||
s.variablesState = {}
|
s.variablesState = {}
|
||||||
-- s.state.ToJson();s.state.LoadJson(savedJson);
|
-- s.state.ToJson();s.state.LoadJson(savedJson);
|
||||||
|
|
||||||
update()
|
stepTo(tree, 1)
|
||||||
process()
|
process()
|
||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
|
|
1
test.lua
1
test.lua
|
@ -24,6 +24,7 @@ function testNest() doTest('nested') end
|
||||||
function testNest2() doTest('nested2') end
|
function testNest2() doTest('nested2') end
|
||||||
function testKnot() doTest('knot') end
|
function testKnot() doTest('knot') end
|
||||||
function testBranching() doTest('branching') end
|
function testBranching() doTest('branching') end
|
||||||
|
function testGlue() doTest('glue') end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ We arrived into London at 9.45pm exactly.
|
||||||
-> hurry_outside
|
-> hurry_outside
|
||||||
|
|
||||||
* "Monsieur, let us savour this moment!"[] I declared.
|
* "Monsieur, let us savour this moment!"[] I declared.
|
||||||
My master clouted me firmly around the head and dragged me out of the door.
|
My master clouted me firmly around the head and dragged me out of the door.<>
|
||||||
-> dragged_outside
|
-> dragged_outside
|
||||||
|
|
||||||
* [We hurried home] -> hurry_outside
|
* [We hurried home] -> hurry_outside
|
||||||
|
@ -49,6 +49,7 @@ expected= {
|
||||||
"para",
|
"para",
|
||||||
"My master clouted me firmly around the head and dragged me out of the door."
|
"My master clouted me firmly around the head and dragged me out of the door."
|
||||||
},
|
},
|
||||||
|
'glue',
|
||||||
{"divert", "dragged_outside"}
|
{"divert", "dragged_outside"}
|
||||||
},
|
},
|
||||||
{"option", "", "We hurried home", " ", {"divert", "hurry_outside"}}
|
{"option", "", "We hurried home", " ", {"divert", "hurry_outside"}}
|
||||||
|
|
30
test/glue.lua
Normal file
30
test/glue.lua
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
return {
|
||||||
|
ink=[[
|
||||||
|
* "Monsieur, let us savour this moment!"[] I declared.
|
||||||
|
My master clouted me firmly around the head and dragged me out of the door. <>
|
||||||
|
-> dragged_outside
|
||||||
|
* [We hurried home] -> hurry_outside
|
||||||
|
=== as_fast_as_we_could ===
|
||||||
|
<> as fast as we could.
|
||||||
|
|
||||||
|
]],
|
||||||
|
expected={
|
||||||
|
{
|
||||||
|
"choice",
|
||||||
|
{
|
||||||
|
"option",
|
||||||
|
'"Monsieur, let us savour this moment!"',
|
||||||
|
"",
|
||||||
|
" I declared.",
|
||||||
|
{
|
||||||
|
"para",
|
||||||
|
"My master clouted me firmly around the head and dragged me out of the door. "
|
||||||
|
},
|
||||||
|
"glue",
|
||||||
|
{"divert", "dragged_outside"}
|
||||||
|
},
|
||||||
|
{"option", "", "We hurried home", " ", {"divert", "hurry_outside"}}
|
||||||
|
},
|
||||||
|
{"knot", "as_fast_as_we_could", "glue", {"para", "as fast as we could."}} -- TODO should be space before 'as'
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue