attempt from scratch
This commit is contained in:
parent
96ea65e3da
commit
3216f11da0
3 changed files with 76 additions and 1 deletions
73
sh/doc.awk
73
sh/doc.awk
|
@ -0,0 +1,73 @@
|
|||
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 {
|
||||
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}"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# self module
|
||||
# self
|
||||
# module
|
||||
|
||||
# meta doc
|
||||
rwx_doc() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue