From dde89502da569e263cdcb3a73964c03dba77991e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Reuh=20Fildadut?= Date: Sat, 10 Apr 2021 14:33:32 +0200 Subject: [PATCH] Fix a lot of issues when resuming from a paragraph in a choice or expression block --- README.md | 2 +- anselme.lua | 4 +- interpreter/expression.lua | 2 +- interpreter/interpreter.lua | 57 +++- parser/common.lua | 2 +- parser/expression.lua | 4 +- parser/preparser.lua | 34 +-- test/tests/choice block.lua | 12 +- test/tests/choice function.lua | 10 +- test/tests/choice simple.lua | 6 +- test/tests/commit.lua | 8 +- test/tests/condition decorator.lua | 4 +- test/tests/condition else false.lua | 2 +- test/tests/condition else true.lua | 2 +- test/tests/condition elseif false.lua | 2 +- test/tests/condition elseif true.lua | 2 +- test/tests/condition true.lua | 2 +- test/tests/custom event.lua | 4 +- test/tests/define override.lua | 2 +- test/tests/equality operator.lua | 16 +- test/tests/flush.ans | 8 + test/tests/flush.lua | 38 +++ test/tests/function arg vararg.lua | 4 +- test/tests/function arg.lua | 2 +- test/tests/function args vararg empty.lua | 4 +- test/tests/function args vararg.lua | 4 +- test/tests/function args.lua | 2 +- test/tests/function cycle.lua | 10 +- test/tests/function next.lua | 10 +- test/tests/function random.lua | 10 +- test/tests/function return nested.lua | 4 +- test/tests/function return.lua | 2 +- test/tests/function scope.lua | 2 +- test/tests/function ufcs arg.lua | 4 +- test/tests/function ufcs args.lua | 2 +- test/tests/function vararg empty.lua | 2 +- test/tests/function vararg.lua | 2 +- test/tests/function.lua | 2 +- .../interrupt callback nested paragraph.lua | 6 +- test/tests/interrupt callback nested.lua | 4 +- test/tests/interrupt callback.lua | 4 +- test/tests/interrupt no callback.lua | 2 +- test/tests/nested conditions.ans | 19 ++ test/tests/nested conditions.lua | 27 ++ test/tests/nested flush.ans | 19 ++ test/tests/nested flush.lua | 67 +++++ ...aragraph decorator scope explicit call.lua | 4 +- ...aragraph decorator scope implicit call.lua | 4 +- test/tests/paragraph decorator scope.lua | 2 +- test/tests/paragraph run force.lua | 16 +- test/tests/paragraph run from.lua | 18 +- test/tests/paragraph run.lua | 18 +- test/tests/paragraph.lua | 2 +- ...sume from paragraph with nested choice.ans | 77 ++++++ ...sume from paragraph with nested choice.lua | 256 ++++++++++++++++++ ...e from paragraph with nested condition.ans | 21 ++ ...e from paragraph with nested condition.lua | 38 +++ test/tests/tag decorator empty.lua | 4 +- test/tests/tag decorator nested.lua | 4 +- test/tests/tag decorator.lua | 4 +- test/tests/tag empty.lua | 4 +- test/tests/tag.lua | 4 +- test/tests/text block.lua | 4 +- test/tests/text break.lua | 4 +- test/tests/text format.lua | 2 +- test/tests/text.lua | 2 +- test/tests/unseen line.lua | 10 +- 67 files changed, 762 insertions(+), 173 deletions(-) create mode 100644 test/tests/flush.ans create mode 100644 test/tests/flush.lua create mode 100644 test/tests/nested conditions.ans create mode 100644 test/tests/nested conditions.lua create mode 100644 test/tests/nested flush.ans create mode 100644 test/tests/nested flush.lua create mode 100644 test/tests/resume from paragraph with nested choice.ans create mode 100644 test/tests/resume from paragraph with nested choice.lua create mode 100644 test/tests/resume from paragraph with nested condition.ans create mode 100644 test/tests/resume from paragraph with nested condition.lua diff --git a/README.md b/README.md index e42dab4..6db4c4c 100644 --- a/README.md +++ b/README.md @@ -139,7 +139,7 @@ There's different types of lines, depending on their first character(s) (after i * `~`: expression line. Can be followed by an [expression](#expressions); otherwise the expression `1` is assumed. If the expression evaluates to [true](#truethness), run its children. -* `~~`: else expression. Same as an expression line, but is only run if the last expression or else-expression line was false (regardless of line distance). +* `~~`: else expression. Same as an expression line, but is only run if the last expression or else-expression line (in the same indentation block) was false (regardless of line distance). ``` ~ 1 diff --git a/anselme.lua b/anselme.lua index 400ae60..3956122 100644 --- a/anselme.lua +++ b/anselme.lua @@ -335,6 +335,8 @@ local vm_mt = { -- events event_type = nil, event_buffer = nil, + -- skip next choices until next event change (to skip currently running choice block when resuming from a paragraph) + skip_choices_until_flush = nil, -- status running_line = nil, -- choice @@ -342,8 +344,6 @@ local vm_mt = { choice_available = {}, -- interrupt interrupt = nil, - -- conditions - last_condition_success = nil, -- tags tags = tags or {}, } diff --git a/interpreter/expression.lua b/interpreter/expression.lua index f94956c..17069ff 100644 --- a/interpreter/expression.lua +++ b/interpreter/expression.lua @@ -97,7 +97,7 @@ local function eval(state, exp) if fn.value.type == "paragraph" or fn.value.paragraph then local r, e if fn.value.type == "paragraph" then - r, e = run_block(state, fn.value.child, false) + r, e = run_block(state, fn.value.child) if e then return r, e end state.variables[fn.value.namespace.."๐Ÿ‘๏ธ"] = { type = "number", diff --git a/interpreter/interpreter.lua b/interpreter/interpreter.lua index 17ba30a..c521f46 100644 --- a/interpreter/interpreter.lua +++ b/interpreter/interpreter.lua @@ -51,23 +51,29 @@ local function run_line(state, line) if not v then return v, ("%s; in tag decorator at %s"):format(e, line.source) end tags:push(state, v) end + -- if line intend to push an event, flush buffer it it's a different event + if line.push_event and state.interpreter.event_buffer and state.interpreter.event_type ~= line.push_event then + local v, e = run_line(state, { source = line.source, type = "flush_events" }) + if e then return v, e end + if v then return v end + end -- line types if line.type == "condition" then - state.interpreter.last_condition_success = nil + line.parent_block.last_condition_success = nil local v, e = eval(state, line.expression) if not v then return v, ("%s; at %s"):format(e, line.source) end if truthy(v) then - state.interpreter.last_condition_success = true + line.parent_block.last_condition_success = true v, e = run_block(state, line.child) if e then return v, e end if v then return v end end elseif line.type == "else-condition" then - if not state.interpreter.last_condition_success then + if not line.parent_block.last_condition_success then local v, e = eval(state, line.expression) if not v then return v, ("%s; at %s"):format(e, line.source) end if truthy(v) then - state.interpreter.last_condition_success = true + line.parent_block.last_condition_success = true v, e = run_block(state, line.child) if e then return v, e end if v then return v end @@ -146,19 +152,40 @@ end -- returns var in case of success and there is a return -- return nil in case of success and there is no return -- return nil, err in case of error -run_block = function(state, block, run_whole_function, i, j) +run_block = function(state, block, resume_from_there, i, j) i = i or 1 - local len = math.min(#block, j or math.huge) - while i <= len do - local v, e = run_line(state, block[i]) - if e then return v, e end - if v then return v end + local max = math.min(#block, j or math.huge) + while i <= max do + local line = block[i] + local skip = false + -- skip current choice block if enabled + if state.interpreter.skip_choices_until_flush then + if line.type == "choice" then + skip = true + elseif line.type == "flush_events" or (line.push_event and line.push_event ~= "choice") then + state.interpreter.skip_choices_until_flush = nil + end + end + -- run line + if not skip then + local v, e = run_line(state, line) + if e then return v, e end + if v then return v end + end i = i + 1 end - -- go up hierarchy if asked to run the whole function - if run_whole_function and block.parent_line and block.parent_line.type ~= "function" then + -- go up hierarchy if asked to resume + -- will stop at function boundary + -- if parent is a choice, will ignore choices that belong to the same block (like the whole block was executed naturally from a higher parent) + -- if parent if a condition, will mark it as a success (skipping following else-conditions) (for the same reasons as for choices) + if resume_from_there and block.parent_line and block.parent_line.type ~= "function" then local parent_line = block.parent_line - local v, e = run_block(state, parent_line.parent_block, run_whole_function, parent_line.parent_position+1) + if parent_line.type == "choice" then + state.interpreter.skip_choices_until_flush = true + elseif parent_line.type == "condition" or parent_line.type == "else-condition" then + parent_line.parent_block.last_condition_success = true + end + local v, e = run_block(state, parent_line.parent_block, resume_from_there, parent_line.parent_position+1) if e then return v, e end if v then return v, e end end @@ -167,9 +194,9 @@ end -- returns var in case of success -- return nil, err in case of error -local function run(state, block, run_whole_function, i, j) +local function run(state, block, resume_from_there, i, j) -- run - local v, e = run_block(state, block, run_whole_function, i, j) + local v, e = run_block(state, block, resume_from_there, i, j) if e then return v, e end if v then return v diff --git a/parser/common.lua b/parser/common.lua index 2dd5286..00b4d89 100644 --- a/parser/common.lua +++ b/parser/common.lua @@ -59,7 +59,7 @@ common = { return nil, ("can't find %q in namespace %s"):format(name, namespace) end, --- transform an identifier into a clean version (trim each part) - format_identifier = function(identifier, state) + format_identifier = function(identifier) local r = identifier:gsub("[^%.]+", function(str) return common.trim(str) end) diff --git a/parser/expression.lua b/parser/expression.lua index 67151e7..5d41680 100644 --- a/parser/expression.lua +++ b/parser/expression.lua @@ -90,7 +90,7 @@ local function expression(s, state, namespace, currentPriority, operatingOn) -- identifier elseif s:match("^"..identifier_pattern) then local name, r = s:match("^("..identifier_pattern..")(.-)$") - name = format_identifier(name, state) + name = format_identifier(name) -- variables local var, vfqm = find(state.aliases, state.variables, namespace, name) if var then @@ -161,7 +161,7 @@ local function expression(s, state, namespace, currentPriority, operatingOn) -- suffix call if op == "." and sright:match("^"..identifier_pattern) then local name, r = sright:match("^("..identifier_pattern..")(.-)$") - name = format_identifier(name, state) + name = format_identifier(name) local funcs, ffqm = find(state.aliases, state.functions, namespace, name) if funcs then local args, explicit_call diff --git a/parser/preparser.lua b/parser/preparser.lua index e2ce73e..6659d60 100644 --- a/parser/preparser.lua +++ b/parser/preparser.lua @@ -30,7 +30,7 @@ local function parse_line(line, state, namespace) local identifier, rem = name:match("^("..identifier_pattern..")(.-)$") if not identifier then return nil, ("no valid identifier in paragraph decorator %q; at %s"):format(identifier, line.source) end -- format identifier - local fqm = ("%s%s"):format(namespace, format_identifier(identifier, state)) + local fqm = ("%s%s"):format(namespace, format_identifier(identifier)) -- get alias if rem:match("^%:") then local content = rem:sub(2) @@ -38,7 +38,7 @@ local function parse_line(line, state, namespace) if not alias then return nil, ("expected an identifier in alias in paragraph decorator, but got %q; at %s"):format(content, line.source) end if rem2:match("[^%s]") then return nil, ("expected end-of-line after identifier in alias in paragraph decorator, but got %q; at %s"):format(rem2, line.source) end -- format alias - local aliasfqm = ("%s%s"):format(namespace, format_identifier(alias, state)) + local aliasfqm = ("%s%s"):format(namespace, format_identifier(alias)) -- define alias if state.aliases[aliasfqm] ~= nil and state.aliases[aliasfqm] ~= fqm then return nil, ("trying to define alias %q for variable %q, but already exist and refer to different variable %q; at %s"):format(aliasfqm, fqm, state.aliases[aliasfqm], line.source) @@ -113,7 +113,7 @@ local function parse_line(line, state, namespace) local identifier, rem = lc:match("^("..identifier_pattern..")(.-)$") if not identifier then return nil, ("no valid identifier in paragraph/function definition line %q; at %s"):format(lc, line.source) end -- format identifier - local fqm = ("%s%s"):format(namespace, format_identifier(identifier, state)) + local fqm = ("%s%s"):format(namespace, format_identifier(identifier)) -- get alias if rem:match("^%:") then local content = rem:sub(2) @@ -121,7 +121,7 @@ local function parse_line(line, state, namespace) alias, rem = content:match("^("..identifier_pattern..")(.-)$") if not alias then return nil, ("expected an identifier in alias in paragraph/function definition line, but got %q; at %s"):format(content, line.source) end -- format alias - local aliasfqm = ("%s%s"):format(namespace, format_identifier(alias, state)) + local aliasfqm = ("%s%s"):format(namespace, format_identifier(alias)) -- define alias if state.aliases[aliasfqm] ~= nil and state.aliases[aliasfqm] ~= fqm then return nil, ("trying to define alias %q for function/paragraph %q, but already exist and refer to %q; at %s"):format(aliasfqm, fqm, state.aliases[aliasfqm], line.source) @@ -137,7 +137,7 @@ local function parse_line(line, state, namespace) local param_identifier, param_rem = param:match("^("..identifier_pattern..")(.-)$") if not identifier then return nil, ("no valid identifier in function parameter %q; at %s"):format(param, line.source) end -- format identifier - local param_fqm = ("%s.%s"):format(fqm, format_identifier(param_identifier, state)) + local param_fqm = ("%s.%s"):format(fqm, format_identifier(param_identifier)) -- get alias if param_rem:match("^%:") then local param_content = param_rem:sub(2) @@ -145,7 +145,7 @@ local function parse_line(line, state, namespace) alias, param_rem = param_content:match("^("..identifier_pattern..")(.-)$") if not alias then return nil, ("expected an identifier in alias in parameter, but got %q; at %s"):format(param_content, line.source) end -- format alias - local aliasfqm = ("%s.%s"):format(fqm, format_identifier(alias, state)) + local aliasfqm = ("%s.%s"):format(fqm, format_identifier(alias)) -- define alias if state.aliases[aliasfqm] ~= nil and state.aliases[aliasfqm] ~= param_fqm then return nil, ("trying to define alias %q for parameter %q, but already exist and refer to %q; at %s"):format(aliasfqm, param_fqm, state.aliases[aliasfqm], line.source) @@ -268,7 +268,7 @@ local function parse_line(line, state, namespace) local identifier, rem2 = rem:match("^("..identifier_pattern..")(.-)$") if not identifier then return nil, ("no valid identifier after expression in definition line %q; at %s"):format(rem, line.source) end -- format identifier - local fqm = ("%s%s"):format(namespace, format_identifier(identifier, state)) + local fqm = ("%s%s"):format(namespace, format_identifier(identifier)) -- get alias if rem2:match("^%:") then local content = rem2:sub(2) @@ -276,7 +276,7 @@ local function parse_line(line, state, namespace) if not alias then return nil, ("expected an identifier in alias in definition line, but got %q; at %s"):format(content, line.source) end if rem3:match("[^%s]") then return nil, ("expected end-of-line after identifier in alias in definition line, but got %q; at %s"):format(rem3, line.source) end -- format alias - local aliasfqm = ("%s%s"):format(namespace, format_identifier(alias, state)) + local aliasfqm = ("%s%s"):format(namespace, format_identifier(alias)) -- define alias if state.aliases[aliasfqm] ~= nil and state.aliases[aliasfqm] ~= fqm then return nil, ("trying to define alias %s for variable %s, but already exist and refer to different variable %s; at %s"):format(aliasfqm, fqm, state.aliases[aliasfqm], line.source) @@ -324,7 +324,7 @@ end -- * block: in case of success -- * nil, err: in case of error -local function parse_block(indented, state, namespace, parent_function, last_event) +local function parse_block(indented, state, namespace, parent_function) local block = { type = "block" } local lastLine -- last line AST for i, l in ipairs(indented) do @@ -338,14 +338,6 @@ local function parse_block(indented, state, namespace, parent_function, last_eve -- add to block AST if not ast.remove_from_block_ast then ast.parent_block = block - -- insert flush on event type change - if ast.type == "flush" then last_event = nil end - if ast.push_event then - if last_event and ast.push_event ~= last_event then - table.insert(block, { source = l.source, type = "flush_events" }) - end - last_event = ast.push_event - end -- add ast node ast.parent_position = #block+1 if ast.replace_with then @@ -367,7 +359,7 @@ local function parse_block(indented, state, namespace, parent_function, last_eve if not lastLine.child then return nil, ("line %s (%s) can't have children"):format(lastLine.source, lastLine.type) else - local r, e = parse_block(l, state, lastLine.namespace or namespace, lastLine.type == "function" and lastLine or parent_function, last_event) + local r, e = parse_block(l, state, lastLine.namespace or namespace, lastLine.type == "function" and lastLine or parent_function) if not r then return r, e end r.parent_line = lastLine lastLine.child = r @@ -395,17 +387,17 @@ local function parse_indent(lines, source, i, indentLevel, insert_empty_line) table.insert(indented, { content = line, source = ("%s:%s"):format(source, i) }) elseif #indent > indentLevel then local t - t, i = parse_indent(lines, source, i, #indent, insert_empty_line) + t, i, insert_empty_line = parse_indent(lines, source, i, #indent, insert_empty_line) table.insert(indented, t) else - return indented, i-1 + return indented, i-1, insert_empty_line end elseif not insert_empty_line then insert_empty_line = i end i = i + 1 end - return indented, i-1 + return indented, i-1, insert_empty_line end --- return the list of raw lines of s diff --git a/test/tests/choice block.lua b/test/tests/choice block.lua index f2759da..3600536 100644 --- a/test/tests/choice block.lua +++ b/test/tests/choice block.lua @@ -5,12 +5,12 @@ _[19]={} _[18]={} _[17]={} _[16]={} -_[15]={tags=_[21],data="plop"} -_[14]={tags=_[20],data="oh"} -_[13]={tags=_[19],data="ho"} -_[12]={tags=_[18],data="ok"} -_[11]={tags=_[17],data="ne"} -_[10]={tags=_[16],data="ye"} +_[15]={data="plop",tags=_[21]} +_[14]={data="oh",tags=_[20]} +_[13]={data="ho",tags=_[19]} +_[12]={data="ok",tags=_[18]} +_[11]={data="ne",tags=_[17]} +_[10]={data="ye",tags=_[16]} _[9]={_[15]} _[8]={_[13],_[14]} _[7]={_[12]} diff --git a/test/tests/choice function.lua b/test/tests/choice function.lua index d99f3e1..315354d 100644 --- a/test/tests/choice function.lua +++ b/test/tests/choice function.lua @@ -4,11 +4,11 @@ _[14]={} _[13]={} _[12]={} _[11]={} -_[10]={tags=_[15],data="ok"} -_[9]={tags=_[14],data="neol"} -_[8]={tags=_[13],data="oh"} -_[7]={tags=_[12],data="neol"} -_[6]={tags=_[11],data="ho"} +_[10]={data="ok",tags=_[15]} +_[9]={data="neol",tags=_[14]} +_[8]={data="oh",tags=_[13]} +_[7]={data="neol",tags=_[12]} +_[6]={data="ho",tags=_[11]} _[5]={_[10]} _[4]={_[6],_[7],_[8],_[9]} _[3]={"return"} diff --git a/test/tests/choice simple.lua b/test/tests/choice simple.lua index 133048b..ee55413 100644 --- a/test/tests/choice simple.lua +++ b/test/tests/choice simple.lua @@ -2,9 +2,9 @@ local _={} _[11]={} _[10]={} _[9]={} -_[8]={tags=_[11],data="ok"} -_[7]={tags=_[10],data="ne"} -_[6]={tags=_[9],data="ye"} +_[8]={data="ok",tags=_[11]} +_[7]={data="ne",tags=_[10]} +_[6]={data="ye",tags=_[9]} _[5]={_[8]} _[4]={_[6],_[7]} _[3]={"return"} diff --git a/test/tests/commit.lua b/test/tests/commit.lua index 821bb9f..0fe975a 100644 --- a/test/tests/commit.lua +++ b/test/tests/commit.lua @@ -3,10 +3,10 @@ _[17]={} _[16]={} _[15]={} _[14]={} -_[13]={tags=_[17],data="parallel: 2"} -_[12]={tags=_[16],data="after: 2"} -_[11]={tags=_[15],data="parallel: 5"} -_[10]={tags=_[14],data="before: 2"} +_[13]={data="parallel: 2",tags=_[17]} +_[12]={data="after: 2",tags=_[16]} +_[11]={data="parallel: 5",tags=_[15]} +_[10]={data="before: 2",tags=_[14]} _[9]={_[13]} _[8]={_[12]} _[7]={_[11]} diff --git a/test/tests/condition decorator.lua b/test/tests/condition decorator.lua index 6a5f16d..f5f9a03 100644 --- a/test/tests/condition decorator.lua +++ b/test/tests/condition decorator.lua @@ -1,8 +1,8 @@ local _={} _[7]={} _[6]={} -_[5]={tags=_[7],data="ok bis"} -_[4]={tags=_[6],data="ok"} +_[5]={data="ok bis",tags=_[7]} +_[4]={data="ok",tags=_[6]} _[3]={_[4],_[5]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/condition else false.lua b/test/tests/condition else false.lua index 1243028..c75476f 100644 --- a/test/tests/condition else false.lua +++ b/test/tests/condition else false.lua @@ -1,6 +1,6 @@ local _={} _[5]={} -_[4]={tags=_[5],data="ok"} +_[4]={data="ok",tags=_[5]} _[3]={_[4]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/condition else true.lua b/test/tests/condition else true.lua index 1243028..c75476f 100644 --- a/test/tests/condition else true.lua +++ b/test/tests/condition else true.lua @@ -1,6 +1,6 @@ local _={} _[5]={} -_[4]={tags=_[5],data="ok"} +_[4]={data="ok",tags=_[5]} _[3]={_[4]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/condition elseif false.lua b/test/tests/condition elseif false.lua index 1243028..c75476f 100644 --- a/test/tests/condition elseif false.lua +++ b/test/tests/condition elseif false.lua @@ -1,6 +1,6 @@ local _={} _[5]={} -_[4]={tags=_[5],data="ok"} +_[4]={data="ok",tags=_[5]} _[3]={_[4]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/condition elseif true.lua b/test/tests/condition elseif true.lua index 1243028..c75476f 100644 --- a/test/tests/condition elseif true.lua +++ b/test/tests/condition elseif true.lua @@ -1,6 +1,6 @@ local _={} _[5]={} -_[4]={tags=_[5],data="ok"} +_[4]={data="ok",tags=_[5]} _[3]={_[4]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/condition true.lua b/test/tests/condition true.lua index 1243028..c75476f 100644 --- a/test/tests/condition true.lua +++ b/test/tests/condition true.lua @@ -1,6 +1,6 @@ local _={} _[5]={} -_[4]={tags=_[5],data="ok"} +_[4]={data="ok",tags=_[5]} _[3]={_[4]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/custom event.lua b/test/tests/custom event.lua index 68bc268..88ec1ce 100644 --- a/test/tests/custom event.lua +++ b/test/tests/custom event.lua @@ -1,8 +1,8 @@ local _={} _[8]={} _[7]={} -_[6]={tags=_[8],data="ho"} -_[5]={tags=_[7],data="ah"} +_[6]={data="ho",tags=_[8]} +_[5]={data="ah",tags=_[7]} _[4]={_[5],_[6]} _[3]={"return"} _[2]={"text",_[4]} diff --git a/test/tests/define override.lua b/test/tests/define override.lua index c5653d1..ab7c161 100644 --- a/test/tests/define override.lua +++ b/test/tests/define override.lua @@ -1,6 +1,6 @@ local _={} _[5]={} -_[4]={tags=_[5],data="a: 5"} +_[4]={data="a: 5",tags=_[5]} _[3]={_[4]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/equality operator.lua b/test/tests/equality operator.lua index b493824..d4c3d0d 100644 --- a/test/tests/equality operator.lua +++ b/test/tests/equality operator.lua @@ -7,14 +7,14 @@ _[29]={} _[28]={} _[27]={} _[26]={} -_[25]={tags=_[33],data="1 = 1"} -_[24]={tags=_[32],data="0 = 0"} -_[23]={tags=_[31],data="0 = 0"} -_[22]={tags=_[30],data="0 = 0"} -_[21]={tags=_[29],data="0 = 0"} -_[20]={tags=_[28],data="1 = 1"} -_[19]={tags=_[27],data="0 = 0"} -_[18]={tags=_[26],data="0 = 0"} +_[25]={data="1 = 1",tags=_[33]} +_[24]={data="0 = 0",tags=_[32]} +_[23]={data="0 = 0",tags=_[31]} +_[22]={data="0 = 0",tags=_[30]} +_[21]={data="0 = 0",tags=_[29]} +_[20]={data="1 = 1",tags=_[28]} +_[19]={data="0 = 0",tags=_[27]} +_[18]={data="0 = 0",tags=_[26]} _[17]={_[25]} _[16]={_[24]} _[15]={_[23]} diff --git a/test/tests/flush.ans b/test/tests/flush.ans new file mode 100644 index 0000000..a2c72c9 --- /dev/null +++ b/test/tests/flush.ans @@ -0,0 +1,8 @@ +a + +> b +~ choose(1) + +c +> d +~ choose(1) diff --git a/test/tests/flush.lua b/test/tests/flush.lua new file mode 100644 index 0000000..8add63e --- /dev/null +++ b/test/tests/flush.lua @@ -0,0 +1,38 @@ +local _={} +_[17]={} +_[16]={} +_[15]={} +_[14]={} +_[13]={data="d",tags=_[17]} +_[12]={data="c",tags=_[16]} +_[11]={data="b",tags=_[15]} +_[10]={data="a",tags=_[14]} +_[9]={_[13]} +_[8]={_[12]} +_[7]={_[11]} +_[6]={_[10]} +_[5]={"return"} +_[4]={"choice",_[9]} +_[3]={"text",_[8]} +_[2]={"choice",_[7]} +_[1]={"text",_[6]} +return {_[1],_[2],_[3],_[4],_[5]} +--[[ +{ "text", { { + data = "a", + tags = {} + } } } +{ "choice", { { + data = "b", + tags = {} + } } } +{ "text", { { + data = "c", + tags = {} + } } } +{ "choice", { { + data = "d", + tags = {} + } } } +{ "return" } +]]-- \ No newline at end of file diff --git a/test/tests/function arg vararg.lua b/test/tests/function arg vararg.lua index 898276b..763d91a 100644 --- a/test/tests/function arg vararg.lua +++ b/test/tests/function arg vararg.lua @@ -1,8 +1,8 @@ local _={} _[7]={} _[6]={} -_[5]={tags=_[7],data="[o, k]"} -_[4]={tags=_[6],data="ok"} +_[5]={data="[o, k]",tags=_[7]} +_[4]={data="ok",tags=_[6]} _[3]={_[4],_[5]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/function arg.lua b/test/tests/function arg.lua index 1243028..c75476f 100644 --- a/test/tests/function arg.lua +++ b/test/tests/function arg.lua @@ -1,6 +1,6 @@ local _={} _[5]={} -_[4]={tags=_[5],data="ok"} +_[4]={data="ok",tags=_[5]} _[3]={_[4]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/function args vararg empty.lua b/test/tests/function args vararg empty.lua index a195e2e..fc7ecbe 100644 --- a/test/tests/function args vararg empty.lua +++ b/test/tests/function args vararg empty.lua @@ -1,8 +1,8 @@ local _={} _[7]={} _[6]={} -_[5]={tags=_[7],data="[]"} -_[4]={tags=_[6],data="ok"} +_[5]={data="[]",tags=_[7]} +_[4]={data="ok",tags=_[6]} _[3]={_[4],_[5]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/function args vararg.lua b/test/tests/function args vararg.lua index 898276b..763d91a 100644 --- a/test/tests/function args vararg.lua +++ b/test/tests/function args vararg.lua @@ -1,8 +1,8 @@ local _={} _[7]={} _[6]={} -_[5]={tags=_[7],data="[o, k]"} -_[4]={tags=_[6],data="ok"} +_[5]={data="[o, k]",tags=_[7]} +_[4]={data="ok",tags=_[6]} _[3]={_[4],_[5]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/function args.lua b/test/tests/function args.lua index 1243028..c75476f 100644 --- a/test/tests/function args.lua +++ b/test/tests/function args.lua @@ -1,6 +1,6 @@ local _={} _[5]={} -_[4]={tags=_[5],data="ok"} +_[4]={data="ok",tags=_[5]} _[3]={_[4]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/function cycle.lua b/test/tests/function cycle.lua index dc573ad..f4a5748 100644 --- a/test/tests/function cycle.lua +++ b/test/tests/function cycle.lua @@ -4,11 +4,11 @@ _[20]={} _[19]={} _[18]={} _[17]={} -_[16]={tags=_[21],data="b"} -_[15]={tags=_[20],data="a"} -_[14]={tags=_[19],data="c"} -_[13]={tags=_[18],data="b"} -_[12]={tags=_[17],data="a"} +_[16]={data="b",tags=_[21]} +_[15]={data="a",tags=_[20]} +_[14]={data="c",tags=_[19]} +_[13]={data="b",tags=_[18]} +_[12]={data="a",tags=_[17]} _[11]={_[16]} _[10]={_[15]} _[9]={_[14]} diff --git a/test/tests/function next.lua b/test/tests/function next.lua index 05e6015..5574217 100644 --- a/test/tests/function next.lua +++ b/test/tests/function next.lua @@ -4,11 +4,11 @@ _[20]={} _[19]={} _[18]={} _[17]={} -_[16]={tags=_[21],data="c"} -_[15]={tags=_[20],data="c"} -_[14]={tags=_[19],data="c"} -_[13]={tags=_[18],data="b"} -_[12]={tags=_[17],data="a"} +_[16]={data="c",tags=_[21]} +_[15]={data="c",tags=_[20]} +_[14]={data="c",tags=_[19]} +_[13]={data="b",tags=_[18]} +_[12]={data="a",tags=_[17]} _[11]={_[16]} _[10]={_[15]} _[9]={_[14]} diff --git a/test/tests/function random.lua b/test/tests/function random.lua index d0e0f2b..a029213 100644 --- a/test/tests/function random.lua +++ b/test/tests/function random.lua @@ -4,11 +4,11 @@ _[20]={} _[19]={} _[18]={} _[17]={} -_[16]={tags=_[21],data="a"} -_[15]={tags=_[20],data="a"} -_[14]={tags=_[19],data="b"} -_[13]={tags=_[18],data="a"} -_[12]={tags=_[17],data="b"} +_[16]={data="a",tags=_[21]} +_[15]={data="a",tags=_[20]} +_[14]={data="b",tags=_[19]} +_[13]={data="a",tags=_[18]} +_[12]={data="b",tags=_[17]} _[11]={_[16]} _[10]={_[15]} _[9]={_[14]} diff --git a/test/tests/function return nested.lua b/test/tests/function return nested.lua index 3373cd9..baedcdc 100644 --- a/test/tests/function return nested.lua +++ b/test/tests/function return nested.lua @@ -1,8 +1,8 @@ local _={} _[7]={} _[6]={} -_[5]={tags=_[7],data="2"} -_[4]={tags=_[6],data="5"} +_[5]={data="2",tags=_[7]} +_[4]={data="5",tags=_[6]} _[3]={_[4],_[5]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/function return.lua b/test/tests/function return.lua index 1cfd3c9..9d39b3d 100644 --- a/test/tests/function return.lua +++ b/test/tests/function return.lua @@ -1,6 +1,6 @@ local _={} _[5]={} -_[4]={tags=_[5],data="5"} +_[4]={data="5",tags=_[5]} _[3]={_[4]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/function scope.lua b/test/tests/function scope.lua index c5653d1..ab7c161 100644 --- a/test/tests/function scope.lua +++ b/test/tests/function scope.lua @@ -1,6 +1,6 @@ local _={} _[5]={} -_[4]={tags=_[5],data="a: 5"} +_[4]={data="a: 5",tags=_[5]} _[3]={_[4]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/function ufcs arg.lua b/test/tests/function ufcs arg.lua index 92dc1c1..b6c0803 100644 --- a/test/tests/function ufcs arg.lua +++ b/test/tests/function ufcs arg.lua @@ -1,8 +1,8 @@ local _={} _[9]={} _[8]={} -_[7]={tags=_[9],data="ok"} -_[6]={tags=_[8],data="ok"} +_[7]={data="ok",tags=_[9]} +_[6]={data="ok",tags=_[8]} _[5]={_[7]} _[4]={_[6]} _[3]={"return"} diff --git a/test/tests/function ufcs args.lua b/test/tests/function ufcs args.lua index 1243028..c75476f 100644 --- a/test/tests/function ufcs args.lua +++ b/test/tests/function ufcs args.lua @@ -1,6 +1,6 @@ local _={} _[5]={} -_[4]={tags=_[5],data="ok"} +_[4]={data="ok",tags=_[5]} _[3]={_[4]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/function vararg empty.lua b/test/tests/function vararg empty.lua index 4131fec..25ed63e 100644 --- a/test/tests/function vararg empty.lua +++ b/test/tests/function vararg empty.lua @@ -1,6 +1,6 @@ local _={} _[5]={} -_[4]={tags=_[5],data="[]"} +_[4]={data="[]",tags=_[5]} _[3]={_[4]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/function vararg.lua b/test/tests/function vararg.lua index 0d0116e..4b57911 100644 --- a/test/tests/function vararg.lua +++ b/test/tests/function vararg.lua @@ -1,6 +1,6 @@ local _={} _[5]={} -_[4]={tags=_[5],data="[o, k]"} +_[4]={data="[o, k]",tags=_[5]} _[3]={_[4]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/function.lua b/test/tests/function.lua index 1243028..c75476f 100644 --- a/test/tests/function.lua +++ b/test/tests/function.lua @@ -1,6 +1,6 @@ local _={} _[5]={} -_[4]={tags=_[5],data="ok"} +_[4]={data="ok",tags=_[5]} _[3]={_[4]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/interrupt callback nested paragraph.lua b/test/tests/interrupt callback nested paragraph.lua index 00fb3a4..35ff609 100644 --- a/test/tests/interrupt callback nested paragraph.lua +++ b/test/tests/interrupt callback nested paragraph.lua @@ -2,9 +2,9 @@ local _={} _[12]={} _[11]={} _[10]={} -_[9]={tags=_[12],data="no"} -_[8]={tags=_[11],data="in interrupt: 5"} -_[7]={tags=_[10],data="before: 2"} +_[9]={data="no",tags=_[12]} +_[8]={data="in interrupt: 5",tags=_[11]} +_[7]={data="before: 2",tags=_[10]} _[6]={_[8],_[9]} _[5]={_[7]} _[4]={"return"} diff --git a/test/tests/interrupt callback nested.lua b/test/tests/interrupt callback nested.lua index 6000689..0a29f65 100644 --- a/test/tests/interrupt callback nested.lua +++ b/test/tests/interrupt callback nested.lua @@ -1,8 +1,8 @@ local _={} _[10]={} _[9]={} -_[8]={tags=_[10],data="in interrupt: 5"} -_[7]={tags=_[9],data="before: 2"} +_[8]={data="in interrupt: 5",tags=_[10]} +_[7]={data="before: 2",tags=_[9]} _[6]={_[8]} _[5]={_[7]} _[4]={"return"} diff --git a/test/tests/interrupt callback.lua b/test/tests/interrupt callback.lua index 6000689..0a29f65 100644 --- a/test/tests/interrupt callback.lua +++ b/test/tests/interrupt callback.lua @@ -1,8 +1,8 @@ local _={} _[10]={} _[9]={} -_[8]={tags=_[10],data="in interrupt: 5"} -_[7]={tags=_[9],data="before: 2"} +_[8]={data="in interrupt: 5",tags=_[10]} +_[7]={data="before: 2",tags=_[9]} _[6]={_[8]} _[5]={_[7]} _[4]={"return"} diff --git a/test/tests/interrupt no callback.lua b/test/tests/interrupt no callback.lua index 97eafe6..3c4fc54 100644 --- a/test/tests/interrupt no callback.lua +++ b/test/tests/interrupt no callback.lua @@ -1,6 +1,6 @@ local _={} _[6]={} -_[5]={tags=_[6],data="before: 2"} +_[5]={data="before: 2",tags=_[6]} _[4]={_[5]} _[3]={"return",""} _[2]={"wait",0} diff --git a/test/tests/nested conditions.ans b/test/tests/nested conditions.ans new file mode 100644 index 0000000..f9fd285 --- /dev/null +++ b/test/tests/nested conditions.ans @@ -0,0 +1,19 @@ +~ 1 + yes + ~ 0 + no +~~ + nope + ~ 1 + hai + ~ 0 + still no +~~ + nein + +~ 0 + nah +~~ + ye + ~~ + da diff --git a/test/tests/nested conditions.lua b/test/tests/nested conditions.lua new file mode 100644 index 0000000..6dac2cf --- /dev/null +++ b/test/tests/nested conditions.lua @@ -0,0 +1,27 @@ +local _={} +_[11]={} +_[10]={} +_[9]={} +_[8]={data="da",tags=_[11]} +_[7]={data="ye",tags=_[10]} +_[6]={data="yes",tags=_[9]} +_[5]={_[7],_[8]} +_[4]={_[6]} +_[3]={"return"} +_[2]={"text",_[5]} +_[1]={"text",_[4]} +return {_[1],_[2],_[3]} +--[[ +{ "text", { { + data = "yes", + tags = {} + } } } +{ "text", { { + data = "ye", + tags = {} + }, { + data = "da", + tags = {} + } } } +{ "return" } +]]-- \ No newline at end of file diff --git a/test/tests/nested flush.ans b/test/tests/nested flush.ans new file mode 100644 index 0000000..31e94e4 --- /dev/null +++ b/test/tests/nested flush.ans @@ -0,0 +1,19 @@ +~ 1 + a + +b + +~ 1 + c +d + +~ 1 + e + +> f +~ choose(1) + +~ 1 + g +> h +~ choose(1) diff --git a/test/tests/nested flush.lua b/test/tests/nested flush.lua new file mode 100644 index 0000000..ac73894 --- /dev/null +++ b/test/tests/nested flush.lua @@ -0,0 +1,67 @@ +local _={} +_[31]={} +_[30]={} +_[29]={} +_[28]={} +_[27]={} +_[26]={} +_[25]={} +_[24]={} +_[23]={data="h",tags=_[31]} +_[22]={data="g",tags=_[30]} +_[21]={data="f",tags=_[29]} +_[20]={data="e",tags=_[28]} +_[19]={data="d",tags=_[27]} +_[18]={data="c",tags=_[26]} +_[17]={data="b",tags=_[25]} +_[16]={data="a",tags=_[24]} +_[15]={_[23]} +_[14]={_[22]} +_[13]={_[21]} +_[12]={_[20]} +_[11]={_[18],_[19]} +_[10]={_[17]} +_[9]={_[16]} +_[8]={"return"} +_[7]={"choice",_[15]} +_[6]={"text",_[14]} +_[5]={"choice",_[13]} +_[4]={"text",_[12]} +_[3]={"text",_[11]} +_[2]={"text",_[10]} +_[1]={"text",_[9]} +return {_[1],_[2],_[3],_[4],_[5],_[6],_[7],_[8]} +--[[ +{ "text", { { + data = "a", + tags = {} + } } } +{ "text", { { + data = "b", + tags = {} + } } } +{ "text", { { + data = "c", + tags = {} + }, { + data = "d", + tags = {} + } } } +{ "text", { { + data = "e", + tags = {} + } } } +{ "choice", { { + data = "f", + tags = {} + } } } +{ "text", { { + data = "g", + tags = {} + } } } +{ "choice", { { + data = "h", + tags = {} + } } } +{ "return" } +]]-- \ No newline at end of file diff --git a/test/tests/paragraph decorator scope explicit call.lua b/test/tests/paragraph decorator scope explicit call.lua index 92b05dc..f4169f2 100644 --- a/test/tests/paragraph decorator scope explicit call.lua +++ b/test/tests/paragraph decorator scope explicit call.lua @@ -1,8 +1,8 @@ local _={} _[9]={} _[8]={} -_[7]={tags=_[9],data="a.\240\159\145\129\239\184\143: 1"} -_[6]={tags=_[8],data="a.\240\159\145\129\239\184\143: 0"} +_[7]={data="a.\240\159\145\129\239\184\143: 1",tags=_[9]} +_[6]={data="a.\240\159\145\129\239\184\143: 0",tags=_[8]} _[5]={_[7]} _[4]={_[6]} _[3]={"return"} diff --git a/test/tests/paragraph decorator scope implicit call.lua b/test/tests/paragraph decorator scope implicit call.lua index cdf0f8f..662b7a5 100644 --- a/test/tests/paragraph decorator scope implicit call.lua +++ b/test/tests/paragraph decorator scope implicit call.lua @@ -1,8 +1,8 @@ local _={} _[7]={} _[6]={} -_[5]={tags=_[7],data="ok"} -_[4]={tags=_[6],data="a.\240\159\145\129\239\184\143: 0"} +_[5]={data="ok",tags=_[7]} +_[4]={data="a.\240\159\145\129\239\184\143: 0",tags=_[6]} _[3]={_[4],_[5]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/paragraph decorator scope.lua b/test/tests/paragraph decorator scope.lua index 94aae53..514bf2c 100644 --- a/test/tests/paragraph decorator scope.lua +++ b/test/tests/paragraph decorator scope.lua @@ -1,6 +1,6 @@ local _={} _[5]={} -_[4]={tags=_[5],data="a.\240\159\145\129\239\184\143: 0"} +_[4]={data="a.\240\159\145\129\239\184\143: 0",tags=_[5]} _[3]={_[4]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/paragraph run force.lua b/test/tests/paragraph run force.lua index 383699a..ebfabf4 100644 --- a/test/tests/paragraph run force.lua +++ b/test/tests/paragraph run force.lua @@ -7,14 +7,14 @@ _[19]={} _[18]={} _[17]={} _[16]={} -_[15]={tags=_[23],data="b"} -_[14]={tags=_[22],data="x"} -_[13]={tags=_[21],data="Force no checkpoint:"} -_[12]={tags=_[20],data="b"} -_[11]={tags=_[19],data="a"} -_[10]={tags=_[18],data="From checkpoint:"} -_[9]={tags=_[17],data="a"} -_[8]={tags=_[16],data="Force run checkpoint:"} +_[15]={data="b",tags=_[23]} +_[14]={data="x",tags=_[22]} +_[13]={data="Force no checkpoint:",tags=_[21]} +_[12]={data="b",tags=_[20]} +_[11]={data="a",tags=_[19]} +_[10]={data="From checkpoint:",tags=_[18]} +_[9]={data="a",tags=_[17]} +_[8]={data="Force run checkpoint:",tags=_[16]} _[7]={_[13],_[14],_[15]} _[6]={_[10],_[11],_[12]} _[5]={_[8],_[9]} diff --git a/test/tests/paragraph run from.lua b/test/tests/paragraph run from.lua index e9fcae3..2a60103 100644 --- a/test/tests/paragraph run from.lua +++ b/test/tests/paragraph run from.lua @@ -8,15 +8,15 @@ _[20]={} _[19]={} _[18]={} _[17]={} -_[16]={tags=_[25],data="b"} -_[15]={tags=_[24],data="x"} -_[14]={tags=_[23],data="Force no checkpoint:"} -_[13]={tags=_[22],data="b"} -_[12]={tags=_[21],data="a"} -_[11]={tags=_[20],data="From checkpoint:"} -_[10]={tags=_[19],data="b"} -_[9]={tags=_[18],data="a"} -_[8]={tags=_[17],data="Force run from checkpoint:"} +_[16]={data="b",tags=_[25]} +_[15]={data="x",tags=_[24]} +_[14]={data="Force no checkpoint:",tags=_[23]} +_[13]={data="b",tags=_[22]} +_[12]={data="a",tags=_[21]} +_[11]={data="From checkpoint:",tags=_[20]} +_[10]={data="b",tags=_[19]} +_[9]={data="a",tags=_[18]} +_[8]={data="Force run from checkpoint:",tags=_[17]} _[7]={_[14],_[15],_[16]} _[6]={_[11],_[12],_[13]} _[5]={_[8],_[9],_[10]} diff --git a/test/tests/paragraph run.lua b/test/tests/paragraph run.lua index e941849..1c639b3 100644 --- a/test/tests/paragraph run.lua +++ b/test/tests/paragraph run.lua @@ -8,15 +8,15 @@ _[20]={} _[19]={} _[18]={} _[17]={} -_[16]={tags=_[25],data="b"} -_[15]={tags=_[24],data="x"} -_[14]={tags=_[23],data="Force no checkpoint:"} -_[13]={tags=_[22],data="b"} -_[12]={tags=_[21],data="a"} -_[11]={tags=_[20],data="From checkpoint:"} -_[10]={tags=_[19],data="b"} -_[9]={tags=_[18],data="x"} -_[8]={tags=_[17],data="No checkpoint:"} +_[16]={data="b",tags=_[25]} +_[15]={data="x",tags=_[24]} +_[14]={data="Force no checkpoint:",tags=_[23]} +_[13]={data="b",tags=_[22]} +_[12]={data="a",tags=_[21]} +_[11]={data="From checkpoint:",tags=_[20]} +_[10]={data="b",tags=_[19]} +_[9]={data="x",tags=_[18]} +_[8]={data="No checkpoint:",tags=_[17]} _[7]={_[14],_[15],_[16]} _[6]={_[11],_[12],_[13]} _[5]={_[8],_[9],_[10]} diff --git a/test/tests/paragraph.lua b/test/tests/paragraph.lua index 004133c..b086675 100644 --- a/test/tests/paragraph.lua +++ b/test/tests/paragraph.lua @@ -1,6 +1,6 @@ local _={} _[5]={} -_[4]={tags=_[5],data="b"} +_[4]={data="b",tags=_[5]} _[3]={_[4]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/resume from paragraph with nested choice.ans b/test/tests/resume from paragraph with nested choice.ans new file mode 100644 index 0000000..6b178a7 --- /dev/null +++ b/test/tests/resume from paragraph with nested choice.ans @@ -0,0 +1,77 @@ +$ f + > a + -> a + ยง p + > aa + -> aa + > ab + -> ab + > b + -> b + ~ choose(2) + + > c + -> c + ~ choose(1) + +~ f + +~ f.p + +$ g + > a + -> a + ยง p + > aa + -> aa + > ab + -> ab + > b + -> b + ~ choose(2) + autoflush + > c + -> c + ~ choose(1) + +~ g + +~ g.p + +$ h + ~ 1 + > a + -> a + ยง p + > aa + -> aa + > ab + -> ab + ~ choose(1) + > b + -> b + > c + -> c + ~ choose(1) + +~ h + +~ h.p + +$ i + > a + -> a + ยง p + > aa + -> aa + > ab + -> ab + > b + -> b + ~ 1 + > c + -> c + +~ i + +~ i.p diff --git a/test/tests/resume from paragraph with nested choice.lua b/test/tests/resume from paragraph with nested choice.lua new file mode 100644 index 0000000..5347a8a --- /dev/null +++ b/test/tests/resume from paragraph with nested choice.lua @@ -0,0 +1,256 @@ +local _={} +_[121]={} +_[120]={} +_[119]={} +_[118]={} +_[117]={} +_[116]={} +_[115]={} +_[114]={} +_[113]={} +_[112]={} +_[111]={} +_[110]={} +_[109]={} +_[108]={} +_[107]={} +_[106]={} +_[105]={} +_[104]={} +_[103]={} +_[102]={} +_[101]={} +_[100]={} +_[99]={} +_[98]={} +_[97]={} +_[96]={} +_[95]={} +_[94]={} +_[93]={} +_[92]={} +_[91]={} +_[90]={} +_[89]={} +_[88]={} +_[87]={} +_[86]={data="c",tags=_[121]} +_[85]={data="b",tags=_[120]} +_[84]={data="a",tags=_[119]} +_[83]={data="-> aa",tags=_[118]} +_[82]={data="ab",tags=_[117]} +_[81]={data="aa",tags=_[116]} +_[80]={data="-> aa",tags=_[115]} +_[79]={data="ab",tags=_[114]} +_[78]={data="aa",tags=_[113]} +_[77]={data="-> a",tags=_[112]} +_[76]={data="c",tags=_[111]} +_[75]={data="b",tags=_[110]} +_[74]={data="a",tags=_[109]} +_[73]={data="-> c",tags=_[108]} +_[72]={data="c",tags=_[107]} +_[71]={data="autoflush",tags=_[106]} +_[70]={data="-> ab",tags=_[105]} +_[69]={data="ab",tags=_[104]} +_[68]={data="aa",tags=_[103]} +_[67]={data="-> c",tags=_[102]} +_[66]={data="c",tags=_[101]} +_[65]={data="autoflush",tags=_[100]} +_[64]={data="-> b",tags=_[99]} +_[63]={data="b",tags=_[98]} +_[62]={data="a",tags=_[97]} +_[61]={data="-> c",tags=_[96]} +_[60]={data="c",tags=_[95]} +_[59]={data="-> ab",tags=_[94]} +_[58]={data="ab",tags=_[93]} +_[57]={data="aa",tags=_[92]} +_[56]={data="-> c",tags=_[91]} +_[55]={data="c",tags=_[90]} +_[54]={data="-> b",tags=_[89]} +_[53]={data="b",tags=_[88]} +_[52]={data="a",tags=_[87]} +_[51]={_[84],_[85],_[86]} +_[50]={_[83]} +_[49]={_[81],_[82]} +_[48]={_[80]} +_[47]={_[78],_[79]} +_[46]={_[77]} +_[45]={_[74],_[75],_[76]} +_[44]={_[73]} +_[43]={_[72]} +_[42]={_[71]} +_[41]={_[70]} +_[40]={_[68],_[69]} +_[39]={_[67]} +_[38]={_[66]} +_[37]={_[65]} +_[36]={_[64]} +_[35]={_[62],_[63]} +_[34]={_[61]} +_[33]={_[60]} +_[32]={_[59]} +_[31]={_[57],_[58]} +_[30]={_[56]} +_[29]={_[55]} +_[28]={_[54]} +_[27]={_[52],_[53]} +_[26]={"error","invalid choice"} +_[25]={"choice",_[51]} +_[24]={"text",_[50]} +_[23]={"choice",_[49]} +_[22]={"text",_[48]} +_[21]={"choice",_[47]} +_[20]={"text",_[46]} +_[19]={"choice",_[45]} +_[18]={"text",_[44]} +_[17]={"choice",_[43]} +_[16]={"text",_[42]} +_[15]={"text",_[41]} +_[14]={"choice",_[40]} +_[13]={"text",_[39]} +_[12]={"choice",_[38]} +_[11]={"text",_[37]} +_[10]={"text",_[36]} +_[9]={"choice",_[35]} +_[8]={"text",_[34]} +_[7]={"choice",_[33]} +_[6]={"text",_[32]} +_[5]={"choice",_[31]} +_[4]={"text",_[30]} +_[3]={"choice",_[29]} +_[2]={"text",_[28]} +_[1]={"choice",_[27]} +return {_[1],_[2],_[3],_[4],_[5],_[6],_[7],_[8],_[9],_[10],_[11],_[12],_[13],_[14],_[15],_[16],_[17],_[18],_[19],_[20],_[21],_[22],_[23],_[24],_[25],_[26]} +--[[ +{ "choice", { { + data = "a", + tags = {} + }, { + data = "b", + tags = {} + } } } +{ "text", { { + data = "-> b", + tags = {} + } } } +{ "choice", { { + data = "c", + tags = {} + } } } +{ "text", { { + data = "-> c", + tags = {} + } } } +{ "choice", { { + data = "aa", + tags = {} + }, { + data = "ab", + tags = {} + } } } +{ "text", { { + data = "-> ab", + tags = {} + } } } +{ "choice", { { + data = "c", + tags = {} + } } } +{ "text", { { + data = "-> c", + tags = {} + } } } +{ "choice", { { + data = "a", + tags = {} + }, { + data = "b", + tags = {} + } } } +{ "text", { { + data = "-> b", + tags = {} + } } } +{ "text", { { + data = "autoflush", + tags = {} + } } } +{ "choice", { { + data = "c", + tags = {} + } } } +{ "text", { { + data = "-> c", + tags = {} + } } } +{ "choice", { { + data = "aa", + tags = {} + }, { + data = "ab", + tags = {} + } } } +{ "text", { { + data = "-> ab", + tags = {} + } } } +{ "text", { { + data = "autoflush", + tags = {} + } } } +{ "choice", { { + data = "c", + tags = {} + } } } +{ "text", { { + data = "-> c", + tags = {} + } } } +{ "choice", { { + data = "a", + tags = {} + }, { + data = "b", + tags = {} + }, { + data = "c", + tags = {} + } } } +{ "text", { { + data = "-> a", + tags = {} + } } } +{ "choice", { { + data = "aa", + tags = {} + }, { + data = "ab", + tags = {} + } } } +{ "text", { { + data = "-> aa", + tags = {} + } } } +{ "choice", { { + data = "aa", + tags = {} + }, { + data = "ab", + tags = {} + } } } +{ "text", { { + data = "-> aa", + tags = {} + } } } +{ "choice", { { + data = "a", + tags = {} + }, { + data = "b", + tags = {} + }, { + data = "c", + tags = {} + } } } +{ "error", "invalid choice" } +]]-- \ No newline at end of file diff --git a/test/tests/resume from paragraph with nested condition.ans b/test/tests/resume from paragraph with nested condition.ans new file mode 100644 index 0000000..9a7b7d4 --- /dev/null +++ b/test/tests/resume from paragraph with nested condition.ans @@ -0,0 +1,21 @@ +$ f + ~ 1 + ยง p + x + ~~ + y + +~ f + +~ f.p + +$ g + ~ 0 + ยง p + x + ~~ + y + +~ g + +~ g.p diff --git a/test/tests/resume from paragraph with nested condition.lua b/test/tests/resume from paragraph with nested condition.lua new file mode 100644 index 0000000..f662658 --- /dev/null +++ b/test/tests/resume from paragraph with nested condition.lua @@ -0,0 +1,38 @@ +local _={} +_[17]={} +_[16]={} +_[15]={} +_[14]={} +_[13]={data="x",tags=_[17]} +_[12]={data="y",tags=_[16]} +_[11]={data="x",tags=_[15]} +_[10]={data="x",tags=_[14]} +_[9]={_[13]} +_[8]={_[12]} +_[7]={_[11]} +_[6]={_[10]} +_[5]={"return"} +_[4]={"text",_[9]} +_[3]={"text",_[8]} +_[2]={"text",_[7]} +_[1]={"text",_[6]} +return {_[1],_[2],_[3],_[4],_[5]} +--[[ +{ "text", { { + data = "x", + tags = {} + } } } +{ "text", { { + data = "x", + tags = {} + } } } +{ "text", { { + data = "y", + tags = {} + } } } +{ "text", { { + data = "x", + tags = {} + } } } +{ "return" } +]]-- \ No newline at end of file diff --git a/test/tests/tag decorator empty.lua b/test/tests/tag decorator empty.lua index 780a643..c5fd791 100644 --- a/test/tests/tag decorator empty.lua +++ b/test/tests/tag decorator empty.lua @@ -1,7 +1,7 @@ local _={} _[6]={1} -_[5]={tags=_[6],data="bar"} -_[4]={tags=_[6],data="foo"} +_[5]={data="bar",tags=_[6]} +_[4]={data="foo",tags=_[6]} _[3]={_[4],_[5]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/tag decorator nested.lua b/test/tests/tag decorator nested.lua index a6f5928..9611766 100644 --- a/test/tests/tag decorator nested.lua +++ b/test/tests/tag decorator nested.lua @@ -2,8 +2,8 @@ local _={} _[8]={2,3} _[7]={1,a=_[8]} _[6]={1} -_[5]={tags=_[7],data="bar"} -_[4]={tags=_[6],data="foo"} +_[5]={data="bar",tags=_[7]} +_[4]={data="foo",tags=_[6]} _[3]={_[4],_[5]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/tag decorator.lua b/test/tests/tag decorator.lua index a6f5928..9611766 100644 --- a/test/tests/tag decorator.lua +++ b/test/tests/tag decorator.lua @@ -2,8 +2,8 @@ local _={} _[8]={2,3} _[7]={1,a=_[8]} _[6]={1} -_[5]={tags=_[7],data="bar"} -_[4]={tags=_[6],data="foo"} +_[5]={data="bar",tags=_[7]} +_[4]={data="foo",tags=_[6]} _[3]={_[4],_[5]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/tag empty.lua b/test/tests/tag empty.lua index 780a643..c5fd791 100644 --- a/test/tests/tag empty.lua +++ b/test/tests/tag empty.lua @@ -1,7 +1,7 @@ local _={} _[6]={1} -_[5]={tags=_[6],data="bar"} -_[4]={tags=_[6],data="foo"} +_[5]={data="bar",tags=_[6]} +_[4]={data="foo",tags=_[6]} _[3]={_[4],_[5]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/tag.lua b/test/tests/tag.lua index a6f5928..9611766 100644 --- a/test/tests/tag.lua +++ b/test/tests/tag.lua @@ -2,8 +2,8 @@ local _={} _[8]={2,3} _[7]={1,a=_[8]} _[6]={1} -_[5]={tags=_[7],data="bar"} -_[4]={tags=_[6],data="foo"} +_[5]={data="bar",tags=_[7]} +_[4]={data="foo",tags=_[6]} _[3]={_[4],_[5]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/text block.lua b/test/tests/text block.lua index b7a6dc2..8c9d78c 100644 --- a/test/tests/text block.lua +++ b/test/tests/text block.lua @@ -1,8 +1,8 @@ local _={} _[7]={} _[6]={} -_[5]={tags=_[7],data="b c"} -_[4]={tags=_[6],data="a"} +_[5]={data="b c",tags=_[7]} +_[4]={data="a",tags=_[6]} _[3]={_[4],_[5]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/text break.lua b/test/tests/text break.lua index 7a00295..89356fb 100644 --- a/test/tests/text break.lua +++ b/test/tests/text break.lua @@ -1,8 +1,8 @@ local _={} _[9]={} _[8]={} -_[7]={tags=_[9],data="b c"} -_[6]={tags=_[8],data="a"} +_[7]={data="b c",tags=_[9]} +_[6]={data="a",tags=_[8]} _[5]={_[7]} _[4]={_[6]} _[3]={"return"} diff --git a/test/tests/text format.lua b/test/tests/text format.lua index c5653d1..ab7c161 100644 --- a/test/tests/text format.lua +++ b/test/tests/text format.lua @@ -1,6 +1,6 @@ local _={} _[5]={} -_[4]={tags=_[5],data="a: 5"} +_[4]={data="a: 5",tags=_[5]} _[3]={_[4]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/text.lua b/test/tests/text.lua index 504a82d..9c00295 100644 --- a/test/tests/text.lua +++ b/test/tests/text.lua @@ -1,6 +1,6 @@ local _={} _[5]={} -_[4]={tags=_[5],data="a"} +_[4]={data="a",tags=_[5]} _[3]={_[4]} _[2]={"return"} _[1]={"text",_[3]} diff --git a/test/tests/unseen line.lua b/test/tests/unseen line.lua index f6ac2a6..f2546fa 100644 --- a/test/tests/unseen line.lua +++ b/test/tests/unseen line.lua @@ -4,11 +4,11 @@ _[12]={} _[11]={} _[10]={} _[9]={} -_[8]={tags=_[13],data="b"} -_[7]={tags=_[12],data="a"} -_[6]={tags=_[11],data="b"} -_[5]={tags=_[10],data="seen only once"} -_[4]={tags=_[9],data="a"} +_[8]={data="b",tags=_[13]} +_[7]={data="a",tags=_[12]} +_[6]={data="b",tags=_[11]} +_[5]={data="seen only once",tags=_[10]} +_[4]={data="a",tags=_[9]} _[3]={_[4],_[5],_[6],_[7],_[8]} _[2]={"return"} _[1]={"text",_[3]}