1
0
Fork 0
mirror of https://github.com/Oreolek/ink-instead.git synced 2024-05-02 00:59:26 +03:00

gather parser, todo: runtime, gather+divert

This commit is contained in:
premek 2017-08-20 18:39:01 +02:00
parent 88e8994a0b
commit e494c4f855
4 changed files with 68 additions and 4 deletions

View file

@ -28,7 +28,10 @@ local stitch = Ct(P('=')^1/'stitch' * wh * C(id) * wh * P('=')^0) * wh
local optDiv = '[' * C((P(1) - ']')^0) * ']' local optDiv = '[' * C((P(1) - ']')^0) * ']'
local optStars = wh * Ct(C'*' * (sp * C'*')^0)/table.getn local optStar = sp * C'*'
local optStars = wh * Ct(optStar * optStar^0)/table.getn
local gatherMark = sp * C'-'
local gatherMarks = wh * Ct(gatherMark * gatherMark^0)/table.getn
local hash = P('#') local hash = P('#')
local tag = hash * wh * V'text' local tag = hash * wh * V'text'
@ -48,6 +51,7 @@ local ink = P({
optAns = V'optAnsWithDiv' + V'optAnsWithoutDiv', optAns = V'optAnsWithDiv' + V'optAnsWithoutDiv',
option = Ct(Cc'option' * optStars * sp * V'optAns'), option = Ct(Cc'option' * optStars * sp * V'optAns'),
gather = Ct(Cc'gather' * gatherMarks * sp * V'text'),
@ -56,7 +60,7 @@ local ink = P({
para = tagAbove^0 * Ct(Cc'para' * V'text') * tagEnd^0 * wh + tagGlobal, para = tagAbove^0 * Ct(Cc'para' * V'text') * tagEnd^0 * wh + tagGlobal,
line = V'stmt' + V'para', line = V'stmt' + V'gather'+ V'para' ,
lines = Ct(V'line'^0) lines = Ct(V'line'^0)
}) })

54
test/parser/gather.lua Normal file
View file

@ -0,0 +1,54 @@
return {
ink=[[
I looked at Monsieur Fogg
* ... and I could contain myself no longer.
'What is the purpose of our journey, Monsieur?'
'A wager,' he replied.
* * 'A wager!'[] I returned.
He nodded.
* * * 'But surely that is foolishness!'
* * * 'A most serious matter then!'
- - - He nodded again.
* * * 'But can we win?'
'That is what we will endeavour to find out,' he answered.
* * * 'A modest wager, I trust?'
'Twenty thousand pounds,' he replied, quite flatly.
* * * I asked nothing further of him then[.], and after a final, polite cough, he offered nothing more to me. <>
* * 'Ah[.'],' I replied, uncertain what I thought.
- - After that, <>
* ... but I said nothing[] and <>
- we passed the day in silence.
- -> END
]], expected= {
{"para", "I looked at Monsieur Fogg"},
{"option", 1, "... and I could contain myself no longer.", "", ""},
{"para", "'What is the purpose of our journey, Monsieur?'"},
{"para", "'A wager,' he replied."},
{"option", 2, "'A wager!'", "", " I returned."},
{"para", "He nodded."},
{"option", 3, "'But surely that is foolishness!'", "", ""},
{"option", 3, "'A most serious matter then!'", "", ""},
{"gather", 3, "He nodded again."},
{"option", 3, "'But can we win?'", "", ""},
{"para", "'That is what we will endeavour to find out,' he answered."},
{"option", 3, "'A modest wager, I trust?'", "", ""},
{"para", "'Twenty thousand pounds,' he replied, quite flatly."},
{
"option",
3,
"I asked nothing further of him then",
".",
", and after a final, polite cough, he offered nothing more to me. "
},
{"glue"},
{"option", 2, "'Ah", ".'", ",' I replied, uncertain what I thought."},
{"gather", 2, "After that, "},
{"glue"},
{"option", 1, "... but I said nothing", "", " and "},
{"glue"},
{"gather", 1, "we passed the day in silence."},
{"gather", 2, "> END"} -- FIXME!
}
}

View file

@ -3,12 +3,16 @@ ink=[[
* "Murder!" * "Murder!"
** A ** A
* * A * * A
* * * B
*** B
* "Suicide!" * "Suicide!"
]], expected= { ]], expected= {
{"option", 1, '"Murder!"', "", ""}, {"option", 1, '"Murder!"', "", ""},
{"option", 2, "A", "", ""}, {"option", 2, "A", "", ""},
{"option", 2, "A", "", ""}, {"option", 2, "A", "", ""},
{"option", 3, "B", "", ""},
{"option", 3, "B", "", ""},
{"option", 1, '"Suicide!"', "", ""} {"option", 1, '"Suicide!"', "", ""}
} }

View file

@ -27,6 +27,7 @@ function testBranching() doTest('branching') end
function testGlue() doTest('glue') end function testGlue() doTest('glue') end
function testInclude() doTest('include') end function testInclude() doTest('include') end
function testTags() doTest('tags') end function testTags() doTest('tags') end
function testGather() doTest('gather') end
--- runtime --- --- runtime ---
@ -40,7 +41,7 @@ end
function testRChoices() function testRChoices()
local story = pink.getStory('test/runtime/branching.ink') local story = pink.getStory('test/runtime/branching.ink')
story.choosePathString('back_in_london'); story.choosePathString('back_in_london');
story.continue() story.continue()
luaunit.assertEquals(story.continue(), 'exactly') luaunit.assertEquals(story.continue(), 'exactly')
luaunit.assertFalse(story.canContinue) luaunit.assertFalse(story.canContinue)
@ -49,7 +50,8 @@ function testRChoices()
luaunit.assertEquals(story.continue(), 'My master clouted me firmly around the head') luaunit.assertEquals(story.continue(), 'My master clouted me firmly around the head')
luaunit.assertEquals(#story.currentChoices, 2) luaunit.assertEquals(#story.currentChoices, 2)
story.chooseChoiceIndex(2) story.chooseChoiceIndex(2)
luaunit.assertEquals(story.continue(), 'huhu') luaunit.assertEquals(story.continue(), 'huhu')
luaunit.assertFalse(story.canContinue)
end end