diff --git a/sh/code.awk b/sh/code.awk index 053f1be..0d23127 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -50,6 +50,18 @@ BEGIN { if (match($0, RE_ALIAS, m)) { print m[1] } + } else if (action == "constants") { + if (match($0, RE_CONSTANT, m)) { + print m[1] + } + } else if (action == "functions") { + if (match($0, RE_FUNCTION, m)) { + print m[1] + } + } else if (action == "variables") { + if (match($0, RE_VARIABLE, m)) { + print m[1] + } } else if (action == "aliases functions") { if (match($0, RE_ALIAS, m)) { append(m[1]) diff --git a/sh/code.sh b/sh/code.sh index 8838276..e5a898b 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -6,8 +6,18 @@ # │ code │ variables │ # ╰──────┴───────────╯ -# path to the required parsing awk script +# cache for the parsing awk script _rwx_code_awk="$(cat "${RWX_ROOT_SYSTEM}/code.awk")" +# cache for code aliases +_rwx_code_aliases="" +# cache for code aliases functions +_rwx_code_aliases_functions="" +# cache for code constants +_rwx_code_constants="" +# cache for code functions +_rwx_code_functions="" +# cache for code variables +_rwx_code_variables="" # ╭──────┬───────╮ # │ code │ parts │ @@ -19,6 +29,11 @@ rwx_code() { echo "${_rwx_code}" } +# show the cached awk script +rwx_code_awk() { + echo "${_rwx_code_awk}" +} + # show the cached aliases #= rca rwx_code_aliases() { @@ -31,11 +46,6 @@ rwx_code_aliases_functions() { echo "${_rwx_code_aliases_functions}" } -# show the cached awk script -rwx_code_awk() { - echo "${_rwx_code_awk}" -} - # show the cached constants #= rcc rwx_code_constants() { @@ -73,9 +83,38 @@ rwx_code_check() { rwx_code_doc() { local name="${1}" [ -n "${name}" ] || return - printf "%s" "${_rwx_code}" | + rwx_code | awk \ --assign action="doc" \ --assign target="${name}" \ - "$(rwx_code_awk)" + "${_rwx_code_awk}" +} + +rwx_code_load() { + # parse aliases + _rwx_code_aliases="$(rwx_code_parse "aliases")" + # parse aliases functions + local line text + _rwx_code_aliases_functions="$(rwx_code_parse "aliases functions")" + while IFS= read -r line; do + text="$(echo "${line}" | sed "s| |() { |")" + text="${text} \"\${@}\"; }" + eval "${text}" + done <