tokenise_commands: improve comments

This commit is contained in:
Starbeamrainbowlabs 2021-05-29 00:54:30 +01:00
parent 50da328c67
commit 46eaf10884
Signed by: sbrl
GPG key ID: 1BE5172E637709C2

View file

@ -24,7 +24,10 @@ function worldeditadditions.parse.tokenise_commands(command_str)
return true, recombine(result) return true, recombine(result)
end end
--- The main tokeniser. Splits the input string up into space separated tokens, except when said spaces are inside { curly braces }.
-- Note that the outermost set of curly braces are stripped.
-- @param str string The input string to tokenise.
-- @returns string[] A list of tokens
local function tokenise(str) local function tokenise(str)
if type(str) ~= "string" then return false, "Error: Expected input of type string." end if type(str) ~= "string" then return false, "Error: Expected input of type string." end
str = str:gsub("%s+", " ") -- Replace all runs of whitespace with a single space str = str:gsub("%s+", " ") -- Replace all runs of whitespace with a single space
@ -82,6 +85,9 @@ local function tokenise(str)
return true, result return true, result
end end
--- Recombines a list of tokens into a list of commands.
-- @param parts string[] The tokens from tokenise(str).
-- @returns string[] The tokens, but run through trim() & grouped into commands (1 element in the list = 1 command)
local function recombine(parts) local function recombine(parts)
local result = {} local result = {}
local acc = {} local acc = {}