Skip to content

Commit e44242c

Browse files
authored
Adjust and clarify simple string interpolation, and clarify identifier rules. (#2198)
Adjust and clarify simple string interpolation (to allow `'$this'`, which is already implemented and useful). Add several lexical rules about identifiers, clarifying the different kinds like `<IDENTIFIER>`, `<identifier>`, `<typeIdentifier>`, `<IDENTIFIER_NO_DOLLAR>`, etc.
1 parent 72b4336 commit e44242c

File tree

1 file changed

+80
-59
lines changed

1 file changed

+80
-59
lines changed

specification/dartLangSpec.tex

Lines changed: 80 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
% that `o` is desugared as `o.call` when the context type is a function type.
3737
% - Clarify the treatment of `covariant` parameters in the interface of a class
3838
% that inherits an implementation where those parameters are not covariant.
39+
% - Adjust and clarify simple string interpolation (to allow `'$this'`, which
40+
% is already implemented and useful).
41+
% - Add several lexical rules about identifiers, clarifying different kinds.
3942
%
4043
% 2.14
4144
% - Add constraint on type of parameter which is covariant-by-declaration in
@@ -2397,7 +2400,7 @@ \section{Classes}
23972400

23982401
\begin{grammar}
23992402
<classDeclaration> ::=
2400-
\ABSTRACT? \CLASS{} <identifier> <typeParameters>?
2403+
\ABSTRACT? \CLASS{} <typeIdentifier> <typeParameters>?
24012404
\gnewline{} <superclass>? <interfaces>?
24022405
\gnewline{} `{' (<metadata> <classMemberDeclaration>)* `}'
24032406
\alt \ABSTRACT? \CLASS{} <mixinApplicationClass>
@@ -5484,7 +5487,7 @@ \subsection{Mixin Declaration}
54845487
for static member declarations.
54855488

54865489
\begin{grammar}
5487-
<mixinDeclaration> ::= \MIXIN{} <identifier> <typeParameters>?
5490+
<mixinDeclaration> ::= \MIXIN{} <typeIdentifier> <typeParameters>?
54885491
\gnewline{} (\ON{} <typeNotVoidList>)? <interfaces>?
54895492
\gnewline{} `\{' (<metadata> <classMemberDeclaration>)* `\}'
54905493
\end{grammar}
@@ -9165,7 +9168,7 @@ \subsubsection{String Interpolation}
91659168
\alt `${' <expression> `}'
91669169

91679170
<SIMPLE\_STRING\_INTERPOLATION> ::= \gnewline{}
9168-
`$' <IDENTIFIER\_NO\_DOLLAR>
9171+
`$' (<IDENTIFIER\_NO\_DOLLAR> | <BUILT\_IN\_IDENTIFIER> | \THIS)
91699172
\end{grammar}
91709173

91719174
\commentary{%
@@ -9179,7 +9182,9 @@ \subsubsection{String Interpolation}
91799182
the beginning of an interpolated expression.
91809183
The \lit{\$} sign may be followed by either:
91819184
\begin{itemize}
9182-
\item A single identifier \id{} that does not contain the \lit{\$} character.
9185+
\item A single identifier \id{} that does not contain the \lit{\$} character
9186+
(but it can be a built-in identifier),
9187+
or the reserved word \THIS.
91839188
\item An expression $e$ delimited by curly braces.
91849189
\end{itemize}
91859190

@@ -16537,62 +16542,70 @@ \subsection{Identifier Reference}
1653716542
\LMHash{}%
1653816543
An \Index{identifier expression} consists of a single identifier;
1653916544
it provides access to an object via an unqualified name.
16545+
A \synt{typeIdentifier} is an identifier which can be used
16546+
as the name of a type declaration.
16547+
16548+
\commentary{%
16549+
A \synt{qualifiedName} is not an identifier expression,
16550+
but we specify its syntax here because it is used in several different contexts,
16551+
and it is more closely related to the plain identifier
16552+
than it is to any single one of those grammar rules where it is used.%
16553+
}
1654016554

1654116555
\begin{grammar}
1654216556
<identifier> ::= <IDENTIFIER>
16557+
\alt <BUILT\_IN\_IDENTIFIER>
16558+
\alt <OTHER\_IDENTIFIER>
1654316559

16544-
<IDENTIFIER\_NO\_DOLLAR> ::= <IDENTIFIER\_START\_NO\_DOLLAR>
16545-
\gnewline{} <IDENTIFIER\_PART\_NO\_DOLLAR>*
16560+
<typeIdentifier> ::= <IDENTIFIER>
16561+
\alt <OTHER\_IDENTIFIER>
1654616562

16547-
<IDENTIFIER> ::= <IDENTIFIER\_START> <IDENTIFIER\_PART>*
16563+
<qualifiedName> ::= <typeIdentifier> `.' <identifier>
16564+
\alt <typeIdentifier> `.' <typeIdentifier> `.' <identifier>
1654816565

16549-
<BUILT\_IN\_IDENTIFIER> ::= \ABSTRACT{}
16550-
\alt \AS{}
16551-
\alt \COVARIANT{}
16552-
\alt \DEFERRED{}
16553-
\alt \DYNAMIC{}
16554-
\alt \EXPORT{}
16555-
\alt \EXTERNAL{}
16556-
\alt \EXTENSION{}
16557-
\alt \FACTORY{}
16558-
\alt \FUNCTION{}
16559-
\alt \GET{}
16560-
\alt \IMPLEMENTS{}
16561-
\alt \IMPORT{}
16562-
\alt \INTERFACE{}
16563-
\alt \LATE{}
16564-
\alt \LIBRARY{}
16565-
\alt \MIXIN{}
16566-
\alt \OPERATOR{}
16567-
\alt \PART{}
16568-
\alt \REQUIRED{}
16569-
\alt \SET{}
16570-
\alt \STATIC{}
16571-
\alt \TYPEDEF{}
16566+
<BUILT\_IN\_IDENTIFIER> ::= \ABSTRACT{} | \AS{} | \COVARIANT{} | \DEFERRED{}
16567+
\alt\hspace{-3mm} \DYNAMIC{} | \EXPORT{} | \EXTERNAL{} | \EXTENSION{} |
16568+
\FACTORY{} | \FUNCTION{} | \GET{}
16569+
\alt\hspace{-3mm} \IMPLEMENTS{} | \IMPORT{} | \INTERFACE{} | \LATE{} |
16570+
\LIBRARY{} | \MIXIN{} | \OPERATOR{}
16571+
\alt\hspace{-3mm} \PART{} | \REQUIRED{} | \SET{} | \STATIC{} | \TYPEDEF{}
1657216572

16573-
<IDENTIFIER\_START> ::= <IDENTIFIER\_START\_NO\_DOLLAR> | `$'
16573+
<OTHER\_IDENTIFIER> ::= \gnewline{}
16574+
\ASYNC{} | \HIDE{} | \OF{} | \ON{} | \SHOW{} | \SYNC{} |
16575+
\AWAIT{} | \YIELD{}
16576+
16577+
<IDENTIFIER\_NO\_DOLLAR> ::= <IDENTIFIER\_START\_NO\_DOLLAR>
16578+
\gnewline{} <IDENTIFIER\_PART\_NO\_DOLLAR>*
1657416579

1657516580
<IDENTIFIER\_START\_NO\_DOLLAR> ::= <LETTER> | `_'
1657616581

1657716582
<IDENTIFIER\_PART\_NO\_DOLLAR> ::= \gnewline{}
1657816583
<IDENTIFIER\_START\_NO\_DOLLAR> | <DIGIT>
1657916584

16580-
<IDENTIFIER\_PART> ::= <IDENTIFIER\_START> | <DIGIT>
16585+
<IDENTIFIER> ::= <IDENTIFIER\_START> <IDENTIFIER\_PART>*
1658116586

16582-
<qualifiedName> ::= <typeIdentifier> `.' <identifier>
16583-
\alt <typeIdentifier> `.' <typeIdentifier> `.' <identifier>
16587+
<IDENTIFIER\_START> ::= <IDENTIFIER\_START\_NO\_DOLLAR> | `$'
16588+
16589+
<IDENTIFIER\_PART> ::= <IDENTIFIER\_START> | <DIGIT>
1658416590

16585-
<LETTER> ::= `a' .. `z'
16586-
\alt `A' .. `Z'
16591+
<LETTER> ::= `a' .. `z' | `A' .. `Z'
1658716592

1658816593
<DIGIT> ::= `0' .. `9'
1658916594

1659016595
<WHITESPACE> ::= (`\\t' | ` ' | <NEWLINE>)+
1659116596
\end{grammar}
1659216597

1659316598
\LMHash{}%
16594-
A built-in identifier is one of the identifiers produced by the production
16595-
\synt{BUILT\_IN\_IDENTIFIER}.
16599+
The ordering of the lexical rules above ensure that \synt{IDENTIFIER}
16600+
and \synt{IDENTIFIER\_NO\_DOLLAR} do not derive any built-in identifiers.
16601+
Similarly, the lexical rule for reserved words (\ref{reservedWords})
16602+
must be considered to come before the rule for \synt{BUILT\_IN\_IDENTIFIER},
16603+
such that \synt{IDENTIFIER} and \synt{IDENTIFIER\_NO\_DOLLAR}
16604+
also do not derive any reserved words.
16605+
16606+
\LMHash{}%
16607+
A \Index{built-in identifier} is one of
16608+
the identifiers produced by the production \synt{BUILT\_IN\_IDENTIFIER}.
1659616609
It is a compile-time error if a built-in identifier is used as
1659716610
the declared name of a prefix, class, mixin, type parameter, or type alias.
1659816611
It is a compile-time error to use a built-in identifier
@@ -16610,8 +16623,8 @@ \subsection{Identifier Reference}
1661016623

1661116624
\LMHash{}%
1661216625
It is a compile-time error if either of the identifiers \AWAIT{} or \YIELD{}
16613-
is used as an identifier in a function body
16614-
marked with either \ASYNC, \code{\ASYNC*} or \code{\SYNC*}.
16626+
is used as an \synt{identifier} in a function body
16627+
marked with either \ASYNC, \code{\ASYNC*}, or \code{\SYNC*}.
1661516628

1661616629
\rationale{%
1661716630
This makes the identifiers \AWAIT{} and \YIELD{} behave like reserved words
@@ -16622,8 +16635,10 @@ \subsection{Identifier Reference}
1662216635
}
1662316636

1662416637
\LMHash{}%
16625-
A \Index{qualified identifier} is an identifier preceded by
16626-
\syntax{<identifier> `.'}.
16638+
A \Index{qualified name} is two or three identifiers separated by \lit{.}.
16639+
All but the last one must be a \synt{typeIdentifier}.
16640+
It is used to denote a declaration which is imported with a prefix,
16641+
or a \STATIC{} declaration in a class, mixin, or extension, or both.
1662716642

1662816643
\LMHash{}%
1662916644
The static type of an identifier expression $e$ which is an identifier \id{}
@@ -19988,16 +20003,12 @@ \subsection{Static Types}
1998820003
Type annotations are used during static checking and when running programs.
1998920004
Types are specified using the following grammar rules.
1999020005

19991-
%% TODO(eernst): The following non-terminal is currently undefined (it will
19992-
%% be defined when more rules are transferred from Dart.g): <typeIdentifier>.
19993-
%% The precise rules are slightly different than the following sentence, but
19994-
%% we should be able to make do with that for now.
19995-
\LMHash{}%
19996-
In the grammar rules below, \synt{typeIdentifier} denotes
19997-
an identifier which can be
19998-
the name of a type, that is, it denotes an \synt{IDENTIFIER} which is not a
19999-
\synt{BUILT\_IN\_IDENTIFIER}.
20000-
20006+
\commentary{%
20007+
A \synt{typeIdentifier} is an identifier which can be the name of a type,
20008+
that is,
20009+
it denotes an \synt{IDENTIFIER} which is not a \synt{BUILT\_IN\_IDENTIFIER}
20010+
(\ref{identifierReference}).%
20011+
}
2000120012
%% TODO(eernst): The following non-terminals are currently unused (they will
2000220013
%% be used when we transfer more grammar rules from Dart.g): <typeNotVoid>
2000320014
%% and <typeNotVoidNotFunctionList>. They are used in the syntax for
@@ -22232,15 +22243,25 @@ \subsubsection{Reserved Words}
2223222243
}
2223322244

2223422245
\begin{grammar}
22235-
<reservedWord> ::= \ASSERT{} | \BREAK{} | \CASE{} | \CATCH{} |
22236-
\CLASS{} | \CONST{} | \CONTINUE{}
22237-
\alt\hspace{-3mm} \DEFAULT{} | \DO{} | \ELSE{} | \ENUM{} | \EXTENDS{} |
22238-
\FALSE{} | \FINAL{} | \FINALLY{} | \FOR{} | \IF{} | \IN{} | \IS{}
22239-
\alt\hspace{-3mm} \NEW{} | \NULL{} | \RETHROW{} | \RETURN{} | \SUPER{} |
22240-
\SWITCH{} | \THIS{} | \THROW{} | \TRUE{} | \TRY{}
22241-
\alt\hspace{-3mm} \VAR{} | \VOID{} | \WHILE{} | \WITH{}
22246+
<RESERVED\_WORD> ::= \ASSERT{} | \BREAK{} | \CASE{} | \CATCH{} |
22247+
\CLASS{} | \CONST{}
22248+
\alt\hspace{-3mm} \CONTINUE{} | \DEFAULT{} | \DO{} | \ELSE{} | \ENUM{} |
22249+
\EXTENDS{} | \FALSE{} | \FINAL{} | \FINALLY{} | \FOR{}
22250+
\alt\hspace{-3mm} \IF{} | \IN{} | \IS{} | \NEW{} | \NULL{} | \RETHROW{} |
22251+
\RETURN{} | \SUPER{} | \SWITCH{} | \THIS{} | \THROW{}
22252+
\alt\hspace{-3mm} \TRUE{} | \TRY{} | \VAR{} | \VOID{} | \WHILE{} | \WITH{}
2224222253
\end{grammar}
2224322254

22255+
\LMHash{}%
22256+
In the grammar, the rule for reserved words above must occur
22257+
before the rule for \synt{BUILT\_IN\_IDENTIFIER}
22258+
(\ref{identifierReference}).
22259+
22260+
\commentary{%
22261+
This ensures that \synt{IDENTIFIER} and \synt{IDENTIFIER\_NO\_DOLLAR} do not
22262+
derive any reserved words, and they do not derive any built-in identifiers.
22263+
}
22264+
2224422265

2224522266
\subsubsection{Comments}
2224622267
\LMLabel{comments}

0 commit comments

Comments
 (0)