action/alias,doc
All checks were successful
/ job (push) Successful in 4m28s

This commit is contained in:
Marc Beninca 2025-07-06 06:41:44 +02:00
parent 30aead95e0
commit 1467c1158a
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F
3 changed files with 72 additions and 43 deletions

View file

@ -41,54 +41,68 @@ BEGIN {
} }
{ {
# doc if (action == "alias") {
if (match($0, RE_SHEBANG, m)) { if (match($0, RE_ALIAS, m)) {
append("shebang: " m[1]) append(m[1])
} else if (match($0, RE_DOC, m)) { } else if (match($0, RE_FUNCTION, m)) {
append(m[1]) n = split(doc, array, "\n")
} else if (match($0, RE_ALIAS, m)) { for (i = 1; i<= n; i++) {
append("alias: " m[1]) print array[i] "() { " m[1] " \"${@}\" ; }"
if (m[1] == target) { }
alias = 1 reset()
}
# set
} else if (match($0, RE_CONSTANT, m)) {
if (m[1] == target) {
printf "constant: "
output(m[1])
} else { } else {
reset() reset()
} }
} else if (match($0, RE_VARIABLE, m)) { } else if (action == "doc") {
if (m[1] == target) { # doc
printf "variable: " if (match($0, RE_SHEBANG, m)) {
output(m[1]) append("shebang: " m[1])
} else { } else if (match($0, RE_DOC, m)) {
append(m[1])
} else if (match($0, RE_ALIAS, m)) {
append("alias: " m[1])
if (m[1] == target) {
alias = 1
}
# set
} else if (match($0, RE_CONSTANT, m)) {
if (m[1] == target) {
printf "constant: "
output(m[1])
} else {
reset()
}
} else if (match($0, RE_VARIABLE, m)) {
if (m[1] == target) {
printf "variable: "
output(m[1])
} else {
reset()
}
# others
} else if (match($0, RE_MODULE, m)) {
reset() reset()
} if (m[1] == target) {
# others module = 1
} else if (match($0, RE_MODULE, m)) { }
reset() } else if (match($0, RE_FUNCTION, m)) {
if (m[1] == target) { if (alias) {
module = 1 print "alias: " target
} printf "function: "
} else if (match($0, RE_FUNCTION, m)) { output(m[1])
if (alias) { } else if (m[1] == target) {
print "alias: " target printf "function: "
printf "function: " output(target)
output(m[1]) } else {
} else if (m[1] == target) { reset()
printf "function: " }
output(target)
} else { } else {
reset() if (module) {
} printf "module: "
} else { output(target)
if (module) { } else {
printf "module: " reset()
output(target) }
} else {
reset()
} }
} }
} }

View file

@ -185,11 +185,25 @@ RWX_REGEX_TARGET_FUNCTION="\
${RWX_REGEX_BEGIN}\\(${RWX_REGEX_FUNCTION}\\)${RWX_REGEX_OPEN}" ${RWX_REGEX_BEGIN}\\(${RWX_REGEX_FUNCTION}\\)${RWX_REGEX_OPEN}"
rwx_parse_code() { rwx_parse_code() {
# parse aliases
local line
RWX_ALIASES="$(rwx_parse_aliases)"
while IFS= read -r line; do
eval "${line}"
done <<EOF
${RWX_ALIASES}
EOF
# parse constants # parse constants
RWX_CONSTANTS="$(rwx_parse_constants)" RWX_CONSTANTS="$(rwx_parse_constants)"
# parse functions # parse functions
RWX_FUNCTIONS="$(rwx_parse_functions)" RWX_FUNCTIONS="$(rwx_parse_functions)"
} }
rwx_parse_aliases() {
printf "%s" "${_rwx_code}" |
awk \
--assign action="alias" \
--file "${RWX_AWK}"
}
rwx_parse_constants() { rwx_parse_constants() {
printf "%s\n" "${_rwx_code}" | printf "%s\n" "${_rwx_code}" |
sed --silent "s|${RWX_REGEX_TARGET_CONSTANT}|\\1|p" sed --silent "s|${RWX_REGEX_TARGET_CONSTANT}|\\1|p"

View file

@ -7,6 +7,7 @@ rwx_doc() {
[ -n "${name}" ] || return [ -n "${name}" ] || return
printf "%s" "${_rwx_code}" | printf "%s" "${_rwx_code}" |
awk \ awk \
--assign action="doc" \
--assign target="${name}" \ --assign target="${name}" \
--file "${RWX_AWK}" --file "${RWX_AWK}"
} }