@@ -55,22 +55,22 @@ class Listener implements UnescapeErrorListener {
5555 logEvent ("AsyncModifier" );
5656 }
5757
58+ /// Ended by either [endAwaitExpression] or [endInvalidAwaitExpression] .
5859 void beginAwaitExpression (Token token) {}
5960
61+ /// One of the two possible corresponding end events for
62+ /// [beginAwaitExpression] .
6063 void endAwaitExpression (Token beginToken, Token endToken) {
6164 logEvent ("AwaitExpression" );
6265 }
6366
67+ /// One of the two possible corresponding end events for
68+ /// [beginAwaitExpression] .
6469 void endInvalidAwaitExpression (
6570 Token beginToken, Token endToken, MessageCode errorCode) {
6671 logEvent ("InvalidAwaitExpression" );
6772 }
6873
69- void endInvalidYieldStatement (Token beginToken, Token starToken,
70- Token endToken, MessageCode errorCode) {
71- logEvent ("InvalidYieldStatement" );
72- }
73-
7474 void beginBlock (Token token, BlockKind blockKind) {}
7575
7676 void endBlock (
@@ -111,8 +111,11 @@ class Listener implements UnescapeErrorListener {
111111
112112 /// Called before parsing a class or named mixin application.
113113 ///
114- /// At this point only the `class` keyword have been seen, so we know a
115- /// declaration is coming but not its name or type parameter declarations.
114+ /// At this point only the `class` or `mixin` keyword have been seen,
115+ /// so we know a declaration is coming but not its name or type
116+ /// parameter declarations.
117+ ///
118+ /// Ended by [endTopLevelDeclaration] .
116119 void beginClassOrNamedMixinApplicationPrelude (Token token) {}
117120
118121 /// Handle the beginning of a class declaration.
@@ -208,11 +211,18 @@ class Listener implements UnescapeErrorListener {
208211 logEvent ("MixinDeclaration" );
209212 }
210213
214+ /// Begins a not-further-categorized top-level declaration.
215+ ///
216+ /// Ended by [endTopLevelDeclaration] .
217+ void beginUncategorizedTopLevelDeclaration (Token token) {}
218+
211219 /// Handle the beginning of an extension methods declaration. Substructures:
212220 /// - metadata
213221 ///
214222 /// At this point only the `extension` keyword have been seen, so we know a
215223 /// declaration is coming but not its name or type parameter declarations.
224+ ///
225+ /// Ended by [endTopLevelDeclaration] .
216226 void beginExtensionDeclarationPrelude (Token extensionKeyword) {}
217227
218228 /// Handle the beginning of an extension methods declaration. Substructures:
@@ -315,6 +325,8 @@ class Listener implements UnescapeErrorListener {
315325 logEvent ("ExpressionStatement" );
316326 }
317327
328+ /// Note that this is ended by [endClassFactoryMethod] ,
329+ /// [endMixinFactoryMethod] or [endExtensionFactoryMethod] .
318330 void beginFactoryMethod (
319331 Token lastConsumed, Token externalToken, Token constToken) {}
320332
@@ -366,7 +378,7 @@ class Listener implements UnescapeErrorListener {
366378 /// - Type
367379 /// - Variable declarations (count times)
368380 ///
369- /// Doesn't have a corresponding begin event, use [beginMember] instead .
381+ /// Started by [beginFields] .
370382 void endClassFields (
371383 Token abstractToken,
372384 Token externalToken,
@@ -386,7 +398,7 @@ class Listener implements UnescapeErrorListener {
386398 /// - Type
387399 /// - Variable declarations (count times)
388400 ///
389- /// Doesn't have a corresponding begin event, use [beginMember] instead .
401+ /// Started by [beginFields] .
390402 void endMixinFields (
391403 Token abstractToken,
392404 Token externalToken,
@@ -408,7 +420,7 @@ class Listener implements UnescapeErrorListener {
408420 /// - Type
409421 /// - Variable declarations (count times)
410422 ///
411- /// Doesn't have a corresponding begin event, use [beginMember] instead .
423+ /// Started by [beginFields] .
412424 void endExtensionFields (
413425 Token abstractToken,
414426 Token externalToken,
@@ -829,6 +841,10 @@ class Listener implements UnescapeErrorListener {
829841 logEvent ("StringJuxtaposition" );
830842 }
831843
844+ /// Called for class-like members (class, mixin, extension), but each member
845+ /// should also have a more specific begin/end pair, e.g.
846+ /// [beginFactoryMethod] /[endClassFactoryMethod] /[endMixinFactoryMethod] /
847+ /// [endExtensionFactoryMethod] .
832848 void beginMember () {}
833849
834850 /// Handle an invalid member declaration. Substructures:
@@ -837,7 +853,10 @@ class Listener implements UnescapeErrorListener {
837853 logEvent ("InvalidMember" );
838854 }
839855
840- /// This event is added for convenience. Normally, one should override
856+ /// This event is added for convenience to the listener.
857+ /// Members will actually be begin/end'ed by more specific
858+ /// events as well.
859+ /// Normally listeners should probably override
841860 /// [endClassFields] , [endMixinFields] , [endExtensionFields] ,
842861 /// [endClassMethod] , [endMixinMethod] , [endExtensionMethod] ,
843862 /// [endClassConstructor] , [endMixinConstructor] ,
@@ -846,8 +865,11 @@ class Listener implements UnescapeErrorListener {
846865 logEvent ("Member" );
847866 }
848867
849- /// Handle the beginning of a method declaration. Substructures:
868+ /// Handle the beginning of a class-like method declaration. Substructures:
850869 /// - metadata
870+ /// Note that this is ended with [endClassConstructor] , [endClassMethod] ,
871+ /// [endExtensionConstructor] , [endExtensionMethod] , [endMixinConstructor] or
872+ /// [endMixinMethod] .
851873 void beginMethod (Token externalToken, Token staticToken, Token covariantToken,
852874 Token varFinalOrConst, Token getOrSet, Token name) {}
853875
@@ -1075,11 +1097,21 @@ class Listener implements UnescapeErrorListener {
10751097 logEvent ("RethrowStatement" );
10761098 }
10771099
1078- /// This event is added for convenience. Normally, one should use
1100+ /// This event is added for convenience for the listener.
1101+ /// All top-level declarations will actually be begin/end'ed by more specific
1102+ /// events as well, e.g. [beginClassDeclaration] /[endClassDeclaration] ,
1103+ /// [beginEnum] /[endEnum] etc.
1104+ ///
1105+ /// Normally listeners should probably override
10791106 /// [endClassDeclaration] , [endNamedMixinApplication] , [endEnum] ,
10801107 /// [endFunctionTypeAlias] , [endLibraryName] , [endImport] , [endExport] ,
1081- /// [endPart] , [endPartOf] , [endTopLevelFields] , or [endTopLevelMethod] .
1082- void endTopLevelDeclaration (Token token) {
1108+ /// [endPart] , [endPartOf] , [endTopLevelFields] , or [endTopLevelMethod]
1109+ /// instead.
1110+ ///
1111+ /// Started by one of [beginExtensionDeclarationPrelude] ,
1112+ /// [beginClassOrNamedMixinApplicationPrelude] , [beginTopLevelMember] or
1113+ /// [beginUncategorizedTopLevelDeclaration] .
1114+ void endTopLevelDeclaration (Token nextToken) {
10831115 logEvent ("TopLevelDeclaration" );
10841116 }
10851117
@@ -1095,18 +1127,24 @@ class Listener implements UnescapeErrorListener {
10951127 }
10961128
10971129 /// Marks the beginning of a top level field or method declaration.
1098- /// Doesn't have a corresponding end event.
1099- /// See [endTopLevelFields] and [endTopLevelMethod] .
1130+ /// See also [endTopLevelFields] and [endTopLevelMethod] .
1131+ ///
1132+ /// Ended by [endTopLevelDeclaration] .
11001133 void beginTopLevelMember (Token token) {}
11011134
1135+ /// Marks the beginning of a fields declaration.
1136+ /// Note that this is ended with [endTopLevelFields] , [endClassFields] ,
1137+ /// [endMixinFields] or [endExtensionFields] .
1138+ void beginFields (Token lastConsumed) {}
1139+
11021140 /// Handle the end of a top level variable declaration. Substructures:
11031141 /// - Metadata
11041142 /// - Type
11051143 /// - Repeated [count] times:
11061144 /// - Variable name (identifier)
11071145 /// - Field initializer
1108- /// Doesn't have a corresponding begin event.
1109- /// Use [beginTopLevelMember] instead .
1146+ ///
1147+ /// Started by [beginFields] .
11101148 void endTopLevelFields (
11111149 Token externalToken,
11121150 Token staticToken,
@@ -1291,6 +1329,12 @@ class Listener implements UnescapeErrorListener {
12911329 logEvent ("BinaryExpression" );
12921330 }
12931331
1332+ /// Called for `.` , `?.` and `..` .
1333+ void handleEndingBinaryExpression (Token token) {
1334+ // TODO(jensj): push implementation into subclasses
1335+ endBinaryExpression (token);
1336+ }
1337+
12941338 /// Called when the parser encounters a `?` operator and begins parsing a
12951339 /// conditional expression.
12961340 void beginConditionalExpression (Token question) {}
@@ -1311,24 +1355,30 @@ class Listener implements UnescapeErrorListener {
13111355 }
13121356
13131357 /// Called before parsing a "for" control flow list, set, or map entry.
1358+ /// Ended by either [endForControlFlow] or [endForInControlFlow] .
13141359 void beginForControlFlow (Token awaitToken, Token forToken) {}
13151360
13161361 /// Called after parsing a "for" control flow list, set, or map entry.
1362+ /// One of the two possible corresponding end events for
1363+ /// [beginForControlFlow] .
13171364 void endForControlFlow (Token token) {
13181365 logEvent ('endForControlFlow' );
13191366 }
13201367
13211368 /// Called after parsing a "for-in" control flow list, set, or map entry.
1369+ /// One of the two possible corresponding end events for
1370+ /// [beginForControlFlow] .
13221371 void endForInControlFlow (Token token) {
13231372 logEvent ('endForInControlFlow' );
13241373 }
13251374
13261375 /// Called before parsing an `if` control flow list, set, or map entry.
1376+ /// Ended by either [endIfControlFlow] or [endIfElseControlFlow] .
13271377 void beginIfControlFlow (Token ifToken) {}
13281378
13291379 /// Called before parsing the `then` portion of an `if` control flow list,
13301380 /// set, or map entry.
1331- void beginThenControlFlow (Token token) {}
1381+ void handleThenControlFlow (Token token) {}
13321382
13331383 /// Called before parsing the `else` portion of an `if` control flow list,
13341384 /// set, or map entry.
@@ -1340,6 +1390,8 @@ class Listener implements UnescapeErrorListener {
13401390 /// Substructures:
13411391 /// - if conditional expression
13421392 /// - expression
1393+ /// One of the two possible corresponding end events for
1394+ /// [beginIfControlFlow] .
13431395 void endIfControlFlow (Token token) {
13441396 logEvent ("endIfControlFlow" );
13451397 }
@@ -1349,6 +1401,8 @@ class Listener implements UnescapeErrorListener {
13491401 /// - if conditional expression
13501402 /// - then expression
13511403 /// - else expression
1404+ /// One of the two possible corresponding end events for
1405+ /// [beginIfControlFlow] .
13521406 void endIfElseControlFlow (Token token) {
13531407 logEvent ("endIfElseControlFlow" );
13541408 }
@@ -1589,12 +1643,22 @@ class Listener implements UnescapeErrorListener {
15891643 logEvent ("handleVoidKeywordWithTypeArguments" );
15901644 }
15911645
1646+ /// Ended by either [endYieldStatement] or [endInvalidYieldStatement] .
15921647 void beginYieldStatement (Token token) {}
15931648
1649+ /// One of the two possible corresponding end events for
1650+ /// [beginYieldStatement] .
15941651 void endYieldStatement (Token yieldToken, Token starToken, Token endToken) {
15951652 logEvent ("YieldStatement" );
15961653 }
15971654
1655+ /// One of the two possible corresponding end events for
1656+ /// [beginYieldStatement] .
1657+ void endInvalidYieldStatement (Token beginToken, Token starToken,
1658+ Token endToken, MessageCode errorCode) {
1659+ logEvent ("InvalidYieldStatement" );
1660+ }
1661+
15981662 /// The parser noticed a syntax error, but was able to recover from it. The
15991663 /// error should be reported using the [message] , and the code between the
16001664 /// beginning of the [startToken] and the end of the [endToken] should be
0 commit comments