Several small corrections, based on SDK issue #50982
Bug: 50982
Change-Id: I786ddb49172702f143dfddda2d3ff6ba0d3c6327
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279000
Commit-Queue: Erik Ernst <eernst@google.com>
Reviewed-by: William Hesse <whesse@google.com>
diff --git a/tools/spec_parser/Dart.g b/tools/spec_parser/Dart.g
index b4c65de..8f14ec4 100644
--- a/tools/spec_parser/Dart.g
+++ b/tools/spec_parser/Dart.g
@@ -4,6 +4,12 @@
// CHANGES:
//
+// v0.27 Remove unused non-terminals; make handling of interpolation in URIs
+// consistent with the language specification. Make `partDeclaration` a
+// start symbol in addition to `libraryDefinition` (such that no special
+// precautions are needed in order to parse a part file). Corrected spacing
+// in several rules.
+//
// v0.26 Add missing `metadata` in `partDeclaration`.
//
// v0.25 Update pattern rules following changes to the patterns feature
@@ -112,7 +118,7 @@
public boolean parseLibrary(String filePath) throws RecognitionException {
this.filePath = filePath;
errorHasOccurred = false;
- libraryDefinition();
+ startSymbol();
return !errorHasOccurred;
}
@@ -129,7 +135,7 @@
// neither `async`, `async*`, nor `sync*`.
void startNonAsyncFunction() { asyncEtcAreKeywords.push(false); }
- // Use this to indicate that we are now leaving any funciton.
+ // Use this to indicate that we are now leaving any function.
void endFunction() { asyncEtcAreKeywords.pop(); }
// Whether we can recognize AWAIT/YIELD as an identifier/typeIdentifier.
@@ -198,6 +204,11 @@
// ---------------------------------------- Grammar rules.
+startSymbol
+ : libraryDefinition
+ | partDeclaration
+ ;
+
libraryDefinition
: FEFF? SCRIPT_TAG?
libraryName?
@@ -258,11 +269,6 @@
: type? identifierNotFUNCTION formalParameterPart
;
-functionBodyPrefix
- : ASYNC? '=>'
- | (ASYNC | ASYNC '*' | SYNC '*')? LBRACE
- ;
-
functionBody
: '=>' { startNonAsyncFunction(); } expression { endFunction(); } ';'
| { startNonAsyncFunction(); } block { endFunction(); }
@@ -608,11 +614,6 @@
: (multiLineString | singleLineString)+
;
-// Not used in the specification (needed here for <uri>).
-stringLiteralWithoutInterpolation
- : singleStringWithoutInterpolation+
- ;
-
setOrMapLiteral
: CONST? typeArguments? LBRACE elements? RBRACE
;
@@ -637,35 +638,35 @@
;
elements
- : element (',' element)* ','?
+ : element (',' element)* ','?
;
element
- : expressionElement
- | mapElement
- | spreadElement
- | ifElement
- | forElement
+ : expressionElement
+ | mapElement
+ | spreadElement
+ | ifElement
+ | forElement
;
expressionElement
- : expression
+ : expression
;
mapElement
- : expression ':' expression
+ : expression ':' expression
;
spreadElement
- : ('...' | '...?') expression
+ : ('...' | '...?') expression
;
ifElement
- : ifCondition element (ELSE element)?
+ : ifCondition element (ELSE element)?
;
forElement
- : AWAIT? FOR '(' forLoopParts ')' element
+ : AWAIT? FOR '(' forLoopParts ')' element
;
constructorTearoff
@@ -698,10 +699,6 @@
| ASYNC '=>' { startAsyncFunction(); } expression { endFunction(); }
;
-functionExpressionBodyPrefix
- : ASYNC? '=>'
- ;
-
functionExpressionWithoutCascade
: formalParameterPart functionExpressionWithoutCascadeBody
;
@@ -723,10 +720,6 @@
{ startAsyncFunction(); } block { endFunction(); }
;
-functionPrimaryBodyPrefix
- : (ASYNC | ASYNC '*' | SYNC '*')? LBRACE
- ;
-
thisExpression
: THIS
;
@@ -1146,7 +1139,7 @@
;
patternAssignment
- : outerPattern '=' expression
+ : outerPattern '=' expression
;
statements
@@ -1353,13 +1346,11 @@
;
partDeclaration
- : partHeader (metadata topLevelDefinition)* EOF
+ : FEFF? partHeader (metadata topLevelDefinition)* EOF
;
-// In the specification a plain <stringLiteral> is used.
-// TODO(eernst): Check whether it creates ambiguities to do that.
uri
- : stringLiteralWithoutInterpolation
+ : stringLiteral
;
configurableUri
@@ -1510,16 +1501,6 @@
: '#' (operator | (identifier ('.' identifier)*) | VOID)
;
-// Not used in the specification (needed here for <uri>).
-singleStringWithoutInterpolation
- : RAW_SINGLE_LINE_STRING
- | RAW_MULTI_LINE_STRING
- | SINGLE_LINE_STRING_DQ_BEGIN_END
- | SINGLE_LINE_STRING_SQ_BEGIN_END
- | MULTI_LINE_STRING_DQ_BEGIN_END
- | MULTI_LINE_STRING_SQ_BEGIN_END
- ;
-
singleLineString
: RAW_SINGLE_LINE_STRING
| SINGLE_LINE_STRING_SQ_BEGIN_END