Skip to content

parser: read the rest of a print list after a parenthesized first expression - #147

Merged
Alonely0 merged 1 commit into
uutils:mainfrom
jayhemnani9910:fix/print-parenthesized-first-argument
Oct 26, 2026
Merged

Alonely0 merged 1 commit into
uutils:mainfrom
jayhemnani9910:fix/print-parenthesized-first-argument

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

print whose first argument starts with a parenthesized expression and goes on ((x) + 1, (x) "str", (x) ? a : b) fails when more arguments follow:

$ echo 'x y' | awk '{ print ($1) "-", $2 }'
Error: Syntax error
$ awk 'BEGIN { print (1) + 1, 2 }'
Error: Syntax error

gawk 5.3.2 prints x- y and 2 2. Without the comma (print (1) + 1) it already works.

parse_command folds the rest of the first expression with fold_rhs and then calls parse_command_args, which only starts at an expression, so the comma before the next argument was left over and ended the statement. The comma is now consumed first, like the print (a, b) in arr, ... branch does, with the same "Expected next argument!" error for a trailing comma. print (1,2), 3 is still rejected (CommandDoubleCall), as in gawk.

Test print_list_after_a_parenthesized_first_expression (fails on main). cargo test --workspace: 219 pass (218 on main), clippy clean. Thirteen print forms around this (ternary, concatenation, arithmetic, in, trailing comma, (a,b), c) give gawk's output or, where gawk errors, an error.

Copilot AI balanced review requested due to automatic review settings October 26, 2026 03:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Alonely0 Alonely0 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of the greatest pain points in AWK's grammar. Thanks for the fix!

Solve the review comment whenever you have a moment and we can merge this.

Comment thread tests/by-util/test_awk.rs
…ression

'print ($1) "-", $2' failed: after folding the first expression the
comma before the next argument was left unparsed.
@jayhemnani9910
jayhemnani9910 force-pushed the fix/print-parenthesized-first-argument branch from ce04776 to 3c0bcba Compare October 26, 2026 15:10
Copilot AI balanced review requested due to automatic review settings October 26, 2026 15:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Alonely0
Alonely0 merged commit d8ed26b into uutils:main Oct 26, 2026
15 checks passed
@Alonely0

Copy link
Copy Markdown
Collaborator

Thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants