ezrosent/frawk

When using archimetric operators in print, strings are ignored

ghuls opened this issue · 3 comments

ghuls commented

When using archimetric operators in print, strings are ignored (or converted to 0).

❯ frawk 'BEGIN { print "test" 6}'
test6

# Should print "test11"
❯ frawk 'BEGIN { print "test" 6 + 5 }'
5

❯ frawk 'BEGIN { print "test" (6 + 5) }'
test11

❯ frawk 'BEGIN { print 6 "test" }'
6test

# Should print "11test"
❯ frawk 'BEGIN { print 6 + 5 "test" }'
11

❯ frawk 'BEGIN { print (6 + 5) "test" }'
11test

Oh nice, thanks! This looks like an operator precedence issue. In Awk, 6 + 5 "test" gets parsed at (6 + 5) "test" but frawk is doing 6 + (5 "test").

I'll take a look.

ghuls commented

Another error I just encountered (division seen as part of a regex):

❯ frawk 'BEGIN { t_array[0] = 5; t = 6; print "test/test\t" (t_array[0] + t); }'
test/test	11

❯ frawk 'BEGIN { t_array[0] = 5; t = 6; print "test/test\t" (t_array[0] * t); }'
test/test	30

❯ frawk 'BEGIN { t_array[0] = 5; t = 6; print "test/test\t" (t_array[0] / t); }'
line 1, column 65. incomplete regex literal

In the original script if gave a different error:

Unrecognized EOF found at line 41, column 81
Expected one of "\n", "!=", "!~", "$", "%", "%=", "&&", "(", ")", "*", "*=", "+", "++", "+=", ",", "-", "--", "-=", "/", "/=", ":", ";", "<", "<=", "=", "==", ">", ">=", ">>", "?", "CALLSTART", "FLOAT", "HEX", "IDENT", "INT", "PATLIT", "STRLIT", "[", "]", "^", "^=", "in", "{", "|", "||", "}" or "~"

Quick update here, I should have a fix for the division issue soon, but I think I'll have to do a larger rewrite of the parser to fix the first concatenation issue. At the very least, it's not a quick fix. I'll be sure fix #49 as well when I get around to that.