Skip to content

Commit 6710976

Browse files
authored
Clarify the meaning of newline characters in multi-line string literals (#2966)
Clarify the meaning of newline characters in multi-line string literals, correct the `NEWLINE` rule, rename it to `LINE_BREAK`.
1 parent 273d355 commit 6710976

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

specification/dartLangSpec.tex

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
% version of the language which will actually be specified by the next stable
3636
% release of this document.
3737
%
38+
% Mar 2023
39+
% - Clarify how line breaks are handled in a multi-line string literal. Rename
40+
% the lexical token NEWLINE to LINE\_BREAK (clarifying that it is not `\n`).
41+
%
3842
% Feb 2023
3943
% - Change the specification of constant expressions of the form `e1 == e2`
4044
% to use primitive equality.
@@ -9166,6 +9170,9 @@ \subsection{Strings}
91669170
It is a compile-time error if the value of the
91679171
\syntax{<HEX\_DIGIT\_SEQUENCE>}
91689172
is not a valid Unicode code point.
9173+
\commentary{For example,}
9174+
{\color{commentaryColor}{\syntax{`\\u{0A}'}}\color{normativeColor}}
9175+
\commentary{is the code point U+000A.}
91699176
\item
91709177
\lit{\$} indicating the beginning of an interpolated expression.
91719178
\item
@@ -9183,8 +9190,9 @@ \subsection{Strings}
91839190

91849191
\LMHash{}%
91859192
Line breaks in a multiline string are represented by
9186-
the \synt{NEWLINE} production.
9187-
A line break introduces a single newline character into the string value.
9193+
the \synt{LINE\_BREAK} production.
9194+
A line break introduces a single newline character (U+000A)
9195+
into the string value.
91889196

91899197
\LMHash{}%
91909198
It is a compile-time error if a non-raw string literal contains
@@ -9196,9 +9204,9 @@ \subsection{Strings}
91969204
or by curly brace delimited sequence of hexadecimal digits.
91979205

91989206
\begin{grammar}
9199-
<NEWLINE> ::= `\\n'
9200-
\alt `\\r'
9207+
<LINE\_BREAK> ::= `\\n'
92019208
\alt `\\r\\n'
9209+
\alt `\\r'
92029210
\end{grammar}
92039211

92049212
\LMHash{}%
@@ -16727,7 +16735,7 @@ \subsection{Identifier Reference}
1672716735

1672816736
<DIGIT> ::= `0' .. `9'
1672916737

16730-
<WHITESPACE> ::= (`\\t' | ` ' | <NEWLINE>)+
16738+
<WHITESPACE> ::= (`\\t' | ` ' | <LINE\_BREAK>)+
1673116739
\end{grammar}
1673216740

1673316741
\LMHash{}%
@@ -19000,7 +19008,7 @@ \section{Libraries and Scripts}
1900019008
<scriptTag>? <libraryName>? <importOrExport>* <partDirective>*
1900119009
\gnewline{} (<metadata> <topLevelDeclaration>)* <EOF>
1900219010

19003-
<scriptTag> ::= `#!' (\gtilde<NEWLINE>)* <NEWLINE>
19011+
<scriptTag> ::= `#!' (\gtilde(`\\r' | `\\n'))* <LINE\_BREAK>
1900419012

1900519013
<libraryName> ::= <metadata> \LIBRARY{} <dottedIdentifierList> `;'
1900619014

@@ -22423,7 +22431,8 @@ \subsubsection{Comments}
2242322431
are sections of program text that are used for documentation.
2242422432

2242522433
\begin{grammar}
22426-
<SINGLE\_LINE\_COMMENT> ::= `//' \gtilde(<NEWLINE>)* (<NEWLINE>)?
22434+
<SINGLE\_LINE\_COMMENT> ::= \gnewline{}
22435+
`//' \gtilde(<LINE\_BREAK>)* (<LINE\_BREAK>)?
2242722436

2242822437
<MULTI\_LINE\_COMMENT> ::= \gnewline{}
2242922438
`/*' (<MULTI\_LINE\_COMMENT> | \gtilde{} `*/')* `*/'

0 commit comments

Comments
 (0)