diff --git a/sh/core/code.awk b/sh/core/code.awk index ca712ae..e7cc470 100644 --- a/sh/core/code.awk +++ b/sh/core/code.awk @@ -64,6 +64,11 @@ function remove_first(string, target, tmp) { return trim(tmp) } +function strip_value(string, tmp) { + split(string, tmp, "=") + return trim(tmp[1]) +} + function trim(string) { text = string sub("^[\t ]*", "", text) @@ -121,6 +126,16 @@ function parse(string) { current_match = "shebang" shebang = remove_first(string, "#!") + # constant + } else if (match(string, re["constant"])) { + current_match = "constant" + constant = strip_value(string) + + # variable + } else if (match(string, re["variable"])) { + current_match = "variable" + variable = strip_value(string) + # alias } else if (match(string, re["alias"])) { current_match = "alias" @@ -159,20 +174,21 @@ if (action == "doc") { } else { doc_append(extract($0, "doc")) } - # set - } else if (match($0, re["constant"])) { - matched = extract($0, "constant") - if (matched == target) { - doc_output(matched, "constant") + # constant + } else if (current_match == "constant") { + if (constant == target) { + doc_output(constant, "constant") } else { doc_reset() + constant = "" } - } else if (match($0, re["variable"])) { - matched = extract($0, "variable") - if (matched == target) { - doc_output(matched, "variable") + # variable + } else if (current_match == "variable") { + if (variable == target) { + doc_output(variable, "variable") } else { doc_reset() + variable = "" } # others } else if (match($0, re["function"])) {