Compare commits

..

No commits in common. "3ccfc82cf26511cd5227f24614d4654b482a1a2b" and "4151928013227bc2b97478bf30a30314e98e6308" have entirely different histories.

4 changed files with 83 additions and 63 deletions

View file

@ -50,18 +50,6 @@ BEGIN {
if (match($0, RE_ALIAS, m)) { if (match($0, RE_ALIAS, m)) {
print m[1] 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") { } else if (action == "aliases functions") {
if (match($0, RE_ALIAS, m)) { if (match($0, RE_ALIAS, m)) {
append(m[1]) append(m[1])

View file

@ -6,18 +6,8 @@
# │ code │ variables │ # │ code │ variables │
# ╰──────┴───────────╯ # ╰──────┴───────────╯
# cache for the parsing awk script # path to the required parsing awk script
_rwx_code_awk="$(cat "${RWX_ROOT_SYSTEM}/code.awk")" _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 │ # │ code │ parts │
@ -29,11 +19,6 @@ rwx_code() {
echo "${_rwx_code}" echo "${_rwx_code}"
} }
# show the cached awk script
rwx_code_awk() {
echo "${_rwx_code_awk}"
}
# show the cached aliases # show the cached aliases
#= rca #= rca
rwx_code_aliases() { rwx_code_aliases() {
@ -46,6 +31,11 @@ rwx_code_aliases_functions() {
echo "${_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 # show the cached constants
#= rcc #= rcc
rwx_code_constants() { rwx_code_constants() {
@ -83,38 +73,9 @@ rwx_code_check() {
rwx_code_doc() { rwx_code_doc() {
local name="${1}" local name="${1}"
[ -n "${name}" ] || return [ -n "${name}" ] || return
rwx_code | printf "%s" "${_rwx_code}" |
awk \ awk \
--assign action="doc" \ --assign action="doc" \
--assign target="${name}" \ --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 <<EOF
${_rwx_code_aliases_functions}
EOF
# parse constants
_rwx_code_constants="$(rwx_code_parse "constants")"
# parse functions
_rwx_code_functions="$(rwx_code_parse "functions")"
# parse variables
_rwx_code_variables="$(rwx_code_parse "variables")"
}
rwx_code_parse() {
local action="${1}"
rwx_code |
awk \
--assign action="${action}" \
"${_rwx_code_awk}"
} }

View file

@ -63,8 +63,8 @@ rwx_main() {
fi fi
# source user root # source user root
rwx_source "${RWX_SELF_USER}" rwx_source "${RWX_SELF_USER}"
# load code cache # parse code cache
rwx_code_load rwx_parse_code
# context / command # context / command
if [ -n "${RWX_COMMAND_NAME}" ]; then if [ -n "${RWX_COMMAND_NAME}" ]; then
"${RWX_SELF_COMMAND}${RWX_COMMAND_NAME}" "${@}" "${RWX_SELF_COMMAND}${RWX_COMMAND_NAME}" "${@}"
@ -177,6 +177,75 @@ rwx_find_shell() {
rwx_find_extension "sh" "${@}" rwx_find_extension "sh" "${@}"
} }
# ╭──────┬───────╮
# │ main │ parse │
# ╰──────┴───────╯
RWX_REGEX_CONSTANT="[_A-Z][_0-9A-Z]*"
RWX_REGEX_FUNCTION="[_A-Za-z][_0-9A-Za-z]*"
RWX_REGEX_SET="=.*"
RWX_REGEX_SPACES="[[:space:]]*"
RWX_REGEX_VARIABLE="[_a-z][_0-9a-z]*"
RWX_REGEX_BEGIN="^"
RWX_REGEX_OPEN="\
${RWX_REGEX_SPACES}(${RWX_REGEX_SPACES})${RWX_REGEX_SPACES}{.*"
RWX_REGEX_TARGET_CONSTANT="\
${RWX_REGEX_BEGIN}\\(${RWX_REGEX_CONSTANT}\\)${RWX_REGEX_SET}"
RWX_REGEX_TARGET_FUNCTION="\
${RWX_REGEX_BEGIN}\\(${RWX_REGEX_FUNCTION}\\)${RWX_REGEX_OPEN}"
RWX_REGEX_TARGET_VARIABLE="\
${RWX_REGEX_BEGIN}\\(${RWX_REGEX_VARIABLE}\\)${RWX_REGEX_SET}"
# cache for code variables
_rwx_code_variables=""
rwx_parse_code() {
# parse aliases
_rwx_code_aliases="$(rwx_parse_aliases)"
# parse aliases functions
local line text
_rwx_code_aliases_functions="$(rwx_parse_aliases_functions)"
while IFS= read -r line; do
text="$(echo "${line}" | sed "s| |() { |")"
text="${text} \"\${@}\"; }"
eval "${text}"
done <<EOF
${_rwx_code_aliases_functions}
EOF
# parse constants
_rwx_code_constants="$(rwx_parse_constants)"
# parse functions
_rwx_code_functions="$(rwx_parse_functions)"
# parse variables
_rwx_code_variables="$(rwx_parse_variables)"
}
rwx_parse_aliases() {
echo "${_rwx_code}" |
awk \
--assign action="aliases" \
"$(rwx_code_awk)"
}
rwx_parse_aliases_functions() {
printf "%s" "${_rwx_code}" |
awk \
--assign action="aliases functions" \
"$(rwx_code_awk)"
}
rwx_parse_constants() {
printf "%s" "${_rwx_code}" |
sed --silent "s|${RWX_REGEX_TARGET_CONSTANT}|\\1|p"
}
rwx_parse_functions() {
printf "%s" "${_rwx_code}" |
sed --silent "s|${RWX_REGEX_TARGET_FUNCTION}|\\1|p"
}
rwx_parse_variables() {
printf "%s" "${_rwx_code}" |
sed --silent "s|${RWX_REGEX_TARGET_VARIABLE}|\\1|p"
}
# ╭──────┬─────╮ # ╭──────┬─────╮
# │ main │ run │ # │ main │ run │
# ╰──────┴─────╯ # ╰──────┴─────╯

View file

@ -21,7 +21,8 @@ rwx_test_code() {
"variables" \ "variables" \
"functions" \ "functions" \
"aliases" \ "aliases" \
"aliases_functions" "aliases_functions" \
rwx_code rwx_code
for items in "${@}"; do for items in "${@}"; do
echo echo
@ -46,7 +47,8 @@ rwx_test_doc() {
"rwx_cache" \ "rwx_cache" \
\ \
"alias/batcat" \ "alias/batcat" \
"b" "b" \
for item in "${@}"; do for item in "${@}"; do
echo echo
rwx_code_doc "${item}" rwx_code_doc "${item}"