Compare commits

...

11 commits

Author SHA1 Message Date
b0afca09a5
shebang
All checks were successful
/ job (push) Successful in 4m59s
2025-07-06 04:43:37 +02:00
96bf706e32
alias,printf 2025-07-06 04:40:46 +02:00
bb787cc0cc
doc/alias
All checks were successful
/ job (push) Successful in 4m56s
2025-07-06 04:33:32 +02:00
d367548c08
types 2025-07-06 04:21:03 +02:00
ec9907d450
main/test 2025-07-06 04:11:06 +02:00
ad235af38f
"" 2025-07-06 03:57:29 +02:00
beb3025828
rejigger
All checks were successful
/ job (push) Successful in 5m26s
2025-07-06 03:53:18 +02:00
918ed255f7
fix
All checks were successful
/ job (push) Successful in 4m56s
2025-07-06 03:24:23 +02:00
3216f11da0
attempt from scratch 2025-07-06 03:16:41 +02:00
96ea65e3da
doc.awk 2025-07-06 00:13:08 +02:00
d377bcea37
doc/awk 2025-07-06 00:12:37 +02:00
3 changed files with 123 additions and 3 deletions

83
sh/doc.awk Normal file
View file

@ -0,0 +1,83 @@
function append(line) {
if (doc) {
doc = doc "\n"
}
doc = doc line
}
function output(name) {
print name
print doc
exit
}
function reset() {
doc = ""
}
BEGIN {
RE_ANY = "(.*)"
RE_NAME = "([_A-Za-z][_0-9A-Za-z]*)"
RE_SPACE = "[[:space:]]"
RE_SPACES = RE_SPACE "*"
RE_BEGIN = "^"
RE_END = RE_SPACES "$"
RE_FUNC = RE_SPACES "\\(" RE_SPACES "\\)" RE_SPACES "{"
RE_ALIAS = RE_BEGIN "#\\(" RE_SPACES RE_NAME RE_END
RE_DOC = RE_BEGIN "#" RE_SPACE RE_ANY RE_END
RE_FUNCTION = RE_BEGIN RE_NAME RE_FUNC RE_END
RE_MODULE = RE_BEGIN "#." RE_SPACES RE_NAME RE_END
RE_SET = RE_BEGIN RE_NAME "=.*" RE_END
RE_SHEBANG = RE_BEGIN "#!" RE_SPACES RE_ANY RE_END
alias = 0
reset()
module = 0
}
{
# doc
if (match($0, RE_SHEBANG, m)) {
append("shebang: " m[1])
} 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
}
# not doc
} else if (match($0, RE_MODULE, m)) {
reset()
if (m[1] == target) {
module = 1
}
} else if (match($0, RE_SET, m)) {
if (m[1] == target) {
printf "set: "
output(m[1])
} else {
reset()
}
} else if (match($0, RE_FUNCTION, m)) {
if (alias) {
print "alias: " target
printf "function: "
output(m[1])
} else if (m[1] == target) {
printf "function: "
output(target)
} else {
reset()
}
} else {
if (module) {
printf "module: "
output(target)
} else {
reset()
}
}
}

View file

@ -1,9 +1,8 @@
#! /usr/bin/env sh
# main module
# ╭──────╮
# │ main │
# ╰──────╯
# main module
# ╭──────┬───────────╮
# │ main │ constants │
@ -11,8 +10,10 @@
# name of the entrypoint file
RWX_MAIN_NAME="main.sh"
# name of the project itself
RWX_SELF_NAME="rwx"
# prefix for command functions
RWX_SELF_COMMAND="_${RWX_SELF_NAME}_cmd_"
# ╭──────┬───────────╮
@ -64,6 +65,7 @@ rwx_main() {
# ╰──────┴───────╯
# cache source code of a module
# inside a global code variable
rwx_cache() {
local root="${1}"
local module="${2}"
@ -193,6 +195,31 @@ rwx_parse_functions() {
sed --silent "s|${RWX_REGEX_TARGET_FUNCTION}|\\1|p"
}
# ╭──────┬──────╮
# │ main │ test │
# ╰──────┴──────╯
rwx_test() {
local item
# TODO CODE
# TODO CONSTANTS
# TODO functions
# TODO variables
set \
"main" \
"self" \
\
"RWX_MAIN_NAME" \
\
"rwx_cache" \
\
"gsc"
for item in "${@}"; do
echo
rwx_doc "${item}"
done
}
# ╭──────┬─────╮
# │ main │ run │
# ╰──────┴─────╯

View file

@ -1,7 +1,17 @@
# self module
# self
# module
# meta doc
rwx_doc() {
local name="${1}"
[ -n "${name}" ] || return
printf "%s" "${RWX_CODE}" |
awk \
-f "${RWX_ROOT_SYSTEM}/doc.awk" \
-v target="${name}"
}
rwx_doc_old() {
local name="${1}"
[ -n "${name}" ] || return
local constant doc func line module