Skip to content

Place every heredoc body and say whether it terminated - #11

Open
nyaarium wants to merge 1 commit into
webpro-nl:mainfrom
nyaarium:heredoc-body-span
Open

Place every heredoc body and say whether it terminated#11
nyaarium wants to merge 1 commit into
webpro-nl:mainfrom
nyaarium:heredoc-body-span

Conversation

@nyaarium

@nyaarium nyaarium commented Sep 6, 2026

Copy link
Copy Markdown

What

Three fields on Redirect, set for << and <<- and undefined otherwise:

  • contentPos / contentEnd: the span content was sliced from, present whenever content is.
  • heredocTerminated: false when end of input ended the body before its delimiter line, which Bash accepts with a warning (here-document delimited by end-of-file).

Why

Today a body is placed only when it expands (body is a Word with pos/end). A quoted body, a plain one, or an unterminated one has content but no position, and nothing says whether the delimiter was found. A consumer that wants to point at the body, or warn where Bash warns, has to rescan the source for the delimiter line, re-deriving the tab-stripping and end-of-input rules the lexer already applied. nyaa-lexicon's Bash provider carries exactly that rescan today and would delete it.

How

consumePendingHereDocs already knows the body start and gets the end back from skipHereDocBody; it now records both on the target. skipHereDocBody sets a flag on its two delimiter-matched returns and clears it on the end-of-input fall-through. readHereDocBody folded into its one caller. No change to content, body, or heredocQuoted.

Tests

test/heredoc-positions.test.ts: the span slices content for plain, quoted, <<-, expanding and empty bodies; the expanding body word and the span agree; two heredocs on one line; end-of-input with and without a trailing newline; an indented, padded, or extended delimiter line does not terminate; a heredoc inside $( ) on the nested script; a non-heredoc redirect has no span. Format, lint, tsc and the full suite pass (1711).

I chose fields over pushing an error for the unterminated case, since Bash runs such a script. Happy to change names or shape.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@nyaarium

nyaarium commented Sep 6, 2026

Copy link
Copy Markdown
Author

ohh shoot. Sorry, the clanker decided to make these PRs. If you don't care for em, close it.

Sorry again.

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