Compare commits
10 commits
4151928013
...
3ccfc82cf2
Author | SHA1 | Date | |
---|---|---|---|
3ccfc82cf2 | |||
b2e965da92 | |||
09c0721560 | |||
0b12a7545e | |||
45f0ebbb9b | |||
40bd26f9ce | |||
fd281ee8d0 | |||
dbfe0e1407 | |||
17aaeb233d | |||
fe98428b6c |
4 changed files with 63 additions and 83 deletions
12
sh/code.awk
12
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])
|
||||
|
|
55
sh/code.sh
55
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 <<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}"
|
||||
}
|
||||
|
|
73
sh/main.sh
73
sh/main.sh
|
@ -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 │
|
||||
# ╰──────┴─────╯
|
||||
|
|
|
@ -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}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue