mirror of
https://github.com/Oreolek/ink-instead.git
synced 2024-05-11 13:38:24 +03:00
choices
This commit is contained in:
parent
8fe40c413d
commit
244d8af495
34
peg.lua
34
peg.lua
|
@ -10,32 +10,24 @@ end
|
|||
local sp = lpeg.S" \t" ^0
|
||||
local wh = lpeg.S" \t\r\n" ^0
|
||||
local nl = lpeg.S"\r\n" ^1
|
||||
local ch = lpeg.P(1)
|
||||
|
||||
local textLine = (lpeg.P(1)-nl)^1
|
||||
local para = lpeg.C(textLine)
|
||||
local para = lpeg.C((ch-nl)^1) *nl^0
|
||||
|
||||
--local id = lpeg.R("az", "AZ")^1 * sp)^1
|
||||
local commOL = '//' * sp * (ch-nl)^0 -- TODO comment that does not start at the line beginning
|
||||
local commML = '/*' * wh * (ch-'*/')^0 * '*/'
|
||||
local comm = commOL + commML
|
||||
|
||||
local choiceAnswer = '*'* sp * para
|
||||
local flowBlock = para -choiceAnswer
|
||||
local choice = choiceAnswer * (flowBlock)^1
|
||||
local choices = lpeg.Ct(choice^1)
|
||||
|
||||
local commOL = '//' * sp * lpeg.C((lpeg.P(1)-nl)^0) -- TODO comment that does not start at the line beginning
|
||||
local commML = '/*' * wh * lpeg.C((lpeg.P(1)-'*/')^0) * '*/'
|
||||
local comm = (commOL + commML) / function (i) return "comment:"..i; end
|
||||
local statement = wh * (comm + choices + para) * wh
|
||||
|
||||
local line = wh * (comm + para) * wh
|
||||
|
||||
local prog = ((wh * lpeg.Ct((line*wh)^0)) )* -1
|
||||
local prog = ((wh * lpeg.Ct((statement*wh)^0)) )* -1
|
||||
|
||||
local ink = prog
|
||||
print(to_string(ink:match(" asd\naa")))
|
||||
print(to_string(ink:match(" // asd a\ta\naa")))
|
||||
print(to_string(ink:match("/* \tas \n\n \tda\n */")))
|
||||
|
||||
print(to_string(ink:match("// \n \tsome text\n// and some comment\n\n\t\n")))
|
||||
print(to_string(ink:match(" \n \t/* \ndemment \n\t comment\n\n\t */ \n")))
|
||||
print(to_string(ink:match(" \t\t \t ")))
|
||||
print(to_string(ink:match("\n\n \t\n\t \t \n")))
|
||||
|
||||
print(to_string(ink:match("hello\nworld\n//comme nt\ntest\n/*demm*/")))
|
||||
print(to_string(ink:match(" \nFc oh\n")))
|
||||
print(to_string(ink:match(" \nF\tc \n ooo")))
|
||||
print(to_string(ink:match("\"What do you make of this?\" she asked. \n\n// Something unprintable...\n\n\"I couldn't possibly comment,\" I replied.\n/*\n ... or an unlimited block of text\n*/")))
|
||||
test(ink, 'content')
|
||||
test(ink, 'choices')
|
||||
|
|
7
test/choices.ink
Normal file
7
test/choices.ink
Normal file
|
@ -0,0 +1,7 @@
|
|||
"What that's?" my master asked.
|
||||
* "I am somewhat tired[."]," I repeated.
|
||||
"Really," he responded. "How deleterious."
|
||||
* "Nothing, Monsieur!"[] I replied.
|
||||
"Very good, then."
|
||||
* "I said, this journey is appalling[."] and I want no more of it."
|
||||
"Ah," he replied, not unkindly. "I see you are feeling frustrated. Tomorrow, things will improve."
|
14
test/content.ink
Normal file
14
test/content.ink
Normal file
|
@ -0,0 +1,14 @@
|
|||
Hello, world!
|
||||
Hello?
|
||||
Hello, are you there?
|
||||
TODO: Write this section properly!
|
||||
|
||||
"What do you make of this?" she asked.
|
||||
|
||||
// Something unprintable...
|
||||
|
||||
"I couldn't possibly comment," I replied.
|
||||
|
||||
/*
|
||||
... or an unlimited block of text
|
||||
*/
|
27
util.lua
27
util.lua
|
@ -34,3 +34,30 @@ function to_string( tbl )
|
|||
return tostring(tbl)
|
||||
end
|
||||
end
|
||||
|
||||
function tprint (tbl, indent)
|
||||
if not indent then indent = 0 end
|
||||
for k, v in pairs(tbl) do
|
||||
formatting = string.rep(" ", indent) .. k .. ": "
|
||||
if type(v) == "table" then
|
||||
print(formatting)
|
||||
tprint(v, indent+1)
|
||||
elseif type(v) == 'boolean' then
|
||||
print(formatting .. tostring(v))
|
||||
else
|
||||
print(formatting .. v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function read(file)
|
||||
local f = io.open(file, "rb")
|
||||
local content = f:read("*all")
|
||||
f:close()
|
||||
return content
|
||||
end
|
||||
|
||||
function test(p, file)
|
||||
print ('\n=== '..file..' ===')
|
||||
tprint(p:match(read('test/'..file..'.ink')))
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue