Skip to content

Commit ef31637

Browse files
committed
Fix specification of multiline strings.
Now say that NEWLINE is one of CR, LF or CR+LF, and that all of these contribute a single LF to the string value. Fixes issue #14073 BUG= http://dartbug.com/14073 [email protected], [email protected] Review-Url: https://codereview.chromium.org/2665613003 .
1 parent 1275367 commit ef31637

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

docs/language/dartLangSpec.tex

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
% - An await-for loop only pauses the subscription if it does something async.
2828
% - Assert statements may now also include a "message" operand.
2929
% - The Null type is now considered a subtype of all types in most cases.
30+
% - Specify what NEWLINE means in multiline strings.
3031
%
3132
% 1.14
3233
% - The call "C()" where "C" is a class name, is a now compile-time error.
@@ -2807,7 +2808,7 @@ \subsection{Strings}
28072808
\end{grammar}
28082809

28092810
\LMHash{}
2810-
A string can be either a sequence of single line strings or a multiline string.
2811+
A string can be a sequence of single line strings and multiline strings.
28112812

28122813
\begin{grammar}
28132814
{\bf singleLineString:}`{\escapegrammar \code{"}}' stringContentDQ* `{\escapegrammar \code{"}}';
@@ -2828,10 +2829,7 @@ \subsection{Strings}
28282829
}
28292830

28302831
\LMHash{}
2831-
Adjacent
2832-
%single line
2833-
strings are implicitly concatenated to form a single string literal.
2834-
%, and so are adjacent multiline strings, but the two forms may not be mixed.
2832+
Adjacent strings are implicitly concatenated to form a single string literal.
28352833

28362834

28372835
\commentary{Here is an example}
@@ -2851,7 +2849,7 @@ \subsection{Strings}
28512849
\end{dartCode}
28522850

28532851
\rationale{ which this prints 'A simple sum: 2 + 2 = 22' rather than 'A simple sum: 2 + 2 = 4'.
2854-
However, the use the concatenation operation is still discouraged for efficiency reasons. Instead, the recommended Dart idiom is to use string interpolation.
2852+
However, the use of the concatenation operation is still discouraged for efficiency reasons. Instead, the recommended Dart idiom is to use string interpolation.
28552853
}
28562854

28572855
\begin{dartCode}
@@ -2876,22 +2874,22 @@ \subsection{Strings}
28762874

28772875

28782876
\begin{grammar}
2879-
{\bf multilineString:}`{\escapegrammar \texttt{"""}}' stringContentTDQ* `{\escapegrammar \texttt{"""}}';
2880-
`{\escapegrammar \code{'}\code{'}\code{'}}' stringContentTSQ* `{\escapegrammar \code{'}\code{'}\code{'}}';
2881-
`r' `{\escapegrammar \texttt{"""}}' (\~{} `{\escapegrammar \texttt{"""}}')* `{\escapegrammar \texttt{"""}}';
2882-
`r' `{\escapegrammar \code{'}\code{'}\code{'}}' (\~{} `{\escapegrammar \code{'}\code{'}\code{'}}')* `{\escapegrammar \code{'}\code{'}\code{'}}'
2883-
.
2877+
{\bf multilineString:}`{\escapegrammar \texttt{"""}}' stringContentTDQ* `{\escapegrammar \texttt{"""}}';
2878+
`{\escapegrammar \code{'}\code{'}\code{'}}' stringContentTSQ* `{\escapegrammar \code{'}\code{'}\code{'}}';
2879+
`r' `{\escapegrammar \texttt{"""}}' (\~{} `{\escapegrammar \texttt{"""}}')* `{\escapegrammar \texttt{"""}}';
2880+
`r' `{\escapegrammar \code{'}\code{'}\code{'}}' (\~{} `{\escapegrammar \code{'}\code{'}\code{'}}')* `{\escapegrammar \code{'}\code{'}\code{'}}'
2881+
.
28842882

28852883

2886-
{\bf ESCAPE\_SEQUENCE:} `$\backslash$ n';
2884+
{\bf ESCAPE\_SEQUENCE:}`$\backslash$ n';
28872885
`$\backslash$ r';
2888-
`$\backslash$ f';
2889-
`$\backslash$ b';
2890-
`$\backslash$ t';
2891-
`$\backslash$ v';
2892-
`$\backslash$ x' HEX\_DIGIT HEX\_DIGIT;
2893-
`$\backslash$ u' HEX\_DIGIT HEX\_DIGIT HEX\_DIGIT HEX\_DIGIT;
2894-
`$\backslash$ u\{' HEX\_DIGIT\_SEQUENCE `\}'
2886+
`$\backslash$ f';
2887+
`$\backslash$ b';
2888+
`$\backslash$ t';
2889+
`$\backslash$ v';
2890+
`$\backslash$ x' HEX\_DIGIT HEX\_DIGIT;
2891+
`$\backslash$ u' HEX\_DIGIT HEX\_DIGIT HEX\_DIGIT HEX\_DIGIT;
2892+
`$\backslash$ u\{' HEX\_DIGIT\_SEQUENCE `\}'
28952893
.
28962894

28972895
{\bf HEX\_DIGIT\_SEQUENCE:}
@@ -2901,12 +2899,11 @@ \subsection{Strings}
29012899
\end{grammar}
29022900

29032901
\LMHash{}
2904-
Multiline strings are delimited by either matching triples of single quotes or matching triples of double quotes. If the first line of a multiline string consists solely of the whitespace characters defined by the production {\em WHITESPACE} \ref{lexicalRules}), possibly prefixed by $\backslash$, then that line is ignored, including the new line at its end.
2905-
2902+
Multiline strings are delimited by either matching triples of single quotes or matching triples of double quotes. If the first line of a multiline string consists solely of the whitespace characters defined by the production {\em WHITESPACE} \ref{lexicalRules}), possibly prefixed by $\backslash$, then that line is ignored, including the line break at its end.
29062903

2907-
\rationale{
2908-
The idea is to ignore whitespace, where whitespace is defined as tabs, spaces and newlines. These can be represented directly, but since for most characters prefixing by backslash is an identity, we allow those forms as well.
2909-
}
2904+
\rationale{
2905+
The idea is to ignore a whitespace-only first line of a multiline string, where whitespace is defined as tabs, spaces and the final line break. These can be represented directly, but since for most characters prefixing by backslash is an identity in a non-raw string, we allow those forms as well.
2906+
}
29102907

29112908
% could be clearer. Is the first line in """\t
29122909
% """ ignored not. It depends if we mean whitespace before escapes are interpreted,
@@ -2915,7 +2912,7 @@ \subsection{Strings}
29152912
\LMHash{}
29162913
Strings support escape sequences for special characters. The escapes are:
29172914
\begin{itemize}
2918-
\item $\backslash$n for newline, equivalent to $\backslash$x0A.
2915+
\item $\backslash$n for newline, equivalent to $\backslash$x0A.
29192916
\item $\backslash$r for carriage return, equivalent to $\backslash$x0D.
29202917
\item $\backslash$f for form feed, equivalent to $\backslash$x0C.
29212918
\item $\backslash$b for backspace, equivalent to $\backslash$x08.
@@ -2933,6 +2930,10 @@ \subsection{Strings}
29332930
\LMHash{}
29342931
Any string may be prefixed with the character `r', indicating that it is a {\em raw string}, in which case no escapes or interpolations are recognized.
29352932

2933+
\LMHash{}
2934+
Line breaks in a multiline string are represented by the {\em NEWLINE} production.
2935+
A line break introduces a single newline character into the string value.
2936+
29362937
\LMHash{}
29372938
It is a compile-time error if a non-raw string literal contains a character sequence of the form $\backslash$x that is not followed by a sequence of two hexadecimal digits. It is a compile-time error if a non-raw string literal contains a character sequence of the form $\backslash$u that is not followed by either a sequence of four hexadecimal digits, or by curly brace delimited sequence of hexadecimal digits.
29382939

@@ -2959,7 +2960,8 @@ \subsection{Strings}
29592960
.
29602961

29612962
{\bf NEWLINE:}$\backslash$ n;
2962-
$\backslash$ r
2963+
$\backslash$ r;
2964+
$\backslash$ r $\backslash$ n
29632965
.
29642966

29652967
\end{grammar}

0 commit comments

Comments
 (0)