Skip to content

syntax: materialize grouped alternation in pattern contexts - #800

Merged
ewhauser merged 3 commits into
mainfrom
ewhauser/pattern-group-alternation
Mar 30, 2026
Merged

ewhauser merged 3 commits into
mainfrom
ewhauser/pattern-group-alternation

Conversation

@ewhauser

Copy link
Copy Markdown
Owner

Summary

  • add a public PatternGroup AST node for bare grouped alternation in pattern contexts
  • materialize grouped alternation in [[ == ]]/[[ = ]]/[[ != ]] and case patterns, with recovery that preserves enclosing AST nodes
  • expose typed parse metadata for pattern-context ( failures and update printer, fidelity, typedjson, expand, docs, and tests

Root cause

Grouped alternation in pattern contexts was being treated as token-level syntax noise instead of a structured pattern construct. That prevented gbash from materializing the surrounding TestClause, CaseClause, and IfClause in recovery cases and forced downstream consumers to fall back to raw line scans.

Impact

This gives analyzers a real AST node for zsh grouped alternation and a typed, recoverable failure shape for bash-like parses. It removes the need for line-scan fallbacks in the affected pattern checks and keeps surrounding syntax trees available under RecoverErrors.

Validation

  • go test ./shell/syntax
  • go test ./shell/syntax/typedjson
  • go test ./shell/expand

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6f094d7b01

ℹ️ 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".

Comment thread shell/syntax/parser.go Resolved
Comment thread shell/syntax/parser.go Resolved
@ewhauser
ewhauser force-pushed the ewhauser/pattern-group-alternation branch from 6f094d7 to ffe01bb Compare March 30, 2026 14:33

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ffe01bb5b3

ℹ️ 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".

Comment thread shell/syntax/parser.go Resolved
@ewhauser
ewhauser force-pushed the ewhauser/pattern-group-alternation branch from 8bf3d73 to 39f3b54 Compare March 30, 2026 14:44

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 39f3b543fd

ℹ️ 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".

Comment thread shell/syntax/parser.go Resolved
@ewhauser
ewhauser merged commit 3fdd8c7 into main Mar 30, 2026
16 checks passed
@ewhauser
ewhauser deleted the ewhauser/pattern-group-alternation branch March 30, 2026 15:04

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8e7f907bba

ℹ️ 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".

Comment thread shell/syntax/parser.go
Comment on lines +3606 to +3610
group, end, ok := r.parsePatternGroup(raw, base, i)
if end > i {
if ok {
flushLit(partStart, i)
parts = append(parts, group)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Restrict PatternGroup parsing in extglob arm literals

parseParts now materializes any parenthesized alternation as PatternGroup, even when parsing an extglob arm. In bash/ksh pattern syntax, parentheses inside extglob arms are literal unless introduced by an extglob operator, so inputs like [[ "(a|b)" == @(x|(a|b)) ]] (and equivalent case patterns) are valid. After this change, the (a|b) arm is turned into PatternGroup, and the new bare-group validation in followCondPattern/caseItems rejects it as an unexpected ( in non-zsh variants, causing valid scripts to fail parsing.

Useful? React with 👍 / 👎.

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.

1 participant