Skip to content

Commit a1bf79d

Browse files
authored
Update the specification section about metadata (#3787)
The association that binds each metadatum in a Dart program to a language construct is specified in a way that is somewhat inconsistent with the grammar. For example, it associates the metadata declared in front of a `<libraryName>` with the keyword `library`, not with the library name directive as a whole. This PR changes the wording such that metadata which occurs at the beginning of a grammar rule is associated with the construct as a whole. If the metadata occurs in any other location in the rule then we continue to use the rule which is specified prior to this PR: The metadata is associated with the program construct which is derived from the following non-terminal. The latter rule works well with cases like `<classDeclaration> ::= ... (<metadata> <classMemberDeclaration>)* ...`. This PR also adds a small amount of rationale text, saying that this whole topic has an implementation specific element, and the normative rules are intentionally somewhat flexible. We trust all tool maintainers to maintain a reasonable amount of consistency, and provide just a few normative rules in order to make it easier to be consistent, insofar as this is possible with the given program representation.
1 parent e1f1861 commit a1bf79d

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

specification/dartLangSpec.tex

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8304,16 +8304,43 @@ \section{Metadata}
83048304
}
83058305

83068306
\LMHash{}%
8307-
Metadata is associated with the abstract syntax tree
8308-
of the program construct $p$ that immediately follows the metadata,
8309-
and which is not itself metadata or a comment.
8307+
Metadata that occurs as the first element of
8308+
the right hand side of a grammar rule
8309+
is associated with the abstract syntax tree for the non-terminal
8310+
on the left hand side of said grammar rule
8311+
\commentary{(that is, it is associated with its parent)}.
8312+
Otherwise, metadata is associated with the abstract syntax tree
8313+
of the program construct $p$ that immediately follows the metadata
8314+
in the grammar rule.
8315+
8316+
\rationale{%
8317+
These rules are intended to ensure a minimal level of consistency
8318+
in the association that binds each metadatum to a program construct.
8319+
The structure of the abstract syntax tree is implementation specific,
8320+
and it is not even guaranteed that a tool will use anything
8321+
which is known as an abstract syntax tree.
8322+
In that case the phrase `abstract syntax tree' should be interpreted as
8323+
the program representation entities which are actually used.
8324+
8325+
This implies that the fine details of the association between metadata
8326+
and an abstract syntax tree node is also implementation specific.
8327+
In particular, an implementation can choose to associate a given metadatum
8328+
with more than one abstract syntax tree node.%
8329+
}
8330+
8331+
\LMHash{}%
83108332
Metadata can be retrieved at run time via a reflective call,
83118333
provided the annotated program construct $p$ is accessible via reflection.
83128334

83138335
\commentary{%
83148336
Obviously, metadata can also be retrieved statically by
83158337
parsing the program and evaluating the constants via a suitable interpreter.
8316-
In fact, many if not most uses of metadata are entirely static.%
8338+
In fact, many if not most uses of metadata are entirely static.
8339+
In this case the binding of each metadatum to an abstract syntax tree node
8340+
is determined by the given static analysis tool,
8341+
which is of course not subject to any constraints in this document.
8342+
Surely it will still be useful to strive for consistency among all tools
8343+
with respect to the binding from metadata to abstract syntax tree nodes.%
83178344
}
83188345

83198346
\rationale{%
@@ -18189,8 +18216,10 @@ \subsection{For}
1818918216
<forStatement> ::= \AWAIT? \FOR{} `(' <forLoopParts> `)' <statement>
1819018217

1819118218
<forLoopParts> ::= <forInitializerStatement> <expression>? `;' <expressionList>?
18192-
\alt <metadata> <declaredIdentifier> \IN{} <expression>
18193-
\alt <identifier> \IN{} <expression>
18219+
\alt <forInLoopPrefix> \IN{} <expression>
18220+
18221+
<forInLoopPrefix> ::= <metadata> <declaredIdentifier>
18222+
\alt <identifier>
1819418223

1819518224
<forInitializerStatement> ::= <localVariableDeclaration>
1819618225
\alt <expression>? `;'

0 commit comments

Comments
 (0)