Thu, 23 Mar 2023 15:09:10 +0000
scansion: Support for per-script captures
main.lua | file | annotate | diff | comparison | revisions | |
scansion/helpers.lua | file | annotate | diff | comparison | revisions | |
scansion/objects/client.lua | file | annotate | diff | comparison | revisions |
--- a/main.lua Thu Mar 23 12:14:53 2023 +0000 +++ b/main.lua Thu Mar 23 15:09:10 2023 +0000 @@ -141,6 +141,7 @@ end local function initialize_script(script, context) + script.captures = {}; local c = 0; for name, object in pairs(script.objects) do --luacheck: ignore name context.line = object.defined_line
--- a/scansion/helpers.lua Thu Mar 23 12:14:53 2023 +0000 +++ b/scansion/helpers.lua Thu Mar 23 15:09:10 2023 +0000 @@ -1,6 +1,9 @@ local function filter_expression(script, s) local expr = s:match("^%$%{(.+)%}$"); if not expr then return s end + if script.captures and script.captures[expr] then + return script.captures[expr]; + end local name, value_name = expr:match("^(.+)'s (.+)$"); assert(name, "Unable to parse expression: "..expr); local key = value_name:lower():gsub(" ", "_");
--- a/scansion/objects/client.lua Thu Mar 23 12:14:53 2023 +0000 +++ b/scansion/objects/client.lua Thu Mar 23 15:09:10 2023 +0000 @@ -83,7 +83,7 @@ text = "Received unexpected stanza"; stanza = tostring(received_stanza); })); - elseif not expected_stanza or not stanzacmp.stanzas_match(expected_stanza, received_stanza) then + elseif not expected_stanza or not stanzacmp.stanzas_match(expected_stanza, received_stanza, client.script.captures) then if not expected_stanza then client.log("Received a stanza when none were expected: %s", received_stanza); else