Repository navigation
Accept the in operator in a compiled expression - #686
Open
bertysentry wants to merge 1 commit into
Open
bertysentry wants to merge 1 commit into
bertysentry wants to merge 1 commit into
Conversation
`Awk.compileExpression()` and `Awk.eval()` parsed the expression with
`allowInKeyword` set to false, so `$1 in arr`, `("a" in arr) ? 1 : 0`
and `(i, j) in arr` failed with a ParserException, also inside
parentheses. That flag is only meant for the first expression of a
`for (...)` statement, and an expression to evaluate has no such
ambiguity.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012oN698ZmgRVZHEQxfFpf9h
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #685.
Problem
Awk.compileExpression()andAwk.eval()refused theinoperator everywhere in an expression, also inside parentheses:$1 in arr,("a" in arr) ? 1 : 0,!("PATH" in ENVIRON)and(1, 2) in arrall failed with aParserException, while a program accepts them.Fix
AwkParser.EXPRESSION_TO_EVALUATE()parsed the expression withallowInKeywordset tofalse. That flag is only meant for the first expression of afor (...)statement, so thatfor (key in arr)is left to theforproduction. An expression to evaluate has no such ambiguity, so it is now parsed withallowInKeywordset totrue. That is the whole change insrc/main.Tests
AwkEvalTest:key in arrand(key in arr)on an array passed in the variables, inside a larger expression (ternary, arithmetic, concatenation,&&,||), negated, the multi-dimensional form(i, j) in arr, on anENVIRONpassed by the host (regular and sandboxed), on an array never assigned, without optimization, and a check thatindoes not create the element.(1, 2)withoutin,"a" inandin arrare still refused.AwkTest:inon theENVIRONof the process, and on the emptyENVIRONof aSandboxedAwk.AwkExpressionTest: aninexpression is not reported as constant.Documentation
java-compile.md.Unreleasedinbehavior-changes.md.Notes
x = 1) is still refused, as noted in the "Related" section of the issue. It comes from the same entry point but may be intended, so it is left for a separate decision.mvn clean verify sitepasses: 1029 unit tests (1019 before), 0 Checkstyle, PMD and SpotBugs issues. The gawk compatibility tests report the same 129 failing tests with and without this change in my environment (they are not blocking,testFailureIgnore).Generated by Claude Code