diff --git a/sh/core/code.awk b/sh/core/code.awk index 0e7042c..2286f33 100644 --- a/sh/core/code.awk +++ b/sh/core/code.awk @@ -66,6 +66,21 @@ function doc_reset() { } } +# ╭──────┬───────────┬─────╮ +# │ code │ functions │ ids │ +# ╰──────┴───────────┴─────╯ + +function ids_get(type) { + return ids[type] +} + +function ids_put(type, name) { + if (ids[type]) { + ids[type] = ids[type] "\n" + } + ids[type] = ids[type] name +} + # ╭──────┬───────────┬───────╮ # │ code │ functions │ strip │ # ╰──────┴───────────┴───────╯ @@ -180,16 +195,19 @@ function parse(string) { } else if (match(string, re["constant"])) { current_match = "constant" constant = strip_value(string) + ids_put(current_match, constant) # variable } else if (match(string, re["variable"])) { current_match = "variable" variable = strip_value(string) + ids_put(current_match, variable) # alias } else if (match(string, re["alias"])) { current_match = "alias" alias = strip_first(string, "#=") + ids_put(current_match, alias) aliases[alias] = "" doc_append("= " alias) @@ -197,6 +215,7 @@ function parse(string) { } else if (match(string, re["command"])) { current_match = "command" command = strip_first(string, "#/") + ids_put(current_match, command) commands[command] = "" doc_append("/ " command) @@ -204,6 +223,7 @@ function parse(string) { } else if (match(string, re["function"])) { current_match = "function" current_function = strip_function(string) + ids_put(current_match, current_function) # task } else if (match(string, RE_TASK)) { @@ -357,12 +377,6 @@ if (action == "doc") { doc_reset() } -# filter -} else if (action == "filter") { - if (match($0, re[target])) { - unique[extract($0, target)] = "" - } - # lint } else if (action == "lint") { parse($0) @@ -380,6 +394,10 @@ if (action == "doc") { # TODO unique command # TODO unique function +# filter +} else if (action == "filter") { + parse($0) + # unknown } else { print "unknown action: " action @@ -436,9 +454,7 @@ END { # filter if (action == "filter") { - for (item in unique) { - print item - } + print ids_get(target) # lint } else if (action == "lint") {