summaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorDenys Vlasenko2021-06-29 12:16:36 +0200
committerDenys Vlasenko2021-06-29 12:16:36 +0200
commit6872c193a935df47facf717c15a32f93b43c6bcf (patch)
tree6710abc0886289331f56a36a983389d7a18b2fc4 /editors
parent686287b5da98508dd03fb295745c82d00440131e (diff)
downloadbusybox-6872c193a935df47facf717c15a32f93b43c6bcf.zip
busybox-6872c193a935df47facf717c15a32f93b43c6bcf.tar.gz
awk: fix parsing of expressions such as "v (a)"
function old new delta next_token 812 825 +13 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors')
-rw-r--r--editors/awk.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/editors/awk.c b/editors/awk.c
index 34bcc17..ce860dc 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -1231,11 +1231,24 @@ static uint32_t next_token(uint32_t expected)
while (isalnum_(*p))
p++;
end_of_name = p;
- tc = TC_VARIABLE;
- /* also consume whitespace between functionname and bracket */
- if (!(expected & TC_VARIABLE) || (expected & TC_ARRAY))
-//TODO: why if variable can be here (but not array ref), skipping is not allowed? Example where it matters?
+
+ if (last_token_class == TC_FUNCDECL)
+ /* eat space in "function FUNC (...) {...}" declaration */
p = skip_spaces(p);
+ else if (expected & TC_ARRAY) {
+ /* eat space between array name and [ */
+ char *s = skip_spaces(p);
+ if (*s == '[') /* array ref, not just a name? */
+ p = s;
+ }
+ /* else: do NOT consume whitespace after variable name!
+ * gawk allows definition "function FUNC (p) {...}" - note space,
+ * but disallows the call "FUNC (p)" because it isn't one -
+ * expression "v (a)" should NOT be parsed as TC_FUNCTION:
+ * it is a valid concatenation if "v" is a variable,
+ * not a function name (and type of name is not known at parse time).
+ */
+
if (*p == '(') {
p++;
tc = TC_FUNCTION;
@@ -1245,6 +1258,7 @@ static uint32_t next_token(uint32_t expected)
tc = TC_ARRAY;
debug_printf_parse("%s: token found:'%s' TC_ARRAY\n", __func__, t_string);
} else {
+ tc = TC_VARIABLE;
debug_printf_parse("%s: token found:'%s' TC_VARIABLE\n", __func__, t_string);
if (end_of_name == p) {
/* there is no space for trailing NUL in t_string!