Add optional gawk-style arrays of arrays (a[i][j])#439
Conversation
- Add allowArraysOfArrays to AwkSettings (default: true) - Thread the flag into Awk.compile() and Awk.compileExpression() - Update AwkParser to parse chained-bracket syntax a[i][j] when enabled - Introduce new opcodes for nested array lvalue operations - Extend AVM to execute nested-array tuples at runtime - Cover reads, writes, in, for-in, delete, ++/--, compound assignment - Add regression tests in AwkTest and AwkParserTest - Update documentation (README, compatibility.md, java.md, java-compile.md) Closes #438
There was a problem hiding this comment.
Pull request overview
Adds optional (default-enabled) support for gawk-style “arrays of arrays” syntax (a[i][j]) across the Jawk compiler and runtime, including parser acceptance, new tuple opcodes, and AVM execution, with accompanying regression and documentation updates.
Changes:
- Introduces
AwkSettings.allowArraysOfArraysand threads it into compilation so the parser can accept/reject chained-bracket syntax. - Extends
AwkParser, tuples/opcodes, andAVMto support nested-array reads/writes and array-valued operations on subarrays. - Expands test coverage (including parser-rejection when disabled) and updates site docs; enables additional POSIX conformance tests by implementing
length(array).
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/io/jawk/util/AwkSettings.java | Adds allowArraysOfArrays compile-time flag and exposes it via API/diagnostics. |
| src/main/java/io/jawk/Awk.java | Passes allowArraysOfArrays into AwkParser during compilation/expression compilation. |
| src/main/java/io/jawk/frontend/AwkParser.java | Parses chained brackets when enabled; updates tuple generation to support subarrays in in, for-in, delete, assignment, built-ins, and function params. |
| src/main/java/io/jawk/intermediate/Opcode.java | Adds new opcodes to operate on stack-provided map elements and nested-array creation. |
| src/main/java/io/jawk/intermediate/AwkTuples.java | Adds tuple emission helpers for the new map-element opcodes. |
| src/main/java/io/jawk/backend/AVM.java | Implements execution for new opcodes; adds length(array) behavior and scalar/array context checks. |
| src/test/java/io/jawk/AwkTest.java | Adds behavior-based regression tests covering nested array semantics and key runtime paths. |
| src/test/java/io/jawk/AwkParserTest.java | Adds test ensuring chained-bracket syntax is rejected when allowArraysOfArrays is disabled. |
| src/test/java/io/jawk/PosixConformanceTest.java | Enables POSIX tests that rely on length(array) by removing prior assumptions. |
| src/site/markdown/java.md | Documents the new AwkSettings.setAllowArraysOfArrays(...) option and default behavior. |
| src/site/markdown/java-compile.md | Documents that compilation settings affect accepted syntax; shows disabling arrays-of-arrays before compiling. |
| src/site/markdown/compatibility.md | Notes support for arrays-of-arrays alongside classic SUBSEP multidimensional arrays. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
jawk/src/main/java/io/jawk/frontend/AwkParser.java
Lines 4397 to 4400 in ff4cd66
This rvalue path dereferences nested arrays via getAst1().populateTuples()/dereferenceArray() without creating an intermediate subarray, so print a[1][2] on an unset a[1] ends up dereferencing a blank scalar as an array at runtime. That is inconsistent with the new gawk-style arrays-of-arrays behavior (and with this patch’s write-side autovivification), causing nested reads on previously unset parents to fail unexpectedly.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Closes #438
Summary
This PR adds support for optional gawk-style arrays of arrays (
a[i][j]) as described in issue #438.Changes
AwkSettingsallowArraysOfArraysfield (default:true) to enable/disable chained-bracket syntax at compile time.AwkallowArraysOfArrayssetting intoAwkParserviacompile()andcompileExpression().AwkParserallowArraysOfArraysis enabled, parse chained-bracket expressions (a[i][j],a[i][j][k], mixed forms likea[i][j,k]) instead of throwing an error.SUBSEP(unchanged behavior).Opcode/AwkTuplesin,for-in,delete,++/--, and compound assignment on nested arrays.AVMMap-based infrastructure.Behavior
a[1][2] = 42; print a[1][2]42a[1][2,3] = 42; print a[1][2,3]SUBSEPa[1,2] = 42; print a[1,2]2 in a[1]for (k in a[1])delete a[1][2]allowArraysOfArrays = false+a[1][2]Tests
AwkTestcovering the acceptance criteria from the issue.AwkParserTestfor when the flag is disabled.Documentation
README.md,compatibility.md,java.md, andjava-compile.md.