Skip to content

adds typed metadata to shell/syntax.ParseError - #790

Merged
ewhauser merged 2 commits into
mainfrom
ewhauser/typed-parse-error-metadata
Mar 30, 2026
Merged

ewhauser merged 2 commits into
mainfrom
ewhauser/typed-parse-error-metadata

Conversation

@ewhauser

Copy link
Copy Markdown
Owner

Summary

This change adds typed metadata to shell/syntax.ParseError so callers can inspect parse failures without scraping diagnostic text.

What changed

  • add exported ParseErrorKind and ParseErrorSymbol types and expose Kind, Construct, Unexpected, Expected, and IsRecoverable on ParseError
  • populate parse-error metadata through the existing parser recovery/error helpers instead of introducing new AST nodes
  • preserve existing Text, Error(), BashError(), and Recoverable() behavior while keeping compound recovery on recovered positions and existing clause token slots
  • migrate internal consumers in interactive parsing, chunked parsing, deferred backquote handling, and arithmetic/parameter expansion away from ParseError.Text string matching
  • add parser, public API, expand, and internal tests for missing compound tokens, unclosed delimiters/heredocs, recoverable cases, and metadata-driven consumers
  • document the public ParseError metadata surface in SPEC.md

Why

The parser already recovers compound-command structure through recovered positions and existing node fields, but ParseError only exposed stringly diagnostics. This left downstream consumers parsing Text to decide whether an error was missing, unexpected, unclosed, recoverable, or tied to a specific shell construct. The new metadata makes that API stable without changing the AST recovery model.

Validation

  • make lint
  • go test ./shell/syntax
  • go test ./shell/expand
  • go test ./internal/shell ./internal/shell/interp
  • go test ./... except for the existing oracle-backed failures in internal/builtins when GBASH_CONFORMANCE_RIPGREP and GBASH_CONFORMANCE_DIFF are not set in the environment

@ewhauser
ewhauser marked this pull request as ready for review March 30, 2026 02:36
@ewhauser ewhauser changed the title [codex] syntax: add typed parse error metadata [codex] Mar 30, 2026
@ewhauser ewhauser changed the title [codex] adds typed metadata to shell/syntax.ParseError Mar 30, 2026

@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: 3824cec38d

ℹ️ 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 +2403 to +2404
case ParseErrorKindUnmatched:
return len(err.Expected) == 1 && err.Expected[0] == ParseErrorSymbolRightBrace && err.Construct == ParseErrorSymbolLeftBrace

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Treat EOF unmatched { as recoverable in backquotes

parseErrRecoverableInBackquotes now only treats brace mismatches as recoverable when Kind == ParseErrorKindUnmatched, but matchingErr classifies the same {/} mismatch as ParseErrorKindUnclosed whenever the unexpected token is EOF (via missingCloseKind). That means EOF-terminated brace mismatches in backquote parsing no longer enter the recovery path (recoverBackquoteCmdSubst), so malformed backquotes that were previously recoverable can now abort parsing instead of letting outer script parsing continue.

Useful? React with 👍 / 👎.

@ewhauser
ewhauser merged commit 60b36e9 into main Mar 30, 2026
16 checks passed
@ewhauser
ewhauser deleted the ewhauser/typed-parse-error-metadata branch March 30, 2026 02:54
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