Repository navigation
lexer: read / after a built-in variable as division - #143
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
| fn slash_after_special_variable_divides() { | ||
| ucmd() | ||
| .arg("{ print NR / 2, NF/NR } END { RSTART = 8; print RSTART / 2 / 2 }") | ||
| .pipe_in("a b\nc d\n") |
There was a problem hiding this comment.
could you please also cover NR /= 2 here?
and maybe add NR/=1 to lexer_test_regex_ambiguity in lexer/src/tests.rs
There was a problem hiding this comment.
Added both in f15885c: NR /= 2 in slash_after_special_variable_divides, and NR/=1 in lexer_test_regex_ambiguity (it fails on main, where /=1 starts a regex). The test sets NR first (NR = 6; NR /= 2), because on main NR in END after a file is still 0 (#140), and gawk keeps NR an integer, so NR /= 2 in a main rule truncates there.
|
sorry, needs to be rebased! |
54cc70b to
a2dd734
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
Thanks for your PR |
Every built-in variable token (
NR,NF,FNR,RSTART, ...) sets the lexer to expect an expression, so a/after one starts a regex. gawk 5.3.2 vs main:The second one parses as
RSTARTconcatenated with the regex/ 2, RLENGTH /, so it prints a wrong number with no error.x / 2with a user variable already works.The built-in variables are operands, so their tokens now use
accept_operator, like identifiers.ARGINDhad no callback and gets the same.New test
slash_after_special_variable_dividesfails without the change.cargo test --workspace: 211 passed (210 on main plus the new one), clippy and fmt clean. 15 programs with/and/=afterNR,NF,FNR,RSTART,RLENGTHandARGC, and regexes afterNR ~andNR,, give the same result as gawk apart from two that differ for other reasons (ARGC's value,NRin an END-only program, which #140 fixes).