1
0
Fork 0
mirror of https://github.com/Oreolek/ink-instead.git synced 2024-07-04 23:54:44 +03:00
This commit is contained in:
premek 2016-12-02 01:19:13 +01:00
parent 2dadbec183
commit 59b9db2ae0
2 changed files with 8 additions and 21 deletions

19
peg.lua
View file

@ -11,10 +11,9 @@ local id = (lpeg.alpha + '_') * (lpeg.alnum + '_')^0
local addr = C(id) * ('.' * C(id))^-1 local addr = C(id) * ('.' * C(id))^-1
local todo = sp * 'TODO:' * sp * (1-nl)^0 / parserLogger * wh -- TODO log location local todo = sp * 'TODO:' * sp * (1-nl)^0 / parserLogger * wh -- TODO log location
local commOL = sp * '//' * sp * (1-nl)^0 * wh -- TODO comment that does not start at the line beginning 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
-- TODO can contain divert mid sentence
local glue = P('<>')/'glue' *wh local glue = P('<>')/'glue' *wh
@ -31,26 +30,16 @@ local stitchHead = P('=')^1/'stitch' * wh * C(id) * wh * P('=')^0 * wh
--local choiceBlock = Ct(choiceAnswer * para^0) --local choiceBlock = Ct(choiceAnswer * para^0)
--local choices = Ct(choiceBlock^1) --local choices = Ct(choiceBlock^1)
--local statement = * (comm + choices + para) *n
--local prog = ((n * lpeg.Ct((statement*n)^0)) )* -1
--local ink = prog
--test(ink, 'content')
--test(choices, 'choices')
--r=knotted:match('= start ==\nhello\nagain\n-> END')
local ink = P({ local ink = P({
"lines", "lines",
knott = Ct(knotHead * (V'line'-knotHead)^0 * wh), knott = Ct(knotHead * (V'line'-knotHead)^0 * wh),
stitch = Ct(stitchHead * (V'line'-stitchHead)^0 * wh), stitch = Ct(stitchHead * (V'line'-stitchHead)^0 * wh),
stmt = glue + divert + V'knott' + V'stitch', stmt = glue + divert + V'knott' + V'stitch' + comm,
para = Ct(Cc('para') * C((1-nl-V'stmt')^1)*wh),
para = Ct(Cc('para') * C((1-nl-V'stmt')^1)*wh), -- hm
line = V'stmt' + V'para', line = V'stmt' + V'para',
lines = Ct(V'line'^1) lines = Ct(V'line'^1)
}) })

View file

@ -1,9 +1,8 @@
return { return {
ink=[[ ink=[[
we <> we <> /* he
hurr ied asdf
*/ hurr ied-> to_savile_row // comm
<> -> to_savile_row
=== to_savile_row === === to_savile_row ===
@ -18,8 +17,7 @@ stiiii
expected= { expected= {
{"para", "we "}, {"para", "we "},
"glue", "glue",
{"para", "hurr ied "}, {"para", "hurr ied"},
"glue",
{"divert", "to_savile_row"}, {"divert", "to_savile_row"},
{ {
"knot", "knot",