Skip to content

Commit

Permalink
Rename looksLikePatternVariableDeclaration.
Browse files Browse the repository at this point in the history
The new name, `looksLikeOuterPatternEquals`, is a more precise
description of what it does.

This helps prepare for adding parser support for pattern assignments,
which require the same functionality.

Bug: #50035
Change-Id: Ibfcc4c37faac1770c98a427facdffda5c40e6d08
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/272344
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Paul Berry <[email protected]>
  • Loading branch information
stereotype441 authored and Commit Queue committed Nov 28, 2022
1 parent e69a503 commit 2a9491b
Show file tree
Hide file tree
Showing 38 changed files with 44 additions and 42 deletions.
9 changes: 5 additions & 4 deletions pkg/_fe_analyzer_shared/lib/src/parser/parser_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7456,7 +7456,7 @@ class Parser {
(optional('var', varFinalOrConst) ||
optional('final', varFinalOrConst)) &&
!onlyParseVariableDeclarationStart &&
looksLikePatternVariableDeclaration(beforeType)) {
looksLikeOuterPatternEquals(beforeType)) {
// If there was any metadata, then the caller was responsible for parsing
// it; if not, then we need to let the listener know there wasn't any.
if (!optional('@', start.next!)) {
Expand Down Expand Up @@ -9763,12 +9763,13 @@ class Parser {
return token;
}

/// Returns `true` if the given [token] should be treated like the start of
/// a pattern variable declaration.
/// Returns `true` if the given [token] looks like an outer pattern followed
/// by `=`. This occurs in the following grammar productions:
///
/// patternVariableDeclaration ::= ( 'final' | 'var' ) outerPattern '='
/// expression
bool looksLikePatternVariableDeclaration(Token token) {
/// patternAssignment ::= outerPattern '=' expression
bool looksLikeOuterPatternEquals(Token token) {
Token? afterOuterPattern = skipOuterPattern(token);
if (afterOuterPattern == null) return false;
return optional('=', afterOuterPattern.next!);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ parseUnit(void)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
listener: beginMetadataStar(var)
listener: endMetadataStar(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ parseUnit(void)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
listener: beginMetadataStar(var)
listener: endMetadataStar(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ parseUnit(void)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
listener: beginMetadataStar(var)
listener: endMetadataStar(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ parseUnit(void)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
listener: beginMetadataStar(var)
listener: endMetadataStar(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ parseUnit(void)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
listener: beginMetadataStar(var)
listener: endMetadataStar(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ parseUnit(void)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
listener: beginMetadataStar(var)
listener: endMetadataStar(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ parseUnit(void)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
listener: beginMetadataStar(var)
listener: endMetadataStar(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ parseUnit(void)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
skipObjectPatternRest(Future)
listener: beginMetadataStar(var)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ parseUnit(void)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
skipObjectPatternRest(Future)
listener: beginMetadataStar(var)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ parseUnit(void)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
skipObjectPatternRest(_)
listener: beginMetadataStar(var)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ parseUnit(void)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
skipObjectPatternRest(_)
listener: beginMetadataStar(var)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ parseUnit(class)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
skipObjectPatternRest(C)
listener: beginMetadataStar(var)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ parseUnit(f)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
listener: beginMetadataStar(var)
listener: endMetadataStar(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ parseUnit(f)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(final, {, null, final, null, false)
looksLikePatternVariableDeclaration(final)
looksLikeOuterPatternEquals(final)
skipOuterPattern(final)
skipObjectPatternRest(C)
listener: beginMetadataStar(final)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ parseUnit(f)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
skipObjectPatternRest(C)
listener: beginMetadataStar(var)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ parseUnit(f)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
listener: beginMetadataStar(var)
listener: endMetadataStar(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ parseUnit(f)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
listener: beginMetadataStar(var)
listener: endMetadataStar(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ parseUnit(f)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
listener: beginMetadataStar(var)
listener: endMetadataStar(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ parseUnit(f)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
listener: beginMetadataStar(var)
listener: endMetadataStar(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ parseUnit(f)
listener: endMetadata(@, null, final)
listener: endMetadataStar(1)
parseExpressionStatementOrDeclarationAfterModifiers(final, {, null, final, null, false)
looksLikePatternVariableDeclaration(final)
looksLikeOuterPatternEquals(final)
skipOuterPattern(final)
skipObjectPatternRest(C)
parsePatternVariableDeclarationStatement(final, {, final)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ parseUnit(f)
listener: endMetadata(@, null, final)
listener: endMetadataStar(1)
parseExpressionStatementOrDeclarationAfterModifiers(final, {, null, final, null, false)
looksLikePatternVariableDeclaration(final)
looksLikeOuterPatternEquals(final)
skipOuterPattern(final)
parsePatternVariableDeclarationStatement(final, {, final)
parsePattern(final, precedence: 1, isRefutableContext: false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ parseUnit(f)
listener: endMetadata(@, null, final)
listener: endMetadataStar(1)
parseExpressionStatementOrDeclarationAfterModifiers(final, {, null, final, null, false)
looksLikePatternVariableDeclaration(final)
looksLikeOuterPatternEquals(final)
skipOuterPattern(final)
parsePatternVariableDeclarationStatement(final, {, final)
parsePattern(final, precedence: 1, isRefutableContext: false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ parseUnit(f)
listener: endMetadata(@, null, final)
listener: endMetadataStar(1)
parseExpressionStatementOrDeclarationAfterModifiers(final, {, null, final, null, false)
looksLikePatternVariableDeclaration(final)
looksLikeOuterPatternEquals(final)
skipOuterPattern(final)
parsePatternVariableDeclarationStatement(final, {, final)
parsePattern(final, precedence: 1, isRefutableContext: false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ parseUnit(f)
listener: endMetadata(@, null, final)
listener: endMetadataStar(1)
parseExpressionStatementOrDeclarationAfterModifiers(final, {, null, final, null, false)
looksLikePatternVariableDeclaration(final)
looksLikeOuterPatternEquals(final)
skipOuterPattern(final)
parsePatternVariableDeclarationStatement(final, {, final)
parsePattern(final, precedence: 1, isRefutableContext: false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ parseUnit(f)
listener: endMetadata(@, null, var)
listener: endMetadataStar(1)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
skipObjectPatternRest(C)
parsePatternVariableDeclarationStatement(var, {, var)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ parseUnit(f)
listener: endMetadata(@, null, var)
listener: endMetadataStar(1)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
parsePatternVariableDeclarationStatement(var, {, var)
parsePattern(var, precedence: 1, isRefutableContext: false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ parseUnit(f)
listener: endMetadata(@, null, var)
listener: endMetadataStar(1)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
parsePatternVariableDeclarationStatement(var, {, var)
parsePattern(var, precedence: 1, isRefutableContext: false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ parseUnit(f)
listener: endMetadata(@, null, var)
listener: endMetadataStar(1)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
parsePatternVariableDeclarationStatement(var, {, var)
parsePattern(var, precedence: 1, isRefutableContext: false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ parseUnit(f)
listener: endMetadata(@, null, var)
listener: endMetadataStar(1)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
parsePatternVariableDeclarationStatement(var, {, var)
parsePattern(var, precedence: 1, isRefutableContext: false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ parseUnit(void)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
listener: beginMetadataStar(var)
listener: endMetadataStar(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ parseUnit(void)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
listener: beginMetadataStar(var)
listener: endMetadataStar(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ parseUnit(void)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
listener: beginMetadataStar(var)
listener: endMetadataStar(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ parseUnit(UnmatchedToken({))
parseStatement(;)
parseStatementX(;)
parseExpressionStatementOrDeclarationAfterModifiers(var, ;, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
looksLikeLocalFunction(=)
listener: beginMetadataStar(var)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ parseUnit(void)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
listener: beginMetadataStar(var)
listener: endMetadataStar(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ parseUnit(void)
parseStatement({)
parseStatementX({)
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, false)
looksLikePatternVariableDeclaration(var)
looksLikeOuterPatternEquals(var)
skipOuterPattern(var)
listener: beginMetadataStar(var)
listener: endMetadataStar(0)
Expand Down
6 changes: 3 additions & 3 deletions pkg/front_end/test/parser_test_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2749,10 +2749,10 @@ class TestParser extends Parser {
}

@override
bool looksLikePatternVariableDeclaration(Token token) {
doPrint('looksLikePatternVariableDeclaration(' '$token)');
bool looksLikeOuterPatternEquals(Token token) {
doPrint('looksLikeOuterPatternEquals(' '$token)');
indent++;
var result = super.looksLikePatternVariableDeclaration(token);
var result = super.looksLikeOuterPatternEquals(token);
indent--;
return result;
}
Expand Down
1 change: 1 addition & 0 deletions pkg/front_end/test/spell_checking_list_code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,7 @@ processes
processor
producers
product
productions
profile
progresses
prohibited
Expand Down

0 comments on commit 2a9491b

Please sign in to comment.