ES4 draft: Triply quoted string literals

Lars Hansen lhansen at adobe.com
Mon Mar 3 23:05:37 PST 2008


> -----Original Message-----
> From: Waldemar Horwat [mailto:waldemar at google.com] 
> Sent: 4. mars 2008 02:25
> To: Lars Hansen
> Cc: es4-discuss Discuss
> Subject: Re: ES4 draft: Triply quoted string literals
> 
> I'm not sure what the intent is, but as this is written:
> 
> """abc""""def"""
> 
> will evaluate to the same string as 'abc""""def'.

It will not.  The text of the spec is "The literal is terminated by the
earliest sequence of three unescaped instances of the the same quote
character that is not followed by a fourth quote character of the same
kind."  So the string is the four-letter sequence abc".  Perhaps the
sentence would be even clearer if the word "immediately" were to precede
the word "followed".

> Furthermore,
> 
> """\"""
> 
> turns into:
> 
> \

It does not, this is an unterminated triple-quoted string according to
the rule above.

> What does the following evaluate to?
> 
> """\n\\\"\t"""

The four character string U+000A U+005C U+0022 U+0009.

> Is it the same as "\n\\\"\t"?

It is.

It is also the same as """<LF>\\"<TAB>""" where <LF> denotes a literal
U+000A (or U+000D or U+000D U+000A pair, cf the proposal on line
terminator normalization).  Note the unescaped quote character.

> If so, then triple quoting seems like an extraneous feature, 
> as we still need to go through and double every backslash 
> located inside the string.

The primary purpose of triple quoting is not to avoid escaping
backslashes, but to avoid escaping quotes and to avoid having to convert
literal line breaks to \n characters.  There is a small amount of
discussion on the original proposal page (reference [1] from the spec
page).

(I too like the r"..." syntax of Python, but that is not what we have
here.)

--lars

> 
>     Waldemar
> 
> 
> Lars Hansen wrote:
> > Please comment.  --lars
> > 
> > 
> > 
> ----------------------------------------------------------------------
> > --
> > 
> > NAME:        "Triply quoted string literals"
> > CATEGORY:    Lexical conventions (E262-3 ch 7)
> > SOURCES:     References [1], [4]
> > SPEC AUTHOR: Lars
> > STATUS:      OPEN ISSUES
> > REVIEWS:     (none)
> > IMPLEMENTED: RI; Tamarin+ESC
> > 
> > 
> > DESCRIPTION
> > 
> > A sequence of three unescaped SINGLEQUOTE or three unescaped 
> > DOUBLEQUOTE characters signifies the start of a 
> triply-quoted string 
> > literal.  The literal is terminated by the earliest 
> sequence of three 
> > unescaped instances of the the same quote character that is not 
> > followed by a fourth quote character of the same kind.
> > 
> > Arbitrary characters, including line terminator characters, are 
> > allowed between the starting and ending quotes.  Following 
> > determination of the starting and ending quotes the input 
> text between 
> > the starting and ending quotes is subject to escape character 
> > processing, wherein sequences of characters starting with BACKSLASH 
> > are replaced by those single characters signified by the sequences.
> > 
> > The escape character processing is performed exactly as for singly 
> > quoted strings.
> > 
> > 
> > NOTES
> > 
> > As always, line terminator normalization [2] is in effect.
> > 
> > 
> > OPEN ISSUES
> > 
> > There is a note on the wiki [4] regarding whether \<lineterminator> 
> > should be handled differently in triple-quoted strings than in 
> > double-quoted strings.  Brendan's opinion is it should -- it should 
> > escape the <lineterminator>.  The RI does not implement 
> that behavior, 
> > and the present proposal follows the RI.  See [3] for a 
> more general 
> > discussion.
> > 
> > 
> > DEFINITIONS
> > 
> > BACKSLASH=U+005C
> > SINGLEQUOTE=U+0027
> > DOUBLEQUOTE=U+0022
> > 
> > 
> > REFERENCES
> > 
> > [1] http://wiki.ecmascript.org/doku.php?id=proposals:triple_quotes
> > [2] "Line terminator normalization" spec [3] "Line continuation in 
> > string literals" spec [4] 
> > 
> http://wiki.ecmascript.org/doku.php?id=proposals:line_terminator_norma
> > lization
> 



More information about the Es4-discuss mailing list