diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2017-02-12 16:36:35 +0000 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2017-02-12 16:36:35 +0000 |
commit | 3ba09da3af9b59cdd1f54626253c3cf67a41a4e7 (patch) | |
tree | 477098d4580ad16887a4715ca81c0c0c1e138e3f | |
parent | aa1f0ebe82f1aa47d055459e96907f050ba751d8 (diff) | |
download | lace-3ba09da3af9b59cdd1f54626253c3cf67a41a4e7.tar.gz |
fix bug where '[' would be lostv1.3.1
If the accumulator was non-empty during the lexing of a lexeme
which contained '[' such as ![foo] the ! being in the accumulator
would prevent the [foo] being processed as a quoted sublexer. Since
[] quoting is only for sublexing, instead we add the accumulator
to the lexeme so that it can be used later in the compiler to ensure
that ![foo] correctly turns into !__autodefN etc.
-rw-r--r-- | lib/lace/compiler.lua | 2 | ||||
-rw-r--r-- | lib/lace/lex.lua | 18 | ||||
-rw-r--r-- | test/test-lace.compile-subdefine3.rules | 2 | ||||
-rw-r--r-- | test/test-lace.compiler.lua | 5 | ||||
-rw-r--r-- | test/test-lace.engine-inverted-subdefine-works.rules | 2 | ||||
-rw-r--r-- | test/test-lace.engine.lua | 8 |
6 files changed, 26 insertions, 11 deletions
diff --git a/lib/lace/compiler.lua b/lib/lace/compiler.lua index 1c3aa01..499abb1 100644 --- a/lib/lace/compiler.lua +++ b/lib/lace/compiler.lua @@ -101,7 +101,7 @@ local function transfer_args(compcontext, content, rules) return bindname(exec_context, rule, name, defn) end - args[#args+1] = definename + args[#args+1] = content[i].acc .. definename rules[#rules+1] = definerule else args[#args+1] = content[i].str diff --git a/lib/lace/lex.lua b/lib/lace/lex.lua index 3bd9ec2..7ebb21a 100644 --- a/lib/lace/lex.lua +++ b/lib/lace/lex.lua @@ -60,16 +60,14 @@ local function _lex_one_line(line, terminator) quoting = c force_empty = true elseif c == '[' and quoting == false then - if acc == "" then - -- Something worth lexing - local ltab, rest, warns = lex_one_line(line, "]") - -- For now, assume the accumulator is good enough - cpos = cpos + #line - #rest - r[#r+1] = { spos = spos, epos = cpos, sub = ltab } - spos = cpos + 1 - line = rest - acc = "" - end + -- Something worth lexing + local ltab, rest, warns = lex_one_line(line, "]") + -- For now, assume the accumulator is good enough + cpos = cpos + #line - #rest + r[#r+1] = { spos = spos, epos = cpos, sub = ltab, acc = acc } + spos = cpos + 1 + line = rest + acc = "" elseif c == "'" and quoting == c then -- End single quotes quoting = false diff --git a/test/test-lace.compile-subdefine3.rules b/test/test-lace.compile-subdefine3.rules new file mode 100644 index 0000000..5c6b97c --- /dev/null +++ b/test/test-lace.compile-subdefine3.rules @@ -0,0 +1,2 @@ +define is_susan equal susan +deny "Booo" is_susan ![equal jeff] diff --git a/test/test-lace.compiler.lua b/test/test-lace.compiler.lua index 9eb7e99..22ee6c4 100644 --- a/test/test-lace.compiler.lua +++ b/test/test-lace.compiler.lua @@ -398,6 +398,11 @@ function suite.okay_nested_subdefine() assert(result, msg) end +function suite.okay_negated_subdefine() + local result, msg = compiler.compile(comp_context, "subdefine3") + assert(result, msg) +end + local count_ok = 0 for _, testname in ipairs(testnames) do -- print("Run: " .. testname) diff --git a/test/test-lace.engine-inverted-subdefine-works.rules b/test/test-lace.engine-inverted-subdefine-works.rules new file mode 100644 index 0000000..df3add8 --- /dev/null +++ b/test/test-lace.engine-inverted-subdefine-works.rules @@ -0,0 +1,2 @@ +default allow +deny "PASS" ![equal jeff geoff] diff --git a/test/test-lace.engine.lua b/test/test-lace.engine.lua index 7b8a055..5e81f07 100644 --- a/test/test-lace.engine.lua +++ b/test/test-lace.engine.lua @@ -253,6 +253,14 @@ function suite.subdefine_works() assert(result, msg) end +function suite.inverted_subdefine_works() + local ruleset, msg = lace.compiler.compile(comp_context, "inverted-subdefine-works") + assert(type(ruleset) == "table", "Ruleset did not compile") + local ectx = {jeff = "geoff"} + local result, msg = lace.engine.run(ruleset, ectx) + assert(result, msg) +end + function suite.subdefine_err_reported() local ruleset, msg = lace.compiler.compile(comp_context, "subdefine-error") assert(type(ruleset) == "table", "Ruleset did not compile") |