Skip to content

preserve heredoc closer metadata - #791

Merged
ewhauser merged 2 commits into
mainfrom
ewhauser/heredoc-closer-metadata
Mar 30, 2026
Merged

ewhauser merged 2 commits into
mainfrom
ewhauser/heredoc-closer-metadata

Conversation

@ewhauser

Copy link
Copy Markdown
Owner

Summary

Preserve here-doc closer metadata on shell/syntax.HeredocDelim so the AST keeps the final close-site instead of only the normalized opener metadata and body text.

What Changed

  • add closer-facing fields to HeredocDelim, including close positions, raw close text, match state, EOF termination, trailing text, and <<- indent results
  • thread closer capture through the heredoc matcher in the parser/lexer without changing existing Pos()/End() behavior or printer output
  • keep partial heredoc statements available on parse errors so callers can inspect closer metadata even for unterminated heredocs
  • extend heredoc parser/file tests and typedjson coverage, and document the public AST addition in SPEC.md

Why

The parser already matches heredoc close lines during lexing, but the AST discarded that information after body parsing. This left an upstream metadata hole for tooling that needs to inspect the actual close site, especially for unmatched or near-match heredocs.

Impact

External shell/syntax consumers can now inspect the physical heredoc closer candidate directly, including EOF termination and tab-stripping details for <<-, without changing printer behavior or redirect span semantics.

Validation

  • go test ./shell/syntax ./shell/syntax/typedjson
  • make lint

@ewhauser ewhauser changed the title [codex] preserve heredoc closer metadata preserve heredoc closer metadata Mar 30, 2026
@ewhauser
ewhauser marked this pull request as ready for review March 30, 2026 02:37

@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: 574806384a

ℹ️ 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/heredoc-closer-metadata branch from eae2073 to b0040d0 Compare March 30, 2026 03:04
@ewhauser
ewhauser merged commit 9161994 into main Mar 30, 2026
16 checks passed
@ewhauser
ewhauser deleted the ewhauser/heredoc-closer-metadata branch March 30, 2026 03:11

@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: b0040d0b56

ℹ️ 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 +5007 to +5010
if s = p.gotStmtPipe(s, false); s == nil {
return nil
}
if p.err != nil && !stmtHasHeredocMetadata(s) {

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 Stop parsing after returning a heredoc-error statement

The new guard in getStmt keeps going when p.err is set if stmtHasHeredocMetadata(s) is true, but stmts only stops when getStmt returns nil; this means a fatal heredoc-related parse error can still be followed by parsing and appending later statements from the same input. For inputs where a heredoc body triggers an error and additional script text follows, callers get a misleading AST that includes statements after the first unrecoverable error.

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