Place every heredoc body and say whether it terminated - #11
Open
nyaarium wants to merge 1 commit into
Open
Conversation
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Author
|
ohh shoot. Sorry, the clanker decided to make these PRs. If you don't care for em, close it. Sorry again. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Three fields on
Redirect, set for<<and<<-andundefinedotherwise:contentPos/contentEnd: the spancontentwas sliced from, present whenevercontentis.heredocTerminated:falsewhen 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 (
bodyis aWordwithpos/end). A quoted body, a plain one, or an unterminated one hascontentbut 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
consumePendingHereDocsalready knows the body start and gets the end back fromskipHereDocBody; it now records both on the target.skipHereDocBodysets a flag on its two delimiter-matched returns and clears it on the end-of-input fall-through.readHereDocBodyfolded into its one caller. No change tocontent,body, orheredocQuoted.Tests
test/heredoc-positions.test.ts: the span slicescontentfor plain, quoted,<<-, expanding and empty bodies; the expandingbodyword 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.