Skip to content

parser: read length without parentheses as length($0) - #144

Merged
Alonely0 merged 2 commits into
uutils:mainfrom
jayhemnani9910:fix/bare-length
Oct 25, 2026
Merged

Alonely0 merged 2 commits into
uutils:mainfrom
jayhemnani9910:fix/bare-length

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

POSIX allows length without an argument list, meaning length($0). main only accepts length(...), so the common one-liner fails:

$ printf 'ab\nabcd\n' | awk 'length > 3'
gawk: abcd
main: Error: Syntax error

{ n += length }, print length, length { ... } and x = length fail the same way.

parse_atom_or_call now builds length with no arguments when no ( follows; the interpreter already treats that as length($0). The lexer gives length accept_operator, so length / 2 divides; length(/re/) is unchanged because ( resets the context.

New test length_without_parentheses_is_length_of_record fails without the change. cargo test --workspace: 211 passed (210 on main plus the new one), clippy and fmt clean. 18 forms (length > 3, length "x", length $1, length / 2, length - 1, length ~ /1/, length ($1), length(/a/), length at the end of a line, ...) print the same as gawk.

Copilot AI balanced review requested due to automatic review settings October 24, 2026 07:20

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.

Comment thread tests/by-util/test_awk.rs
#[test]
fn length_without_parentheses_is_length_of_record() {
ucmd()
.arg("length > 2 { print length, length / 2 } BEGIN { print length }")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could you please also cover length(/b/) and length $1 here?
the lexer change makes sure these keep working

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added in f78f1fb: { print length(/b/), length $1 } on abc def and xyz gives 1 7abc and 1 3xyz, the same as gawk 5.3.2 (length $1 is length followed by $1, concatenated).

@Alonely0

Copy link
Copy Markdown
Collaborator

sorry, needs to be rebased!

Copilot AI balanced review requested due to automatic review settings October 24, 2026 16:45

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.

Copilot AI balanced review requested due to automatic review settings October 24, 2026 18:46

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.

Copilot AI balanced review requested due to automatic review settings October 25, 2026 10:25

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.

Good catch! Address the trivial conflicts on the test file whenever you have a moment, and we can merge this right away.

Copilot AI balanced review requested due to automatic review settings October 25, 2026 14:43

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 71bea18 into uutils:main Oct 25, 2026
15 checks passed
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.

4 participants