[codex] Add comma-disambiguated array literals#20
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds comma-disambiguated array literal construction ([a, b]) to the Shorthand query language while preserving existing bracket semantics for root indexing/slicing/filtering/flattening, and extends support to object field expressions with improved error offset reporting.
Changes:
- Extend
GetPathparsing to support array literals at the start of a query / field value when the bracket body contains a top-level comma. - Add parsing + evaluation helpers for array literal elements and rebase nested-expression errors to original query offsets.
- Document the disambiguation rule and add comprehensive compatibility and edge-case tests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| README.md | Documents array construction and the comma-disambiguation rule; adds usage examples. |
| get.go | Implements array literal detection/parsing, nested error rebasing, and integrates the feature into path evaluation. |
| get_test.go | Adds tests for root-bracket compatibility, nested usage in fields, quoting/commas, and malformed literal cases. |
Comments suppressed due to low confidence (2)
get.go:55
GetPathonly passesallowArrayLiteral=truefor the very first pipe segment (it’s set tofalsefor all subsequent segments). This means array literals won’t be recognized at the start of a post-pipe segment (e.g.users|[id, name]), which may conflict with the README wording about “beginning of a query”. Consider resetting the flag after consuming|(treat each pipe segment as a query start) or updating documentation/tests to reflect the intended limitation.
value, ok := c.entries[key]
return value, ok
}
func (c *boundedConcurrentCache) LoadOrStore(key string, value any) (any, bool) {
c.mu.Lock()
defer c.mu.Unlock()
if cached, ok := c.entries[key]; ok {
return cached, true
get.go:719
- In
getFields, the bracket fast-path callsparseUntilNoReset(1)but ignores the returned error. If there’s an unterminated quoted string (or other parsing error) inside the bracket expression, it will be silently swallowed and likely produce confusing downstream errors. Capture and return the error fromparseUntilNoResethere.
if indexes[1] == "" {
indexes[1] = "-1"
}
if stopIndex, err := strconv.Atoi(indexes[1]); err == nil {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
Adds array construction to shorthand queries while preserving existing bracket behavior for indexing, slicing, filtering, and flattening.
Array literals are intentionally comma-disambiguated: construction is supported at the beginning of a query or object field value only when the bracket body contains a top-level comma. Empty and single-element array construction remain unsupported so existing root bracket operations such as
[],[0],[:1], and filters continue to behave as before.Changes
GetPath.Validation
env GOCACHE=/tmp/shorthand-gocache go test ./... -count=1