From 035be2b0d4f49f0eeb075d4f87a8e7873c0d56ba Mon Sep 17 00:00:00 2001 From: Erik Ernst Date: Tue, 21 May 2024 09:07:23 +0000 Subject: [PATCH] Update Dart.g to clarify the association of metadata and its target AST Change-Id: I02a3e155aab73d638ddbc20485db9db3dcbe6c9f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365781 Reviewed-by: Chloe Stefantsova Commit-Queue: Erik Ernst --- tools/spec_parser/Dart.g | 25 ++++++++++++++++------ tools/spec_parser/dart_spec_parser/Dart.g4 | 25 ++++++++++++++++------ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/tools/spec_parser/Dart.g b/tools/spec_parser/Dart.g index d921e2c233a..c20183f4248 100644 --- a/tools/spec_parser/Dart.g +++ b/tools/spec_parser/Dart.g @@ -4,6 +4,12 @@ // CHANGES: // +// v0.43 Change rule structure such that the association of metadata +// with non-terminals can be explained in a simple and consistent way. +// The derivable terms do not change. Remove `metadata` from the kind +// of `forLoopParts` where the iteration variable is an existing variable +// in scope (this is not implemented, is inconsistent anyway). +// // v0.42 Support updated augmented `extensionDeclaration`. // // v0.41 Add missing `enumEntry` update for augmentations. @@ -451,7 +457,7 @@ extensionTypeDeclaration ; representationDeclaration - : ('.' identifierOrNew)? '(' metadata type identifier ')' + : ('.' identifierOrNew)? '(' metadata typedIdentifier ')' ; @@ -1197,7 +1203,7 @@ objectPattern ; patternVariableDeclaration - : (FINAL | VAR) outerPattern '=' expression + : outerPatternDeclarationPrefix '=' expression ; outerPattern @@ -1208,6 +1214,10 @@ outerPattern | objectPattern ; +outerPatternDeclarationPrefix + : (FINAL | VAR) outerPattern + ; + patternAssignment : outerPattern '=' expression ; @@ -1275,12 +1285,15 @@ forStatement : AWAIT? FOR '(' forLoopParts ')' statement ; -// TODO: Include `metadata` in the pattern form? forLoopParts - : metadata declaredIdentifier IN expression - | metadata identifier IN expression + : forInLoopPrefix IN expression | forInitializerStatement expression? ';' expressionList? - | metadata (FINAL | VAR) outerPattern IN expression + ; + +forInLoopPrefix + : metadata declaredIdentifier + | metadata outerPatternDeclarationPrefix + | identifier ; // The localVariableDeclaration cannot be CONST, but that can diff --git a/tools/spec_parser/dart_spec_parser/Dart.g4 b/tools/spec_parser/dart_spec_parser/Dart.g4 index 1980ee00449..c7673f7b720 100644 --- a/tools/spec_parser/dart_spec_parser/Dart.g4 +++ b/tools/spec_parser/dart_spec_parser/Dart.g4 @@ -4,6 +4,12 @@ // CHANGES: // +// v0.44 Change rule structure such that the association of metadata +// with non-terminals can be explained in a simple and consistent way. +// The derivable terms do not change. Remove `metadata` from the kind +// of `forLoopParts` where the iteration variable is an existing variable +// in scope (this is not implemented, is inconsistent anyway). +// // v0.43 Support updated augmented `extensionDeclaration`. // // v0.42 Add missing `enumEntry` update for augmentations. @@ -457,7 +463,7 @@ extensionTypeDeclaration ; representationDeclaration - : ('.' identifierOrNew)? '(' metadata type identifier ')' + : ('.' identifierOrNew)? '(' metadata typedIdentifier ')' ; @@ -1203,7 +1209,7 @@ objectPattern ; patternVariableDeclaration - : (FINAL | VAR) outerPattern '=' expression + : outerPatternDeclarationPrefix '=' expression ; outerPattern @@ -1214,6 +1220,10 @@ outerPattern | objectPattern ; +outerPatternDeclarationPrefix + : (FINAL | VAR) outerPattern + ; + patternAssignment : outerPattern '=' expression ; @@ -1281,12 +1291,15 @@ forStatement : AWAIT? FOR '(' forLoopParts ')' statement ; -// TODO: Include `metadata` in the pattern form? forLoopParts - : metadata declaredIdentifier IN expression - | metadata identifier IN expression + : forInLoopPrefix IN expression | forInitializerStatement expression? ';' expressionList? - | metadata (FINAL | VAR) outerPattern IN expression + ; + +forInLoopPrefix + : metadata declaredIdentifier + | metadata outerPatternDeclarationPrefix + | identifier ; // The localVariableDeclaration cannot be CONST, but that can