* What does REDIRF_FROM_HEREDOC flag represent?
@ 2021-10-21 9:53 Jett Husher
2021-10-21 14:39 ` Daniel Shahaf
0 siblings, 1 reply; 4+ messages in thread
From: Jett Husher @ 2021-10-21 9:53 UTC (permalink / raw)
To: zsh-workers
Good day!
I was peeking at the source code and found REDIRF_FROM_HEREDOC flag. The comments say that it's for a here-string that came from a here-document but I'm still not clear how this looks exactly. Is it that every line in heredoc is a here-string? I've tried to read the part in parser.c where this flag is being set, but couldn't make sense of it since I'm not at all acquainted with C or the codebase as a whole.
Would very much appreciate the explanation.
- Jett
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: What does REDIRF_FROM_HEREDOC flag represent?
2021-10-21 9:53 What does REDIRF_FROM_HEREDOC flag represent? Jett Husher
@ 2021-10-21 14:39 ` Daniel Shahaf
[not found] ` <vBtfA3xVArPp-qWVYvqO2koSzHro1ms6um1SMPrWwJSp-luOAzAkWH2xx7FAxaPw8IWt1uQw3PiNd0yhOfXRAMGRgSGlscm23N0CnMY1oKI=@pm.me>
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Shahaf @ 2021-10-21 14:39 UTC (permalink / raw)
To: Jett Husher; +Cc: zsh-workers
Jett Husher wrote on Thu, Oct 21, 2021 at 09:53:42 +0000:
> Good day!
>
> I was peeking at the source code
Welcome :)
> and found REDIRF_FROM_HEREDOC flag. The comments say that it's for a
> here-string that came from a here-document but I'm still not clear how
> this looks exactly.
A here-string is this thing:
item(tt(<<<) var(word))(
Perform shell expansion on var(word) and pass the result
to standard input. This is known as a em(here-string).
Compare the use of var(word) in here-documents above, where var(word)
does not undergo shell expansion.
)
Example:
% nl -ba <<< $'foo\nbar'
1 foo
2 bar
%
> Is it that every line in heredoc is a here-string?
No.
> I've tried to read the part in parser.c where this flag is being set,
> but couldn't make sense of it since I'm not at all acquainted with C
> or the codebase as a whole.
I think what happens is this:
- After parsing, a here-doc is represented as a here-string with
REDIRF_FROM_HEREDOC set
- text.c looks for that bit and does the reverse transformation, so
stuff like
.
f() { foo <<< lorem; bar <<'EOF'
ipsum
EOF
}
.
gets emitted by `which f` using the same type as input redirections as
it used when the shell first lexed/parsed it.
- exec.c appends a newline to here-strings' data before passing it to
commands; see:
.
% xxd <<<foo
00000000: 666f 6f0a foo.
- There are no other mentions of REDIRF_FROM_HEREDOC.
It did help that I already knew what each file does in general, but
yeah, I don't have access to zsh-with-comments.git either ☹
Cheers,
Daniel
> Would very much appreciate the explanation.
>
> - Jett
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-10-25 19:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-21 9:53 What does REDIRF_FROM_HEREDOC flag represent? Jett Husher
2021-10-21 14:39 ` Daniel Shahaf
[not found] ` <vBtfA3xVArPp-qWVYvqO2koSzHro1ms6um1SMPrWwJSp-luOAzAkWH2xx7FAxaPw8IWt1uQw3PiNd0yhOfXRAMGRgSGlscm23N0CnMY1oKI=@pm.me>
2021-10-22 4:42 ` Jett Husher
2021-10-25 19:30 ` Daniel Shahaf
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).