mirror of
https://github.com/brues-code/SuperCleveRoidMacros.git
synced 2026-09-16 03:38:00 +00:00
Support Blizzard-style bracket groups: [a][b] Spell and [] fall-through
A clause may now carry a leading run of [group] blocks sharing one action; groups are OR'd, first pass wins, and [] always passes. The existing ;-separated single-block form is unchanged and mixes freely. The OR loop lives in the two single-clause evaluators, DoWithConditionals and TestAction, which expand a multi-group clause into one-group variants and recurse. That covers every ;-split site, /castsequence (where ; is not a separator and the sequence is keyed by the full args), /cancelaura, /stopmacro and the editor highlight without rewriting strings, so action.args, the ParsedMsg/Sequences caches and highlight offsets keep their identity. ParseMsg scans the leading group run (quote-aware) instead of the greedy %[(.+)%], which previously turned [a][b] into the bogus key a][b and made such clauses fail silently on both the cast and icon paths. The flag pattern still runs on the whole clause when there are no groups, so !Spell is byte-identical. TestAction reports which variant passed and TestForActiveAction stores its conditionals, so range/usable colouring follows the passing group's @unit rather than group 1's. /target gains ; and group support; /pfcast injects the resolved unit into every group, not just the first. The macro checker validates every leading block, drops the EMPTY_CONDITIONAL error, and catches a missing action after the last group.
This commit is contained in:
+70
@@ -614,6 +614,76 @@ function CleveRoids.splitStringIgnoringQuotes(str, separator)
|
||||
return result
|
||||
end
|
||||
|
||||
-- Splits a macro clause into its leading run of [group] blocks and the action
|
||||
-- that follows, Blizzard-style: `[a][b] Spell` is two groups sharing one action.
|
||||
-- Returns prefix (the leading whitespace and ? ! ~ flag characters, kept so a
|
||||
-- variant re-parses exactly like the original), groups (array with .n, each
|
||||
-- entry including its brackets) and restStart (index of the action text; 1 when
|
||||
-- there are no groups). Quote-aware for " so a ] inside a quoted argument does
|
||||
-- not close a group; not nesting-aware. An unclosed [ ends the scan at that [,
|
||||
-- which is what the old greedy "%[(.+)%]" produced for such input.
|
||||
function CleveRoids.ScanBracketGroups(msg)
|
||||
local groups = { n = 0 }
|
||||
if not msg then return "", groups, 1 end
|
||||
|
||||
local len = string.len(msg)
|
||||
local _, prefixEnd = string.find(msg, "^[%s%?!~]*")
|
||||
local prefix = string.sub(msg, 1, prefixEnd)
|
||||
local i = prefixEnd + 1
|
||||
|
||||
while i <= len and string.sub(msg, i, i) == "[" do
|
||||
local close = nil
|
||||
local inQuotes = false
|
||||
for j = i + 1, len do
|
||||
local c = string.sub(msg, j, j)
|
||||
if c == "\"" then
|
||||
inQuotes = not inQuotes
|
||||
elseif c == "]" and not inQuotes then
|
||||
close = j
|
||||
break
|
||||
end
|
||||
end
|
||||
if not close then break end
|
||||
|
||||
groups.n = groups.n + 1
|
||||
groups[groups.n] = string.sub(msg, i, close)
|
||||
local _, wsEnd = string.find(msg, "^%s*", close + 1)
|
||||
i = wsEnd + 1
|
||||
end
|
||||
|
||||
if groups.n == 0 then
|
||||
return prefix, groups, 1
|
||||
end
|
||||
return prefix, groups, i
|
||||
end
|
||||
|
||||
-- Single-group variants of a multi-group clause: `[a][b] Spell` becomes
|
||||
-- { "[a] Spell", "[b] Spell", n = 2 }. nil for anything with fewer than two
|
||||
-- groups so callers take their normal path without allocating. Memoised per
|
||||
-- clause string in CleveRoids.ExpandedGroups (false marks "nothing to expand").
|
||||
function CleveRoids.ExpandBracketGroups(msg)
|
||||
if not msg or not string.find(msg, "%[") then return nil end
|
||||
|
||||
local cached = CleveRoids.ExpandedGroups[msg]
|
||||
if cached ~= nil then
|
||||
return cached or nil
|
||||
end
|
||||
|
||||
local variants = nil
|
||||
local prefix, groups, restStart = CleveRoids.ScanBracketGroups(msg)
|
||||
if groups.n > 1 then
|
||||
local rest = string.sub(msg, restStart)
|
||||
if rest ~= "" then rest = " " .. rest end
|
||||
variants = { n = groups.n }
|
||||
for i = 1, groups.n do
|
||||
variants[i] = prefix .. groups[i] .. rest
|
||||
end
|
||||
end
|
||||
|
||||
CleveRoids.ExpandedGroups[msg] = variants or false
|
||||
return variants
|
||||
end
|
||||
|
||||
function CleveRoids.Print(...)
|
||||
local c = "|cFF4477FFCleveR|r|cFFFFFFFFoid :: |r"
|
||||
local out = ""
|
||||
|
||||
Reference in New Issue
Block a user