From 98a04b12db41ff30f675623d7340ad09075b751a Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sat, 29 May 2021 00:57:42 +0100 Subject: [PATCH] tokenise_commands: fix ordering --- .../utils/parse/tokenise_commands.lua | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/worldeditadditions/utils/parse/tokenise_commands.lua b/worldeditadditions/utils/parse/tokenise_commands.lua index 21c62dc..2a96746 100644 --- a/worldeditadditions/utils/parse/tokenise_commands.lua +++ b/worldeditadditions/utils/parse/tokenise_commands.lua @@ -3,27 +3,6 @@ -- function worldeditadditions.trim(str) return (str:gsub("^%s*(.-)%s*$", "%1")) end ---- Tokenises a string of multiple commands into an array of individual commands. --- Preserves the forward slash at the beginning of each command name. --- Also supports arbitrarily nested and complex curly braces { } for grouping --- commands together that would normally be split apart. --- --- Simple example: --- INPUT: //1 //2 //outset 25 //fixlight --- OUTPUT: { "//1", "//2", "//outset 25", "//fixlight" } --- --- Example with curly braces: --- INPUT: //1 //2 //outset 50 {//many 5 //multi //fixlight //clearcut} --- OUTPUT: { "//1", "//2", "//outset 50", "//many 5 //multi //fixlight //clearcut"} --- --- @param command_str str The command string to operate on. --- @returns bool,(string[]|string) If the operation was successful, then true followed by a table of strings is returned. If the operation was not successful, then false followed by an error message (as a single string) is returned instead. -function worldeditadditions.parse.tokenise_commands(command_str) - local success, result = tokenise(command_str) - if not success then return success, result end - return true, recombine(result) -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. @@ -103,6 +82,29 @@ local function recombine(parts) return result end + +--- Tokenises a string of multiple commands into an array of individual commands. +-- Preserves the forward slash at the beginning of each command name. +-- Also supports arbitrarily nested and complex curly braces { } for grouping +-- commands together that would normally be split apart. +-- +-- Simple example: +-- INPUT: //1 //2 //outset 25 //fixlight +-- OUTPUT: { "//1", "//2", "//outset 25", "//fixlight" } +-- +-- Example with curly braces: +-- INPUT: //1 //2 //outset 50 {//many 5 //multi //fixlight //clearcut} +-- OUTPUT: { "//1", "//2", "//outset 50", "//many 5 //multi //fixlight //clearcut"} +-- +-- @param command_str str The command string to operate on. +-- @returns bool,(string[]|string) If the operation was successful, then true followed by a table of strings is returned. If the operation was not successful, then false followed by an error message (as a single string) is returned instead. +function worldeditadditions.parse.tokenise_commands(command_str) + local success, result = tokenise(command_str) + if not success then return success, result end + return true, recombine(result) +end + + ----- Test harness code ----- ----------------------------- -- local function printparts(tbl)