diff --git a/sh/main.sh b/sh/main.sh index 4316a9a..8e76ad4 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -49,7 +49,7 @@ rwx_main() { # source user root rwx_source "${RWX_SELF_USER}" # parse code cache - rwx_parse + rwx_parse_code # context / command if [ -n "${RWX_COMMAND_NAME}" ]; then "${RWX_SELF_COMMAND}${RWX_COMMAND_NAME}" "${@}" @@ -172,26 +172,21 @@ RWX_REGEX_BEGIN="^${RWX_REGEX_SPACES}" RWX_REGEX_OPEN="\ ${RWX_REGEX_SPACES}(${RWX_REGEX_SPACES})${RWX_REGEX_SPACES}{.*" -rwx_parse() { - local line +rwx_parse_code() { # parse constants - RWX_CONSTANTS="" + RWX_CONSTANTS="$(rwx_parse_constants)" + # parse functions + RWX_FUNCTIONS="$(rwx_parse_functions)" +} +rwx_parse_constants() { printf "%s\n" "${RWX_CODE}" | grep "${RWX_REGEX_BEGIN}${RWX_REGEX_CONSTANT}${RWX_REGEX_SET}" | - sed "s|${RWX_REGEX_BEGIN}\\(${RWX_REGEX_CONSTANT}\\)${RWX_REGEX_SET}|\\1|" | - while IFS= read -r line; do - RWX_CONSTANTS="${RWX_CONSTANTS}${line} -" - done - # parse functions - RWX_FUNCTIONS="" + sed "s|${RWX_REGEX_BEGIN}\\(${RWX_REGEX_CONSTANT}\\)${RWX_REGEX_SET}|\\1|" +} +rwx_parse_functions() { printf "%s\n" "${RWX_CODE}" | grep "${RWX_REGEX_BEGIN}${RWX_REGEX_FUNCTION}${RWX_REGEX_OPEN}" | - sed "s|${RWX_REGEX_BEGIN}\\(${RWX_REGEX_FUNCTION}\\)${RWX_REGEX_OPEN}|\\1|" | - while IFS= read -r line; do - RWX_FUNCTIONS="${RWX_FUNCTIONS}${line} -" - done + sed "s|${RWX_REGEX_BEGIN}\\(${RWX_REGEX_FUNCTION}\\)${RWX_REGEX_OPEN}|\\1|" } # ╭──────┬─────╮