Compare commits

..

10 commits

Author SHA1 Message Date
3ccfc82cf2
fix
All checks were successful
/ job (push) Successful in 5m2s
2025-07-07 03:09:02 +02:00
b2e965da92
code/parse 2025-07-07 03:07:28 +02:00
09c0721560
code/parse 2025-07-07 03:01:21 +02:00
0b12a7545e
code/load 2025-07-07 02:58:39 +02:00
45f0ebbb9b
code/vars 2025-07-07 02:45:58 +02:00
40bd26f9ce
awk/variables 2025-07-07 02:31:01 +02:00
fd281ee8d0
awk/constants 2025-07-07 02:27:41 +02:00
dbfe0e1407
awk/variable 2025-07-07 02:23:26 +02:00
17aaeb233d
lint 2025-07-07 02:21:50 +02:00
fe98428b6c
awk/functions 2025-07-07 02:20:25 +02:00
4 changed files with 63 additions and 83 deletions

View file

@ -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])

View file

@ -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 <<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
# source user root
rwx_source "${RWX_SELF_USER}"
# parse code cache
rwx_parse_code
# load code cache
rwx_code_load
# context / command
if [ -n "${RWX_COMMAND_NAME}" ]; then
"${RWX_SELF_COMMAND}${RWX_COMMAND_NAME}" "${@}"
@ -177,75 +177,6 @@ rwx_find_shell() {
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 │
# ╰──────┴─────╯

View file

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