Skip to content

[codex] Add comma-disambiguated array literals#20

Merged
danielgtaylor merged 2 commits into
mainfrom
codex/array-literals-top-level-comma
May 8, 2026
Merged

[codex] Add comma-disambiguated array literals#20
danielgtaylor merged 2 commits into
mainfrom
codex/array-literals-top-level-comma

Conversation

@danielgtaylor

Copy link
Copy Markdown
Owner

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

  • Parse comma-disambiguated array literals in GetPath.
  • Preserve root bracket index/slice/filter/flatten compatibility.
  • Support array literals inside object field expressions, including piped elements and nested projections.
  • Rebase nested expression errors so offsets point back to the original query.
  • Document the array construction rule in the README.
  • Add tests for compatibility, nesting, missing values, malformed literals, quoted commas, and function-call commas.

Validation

  • env GOCACHE=/tmp/shorthand-gocache go test ./... -count=1

@danielgtaylor danielgtaylor requested a review from Copilot May 5, 2026 06:26
@danielgtaylor danielgtaylor marked this pull request as ready for review May 5, 2026 06:26

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.

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 GetPath parsing 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

  • GetPath only passes allowArrayLiteral=true for the very first pipe segment (it’s set to false for 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 calls parseUntilNoReset(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 from parseUntilNoReset here.
				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.

@danielgtaylor danielgtaylor merged commit 614f784 into main May 8, 2026
2 checks passed
@danielgtaylor danielgtaylor deleted the codex/array-literals-top-level-comma branch May 8, 2026 01:04
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.

2 participants