Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: triviality with prompts

On 12/06/2014 01:28 PM, Bart Schaefer wrote:
Not exactly.  It's a delineated block of characters in which a defined
syntax will apply.  Of course in the colloquial sense the meaning of an
individual grapheme in a syntax is its "semantics", but in the computer
science sense the syntax and semantics of a language are distinct.
Yeah, may as well be strict.  I don't want to split hairs too finely tho,
and I only know the rules for this in natural language.
Quoting defines the meaning of individual characters, e.g., transforming
the digraph \n into something else -- either a literal "n" or a newline,
depending on the interpretation of the backslash.  Quoting also creates
a syntactic unit, affecting how a collection of graphemes is assembled
into tokens (most often, resulting in a single token instead of many,
and usually resulting in tokens that are treated as plain strings and
not as having any particular higher-level meaning).

Constructs like $( ) define the meaning and higher-level structure of
the language tokens that came from interpretation of the syntax.  The
shell language is unusual among programming languages in that it allows
certain semantic constructs to be interpreted even when inside certain
syntactic constructs (double-quoting, mostly), so that it's necessary
to interleave syntactic and semantic analysis (and even execution of
the code resulting from the latter) to arrive at a final tokenization.

Most programming languages force you to make that explicit, but the
shell is all about building up or cutting up strings by implicit con-
catenation and delineation, so it takes all kinds of shortcuts that
make the language ugly to formally define but faster to interact with
in the common cases.
You know, once you 'just say it' half the problem goes away.  I'm still
looking for rigor. Once I just stop looking for it I won't get into a lather
nearly so  often.

E.g. in
	'$(echo foo bar)'
the definition of single quotes means that none of $ ( or ) is special,
and results in one plain-string token made up of the characters between
the single quotes.  Conversely in
	"$(echo foo bar)"
the definition of double quotes means that $ is special, which in turn
means that the digraph $( introduces a subexpression that has to be
interpreted using the higher-level rules of command substitution, which
consumes everything up through the closing paren.  The final token can
only be generated after the command inside the parens is executed and
its output captured, but it still results in only one plain string.

Compare to $(echo foo bar) without the quotes, which normally results
in two string tokens foo and bar, or to
	"\$(echo foo bar)"
where the definition of backslash means that the digraph \$ transforms
into a non-special $ which therefore is NOT part of a $( digraph and
therefore does not introduce command substitution.

} Maybe what I'm reaching for with the list above is a complete list of
} 'delineators'.  So, if one had such a list, one could learn the syntactic
} rules inside each one in a tractable way.

In zsh's info doc, sections 6.9 (Quoting) and 14 (Expansion) together
make up that list.

That, sir, was beautifully written.

Messages sorted by: Reverse Date, Date, Thread, Author