strip_value

This commit is contained in:
Marc Beninca 2025-08-02 17:50:04 +02:00
parent 1e1a2f1c6e
commit 9bda167820
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

View file

@ -64,6 +64,11 @@ function remove_first(string, target, tmp) {
return trim(tmp) return trim(tmp)
} }
function strip_value(string, tmp) {
split(string, tmp, "=")
return trim(tmp[1])
}
function trim(string) { function trim(string) {
text = string text = string
sub("^[\t ]*", "", text) sub("^[\t ]*", "", text)
@ -121,6 +126,16 @@ function parse(string) {
current_match = "shebang" current_match = "shebang"
shebang = remove_first(string, "#!") 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 # alias
} else if (match(string, re["alias"])) { } else if (match(string, re["alias"])) {
current_match = "alias" current_match = "alias"
@ -159,20 +174,21 @@ if (action == "doc") {
} else { } else {
doc_append(extract($0, "doc")) doc_append(extract($0, "doc"))
} }
# set # constant
} else if (match($0, re["constant"])) { } else if (current_match == "constant") {
matched = extract($0, "constant") if (constant == target) {
if (matched == target) { doc_output(constant, "constant")
doc_output(matched, "constant")
} else { } else {
doc_reset() doc_reset()
constant = ""
} }
} else if (match($0, re["variable"])) { # variable
matched = extract($0, "variable") } else if (current_match == "variable") {
if (matched == target) { if (variable == target) {
doc_output(matched, "variable") doc_output(variable, "variable")
} else { } else {
doc_reset() doc_reset()
variable = ""
} }
# others # others
} else if (match($0, re["function"])) { } else if (match($0, re["function"])) {