os.translateCommands now supports multiple tokens

This commit is contained in:
Sam Surtees 2017-04-20 02:05:27 +10:00
parent 39367d6c57
commit 537392428d
2 changed files with 24 additions and 8 deletions

View File

@ -535,15 +535,24 @@
end end
local processOne = function(cmd) local processOne = function(cmd)
local token = cmd:match("^{.+}") local i, j, prev
if token then repeat
token = token:sub(2, #token - 1):lower() i, j = cmd:find("{.-}")
local args = cmd:sub(#token + 4) if i then
local func = map[token] or os.commandTokens["_"][token] if i == prev then
if func then break
cmd = func(args) end
local token = cmd:sub(i + 1, j - 1):lower()
local args = cmd:sub(j + 2)
local func = map[token] or os.commandTokens["_"][token]
if func then
cmd = cmd:sub(1, i -1) .. func(args)
end
prev = i
end end
end until i == nil
return cmd return cmd
end end

View File

@ -177,6 +177,13 @@
test.isequal("test a b", os.translateCommands("{COPY} a b", "test")) test.isequal("test a b", os.translateCommands("{COPY} a b", "test"))
end end
function suite.translateCommand_callsProcessor_multipleTokens()
os.commandTokens.test = {
copy = function(value) return "test " .. value end
}
test.isequal("test a b; test c d; test e f;", os.translateCommands("{COPY} a b; {COPY} c d; {COPY} e f;", "test"))
end
-- --
-- os.translateCommand() windows COPY tests -- os.translateCommand() windows COPY tests
-- --