Skip to content

recover missing-then if clause AST recovery - #798

Merged
ewhauser merged 6 commits into
mainfrom
ewhauser/recover-if-missing-then
Mar 30, 2026
Merged

ewhauser merged 6 commits into
mainfrom
ewhauser/recover-if-missing-then

Conversation

@ewhauser

Copy link
Copy Markdown
Owner

Summary

Recover IfClause nodes under RecoverErrors when then is omitted before fi, else, or elif.

What Changed

  • parse if/elif heads against then, fi, else, and elif so missing-then forms can still build a structured *syntax.IfClause
  • recover ThenPos and split the parsed statements into Cond and Then when the first body statement appears before the missing then
  • treat recovered ThenPos as a real if/elif marker in AST consumers and printing
  • add regression coverage for:
    • if <cond>\n<body>\nfi
    • if <cond>\n<body>\nelse ...
    • recovered elif chains with a missing then

Why

The parser previously recovered the missing then token position but did not preserve the surrounding clause structure. In missing-then forms, that left the body unavailable as IfClause.Then and forced downstream fallback logic to infer the shape from less structured parser output.

Impact

Recovered IfClause trees now expose the missing-then body and else/elif structure directly, which should remove the need for the fallback handling behind SH-175 and SH-176.

Validation

  • go test ./shell/syntax -count=1
  • make lint

@ewhauser ewhauser changed the title [codex] recover missing-then if clause AST recovery recover missing-then if clause AST recovery Mar 30, 2026
@ewhauser
ewhauser marked this pull request as ready for review March 30, 2026 13:43

@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: 194c704742

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

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

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

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

ℹ️ 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 5214841 into main Mar 30, 2026
16 checks passed
@ewhauser
ewhauser deleted the ewhauser/recover-if-missing-then branch March 30, 2026 14:34
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