parse/tasks

This commit is contained in:
Marc Beninca 2025-08-02 21:49:07 +02:00
parent 8caa6e6795
commit 7d8e9a03e2
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

View file

@ -76,11 +76,15 @@ function strip_from(string, sep, tmp) {
return strip(tmp[1])
}
function strip_function(string, tmp) {
function strip_function(string) {
return strip_from(string, "(")
}
function strip_value(string, tmp) {
function strip_task(string) {
return strip_from(strip_first(string, "#"), " ")
}
function strip_value(string) {
return strip_from(string, "=")
}
@ -104,17 +108,15 @@ re["alias"] = RE_BEGIN "#=" RE_SPACES RE_VAR RE_END
re["binary"] = RE_BEGIN "#\\|" RE_SPACES RE_VAR RE_END
RE_CLOSE = RE_BEGIN "}" RE_SPACES RE_END
re["command"] = RE_BEGIN "#/" RE_SPACES RE_VAR RE_END
RE_COMMENT = RE_BEGIN "#" RE_ANY RE_END
RE_COMMENT = RE_BEGIN RE_SPACES "# " RE_ANY RE_END
re["constant"] = RE_BEGIN RE_CONST RE_SET RE_END
RE_DOC = RE_BEGIN RE_SPACES "#" RE_SPACE RE_ANY RE_END
RE_DOC = RE_BEGIN "# " RE_ANY RE_END
re["function"] = RE_BEGIN RE_VAR RE_FUNC RE_END
RE_MODULE = RE_BEGIN "#\\." RE_SPACES RE_ANY RE_END
RE_SHEBANG = RE_BEGIN "#!" RE_SPACES RE_ANY RE_END
RE_TASK = RE_BEGIN RE_SPACES "#" RE_SPACES RE_TSK RE_ANY RE_END
re["variable"] = RE_BEGIN RE_VAR RE_SET RE_END
match_task = 0
# ← begin
}
@ -163,13 +165,20 @@ function parse(string) {
current_match = "function"
current_function = strip_function(string)
# task
} else if (match(string, RE_TASK)) {
current_match = "task"
task = strip_task(string)
tasks[task] = ""
doc_append(line ": " string)
# doc
} else if (match(string, RE_DOC)) {
if (current_function) {
doc_append(string)
} else {
doc_append(strip_first(string, "# "))
}
# comment
} else if (match(string, RE_COMMENT)) {
doc_append(string)
# other
} else {
@ -232,35 +241,37 @@ if (action == "doc") {
# tasks
} else if (action == "tasks") {
line++
if (match($0, RE_MODULE)) {
line = 1
parse($0)
# module
if (current_match == "module") {
if (output_tasks) {
print ""
print output_module
print ". " module
print output_tasks
output_tasks = ""
}
doc = ""
match_task = 0
output_module = ". " extract($0, "module")
} else if (match($0, RE_TASK)) {
# task
} else if (current_match == "task") {
if (target) {
if (target == extract($0, "task")) {
if (target in tasks) {
match_task = 1
}
} else {
match_task = 1
}
doc_append(line ": " $0)
} else if (match($0, RE_COMMENT)) {
doc_append(line ": " $0)
# other
} else {
if (match_task) {
output_tasks = output_tasks "\n" doc
}
doc = ""
match_task = 0
}
# function