Compare commits
4 commits
6ba73ec573
...
918ed255f7
Author | SHA1 | Date | |
---|---|---|---|
918ed255f7 | |||
3216f11da0 | |||
96ea65e3da | |||
d377bcea37 |
3 changed files with 89 additions and 1 deletions
77
sh/doc.awk
Normal file
77
sh/doc.awk
Normal file
|
@ -0,0 +1,77 @@
|
|||
function append(line) {
|
||||
if (doc) {
|
||||
doc = doc "\n"
|
||||
}
|
||||
doc = doc line
|
||||
}
|
||||
|
||||
function output(name) {
|
||||
print name
|
||||
print "↓"
|
||||
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
|
||||
}
|
||||
|
||||
{
|
||||
if (match($0, RE_MODULE, m)) {
|
||||
reset()
|
||||
if (m[1] == target) {
|
||||
module = 1
|
||||
}
|
||||
} else if (match($0, RE_SHEBANG, m)) {
|
||||
append(m[1])
|
||||
} else if (match($0, RE_DOC, m)) {
|
||||
append(m[1])
|
||||
} else if (match($0, RE_SET, m)) {
|
||||
if (m[1] == target) {
|
||||
output(m[1])
|
||||
} else {
|
||||
reset()
|
||||
}
|
||||
} else if (match($0, RE_ALIAS, m)) {
|
||||
if (m[1] == target) {
|
||||
alias = 1
|
||||
}
|
||||
append(m[1])
|
||||
} else if (match($0, RE_FUNCTION, m)) {
|
||||
if (alias) {
|
||||
output(m[1])
|
||||
} else if (m[1] == target) {
|
||||
output(m[1])
|
||||
} else {
|
||||
reset()
|
||||
}
|
||||
} else {
|
||||
if (module) {
|
||||
output(target)
|
||||
} else {
|
||||
reset()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -64,6 +64,7 @@ rwx_main() {
|
|||
# ╰──────┴───────╯
|
||||
|
||||
# cache source code of a module
|
||||
# inside a global code variable
|
||||
rwx_cache() {
|
||||
local root="${1}"
|
||||
local module="${2}"
|
||||
|
|
12
sh/self.sh
12
sh/self.sh
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue