Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 275b922

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Revert recent parser fixes
Commit 1f9b5c1 causes tests to fail in angular when rolled into internal sources; the other two commits need to be reverted as well to avoid merge conflicts. This reverts commit 1f9b5c1. This reverts commit c40b24d. This reverts commit 96df1f9. Change-Id: Ic4e55181ef60e825ce4409a9a9528ecbf19c39c4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/147822 Reviewed-by: Mike Fairhurst <mfairhurst@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
1 parent 40d8763 commit 275b922

65 files changed

Lines changed: 72 additions & 2731 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pkg/_fe_analyzer_shared/lib/src/parser/parser_impl.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3120,8 +3120,6 @@ class Parser {
31203120
return token.type.isReservedWord;
31213121
}
31223122

3123-
/// Whether [token] (the token right after a potential name) indicates it to
3124-
/// be a method or field definition.
31253123
bool indicatesMethodOrField(Token token) {
31263124
String value = token.stringValue;
31273125
if (identical(value, ';') ||
@@ -4927,8 +4925,7 @@ class Parser {
49274925
Token parseLiteralListSuffix(Token token, Token constKeyword) {
49284926
Token beforeToken = token;
49294927
Token beginToken = token = token.next;
4930-
assert(optional('[', token) || optional('[]', token),
4931-
"Token isn't as expected: ${token?.lexeme}");
4928+
assert(optional('[', token) || optional('[]', token));
49324929
int count = 0;
49334930
if (optional('[]', token)) {
49344931
token = rewriteSquareBrackets(beforeToken).next;

pkg/_fe_analyzer_shared/lib/src/scanner/abstract_scanner.dart

Lines changed: 8 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import 'characters.dart';
2727
import 'error_token.dart'
2828
show
2929
NonAsciiIdentifierToken,
30-
UnmatchedEndToken,
3130
UnmatchedToken,
3231
UnsupportedOperator,
3332
UnterminatedString,
@@ -125,35 +124,15 @@ abstract class AbstractScanner implements Scanner {
125124
*/
126125
Link<BeginToken> groupingStack = const Link<BeginToken>();
127126

128-
final bool inRecoveryOption;
129-
int recoveryCount = 0;
130-
131127
AbstractScanner(ScannerConfiguration config, this.includeComments,
132128
this.languageVersionChanged,
133129
{int numberOfBytesHint})
134-
: lineStarts = new LineStarts(numberOfBytesHint),
135-
inRecoveryOption = false {
130+
: lineStarts = new LineStarts(numberOfBytesHint) {
136131
this.tail = this.tokens;
137132
this.errorTail = this.tokens;
138133
this.configuration = config;
139134
}
140135

141-
AbstractScanner createRecoveryOptionScanner();
142-
143-
AbstractScanner.recoveryOptionScanner(AbstractScanner copyFrom)
144-
: lineStarts = [],
145-
includeComments = false,
146-
languageVersionChanged = null,
147-
inRecoveryOption = true {
148-
this.tail = this.tokens;
149-
this.errorTail = this.tokens;
150-
this._enableExtensionMethods = copyFrom._enableExtensionMethods;
151-
this._enableNonNullable = copyFrom._enableNonNullable;
152-
this._enableTripleShift = copyFrom._enableTripleShift;
153-
this.tokenStart = copyFrom.tokenStart;
154-
this.groupingStack = copyFrom.groupingStack;
155-
}
156-
157136
@override
158137
set configuration(ScannerConfiguration config) {
159138
if (config != null) {
@@ -383,22 +362,9 @@ abstract class AbstractScanner implements Scanner {
383362
*/
384363
int appendEndGroup(TokenType type, int openKind) {
385364
assert(!identical(openKind, LT_TOKEN)); // openKind is < for > and >>
386-
bool foundMatchingBrace = discardBeginGroupUntil(openKind);
387-
return appendEndGroupInternal(foundMatchingBrace, type, openKind);
388-
}
389-
390-
/// Append the end group (parenthesis, bracket etc).
391-
/// If [foundMatchingBrace] is true the grouping stack (stack of parenthesis
392-
/// etc) is updated, otherwise it's left alone.
393-
/// In effect, if [foundMatchingBrace] is false this end token is basically
394-
/// ignored, i.e. not really seen as an end group.
395-
int appendEndGroupInternal(
396-
bool foundMatchingBrace, TokenType type, int openKind) {
397-
if (!foundMatchingBrace) {
398-
// No begin group. Leave the grouping stack alone and just continue.
399-
Token ignoredToken = new Token(type, tokenStart, comments);
400-
appendToken(ignoredToken);
401-
prependErrorToken(new UnmatchedEndToken(ignoredToken));
365+
if (!discardBeginGroupUntil(openKind)) {
366+
// No begin group found. Just continue.
367+
appendPrecedenceToken(type);
402368
return advance();
403369
}
404370
appendPrecedenceToken(type);
@@ -506,7 +472,7 @@ abstract class AbstractScanner implements Scanner {
506472
* then discard begin group tokens up to that match and return `true`,
507473
* otherwise return `false`.
508474
* This recovers nicely from from situations like "{[}" and "{foo());}",
509-
* but not "foo(() {bar());});"
475+
* but not "foo(() {bar());});
510476
*/
511477
bool discardBeginGroupUntil(int openKind) {
512478
Link<BeginToken> originalStack = groupingStack;
@@ -533,8 +499,6 @@ abstract class AbstractScanner implements Scanner {
533499
groupingStack = groupingStack.tail;
534500
} while (!groupingStack.isEmpty);
535501

536-
recoveryCount++;
537-
538502
// If the stack does not have any opener of the given type,
539503
// then return without discarding anything.
540504
// This recovers nicely from from situations like "{foo());}".
@@ -543,90 +507,16 @@ abstract class AbstractScanner implements Scanner {
543507
return false;
544508
}
545509

546-
// We found a matching group somewhere in the stack, but generally don't
547-
// know if we should recover by inserting synthetic closers or
548-
// basically ignore the current token.
549-
// We're in a recovery setting so we're allowed to be 'relatively slow' ---
550-
// try both and see which is better (i.e. gives fewest rewrites later).
551-
// To not get exponential runtime we will not do this nested though.
552-
// E.g. we can recover "{[}" as "{[]}" (better) or (with . for ignored
553-
// tokens) "{[.".
554-
// Or we can recover "[(])]" as "[()].." or "[(.)]" (better).
555-
if (!inRecoveryOption) {
556-
TokenType type;
557-
switch (openKind) {
558-
case OPEN_SQUARE_BRACKET_TOKEN:
559-
type = TokenType.CLOSE_SQUARE_BRACKET;
560-
break;
561-
case OPEN_CURLY_BRACKET_TOKEN:
562-
type = TokenType.CLOSE_CURLY_BRACKET;
563-
break;
564-
case OPEN_PAREN_TOKEN:
565-
type = TokenType.CLOSE_PAREN;
566-
break;
567-
default:
568-
throw new StateError("Unexpected openKind");
569-
}
570-
571-
// Option #1: Insert synthetic closers.
572-
int option1Recoveries;
573-
{
574-
AbstractScanner option1 = createRecoveryOptionScanner();
575-
option1.insertSyntheticClosers(originalStack, groupingStack);
576-
option1Recoveries =
577-
option1.recoveryOptionTokenizer(option1.appendEndGroupInternal(
578-
/* foundMatchingBrace = */ true,
579-
type,
580-
openKind));
581-
option1Recoveries += option1.groupingStack.slowLength();
582-
}
583-
584-
// Option #2: ignore this token.
585-
int option2Recoveries;
586-
{
587-
AbstractScanner option2 = createRecoveryOptionScanner();
588-
option2.groupingStack = originalStack;
589-
option2Recoveries =
590-
option2.recoveryOptionTokenizer(option2.appendEndGroupInternal(
591-
/* foundMatchingBrace = */ false,
592-
type,
593-
openKind));
594-
// We add 1 to make this option pay for ignoring this token.
595-
option2Recoveries += option2.groupingStack.slowLength() + 1;
596-
}
597-
598-
// The option-runs might have set invalid endGroup pointers. Reset them.
599-
for (Link<BeginToken> link = originalStack;
600-
link.isNotEmpty;
601-
link = link.tail) {
602-
link.head.endToken = null;
603-
}
604-
605-
if (option2Recoveries < option1Recoveries) {
606-
// Perform option #2 recovery.
607-
groupingStack = originalStack;
608-
return false;
609-
}
610-
// option #1 is the default, so fall though.
611-
}
612-
613-
// Insert synthetic closers and report errors for any unbalanced openers.
614-
// This recovers nicely from from situations like "{[}".
615-
insertSyntheticClosers(originalStack, groupingStack);
616-
return true;
617-
}
618-
619-
void insertSyntheticClosers(
620-
Link<BeginToken> originalStack, Link<BeginToken> entryToUse) {
621510
// Insert synthetic closers and report errors for any unbalanced openers.
622511
// This recovers nicely from from situations like "{[}".
623-
while (!identical(originalStack, entryToUse)) {
512+
while (!identical(originalStack, groupingStack)) {
624513
// Don't report unmatched errors for <; it is also the less-than operator.
625-
if (!identical(entryToUse.head.kind, LT_TOKEN)) {
514+
if (!identical(groupingStack.head.kind, LT_TOKEN)) {
626515
unmatchedBeginGroup(originalStack.head);
627516
}
628517
originalStack = originalStack.tail;
629518
}
519+
return true;
630520
}
631521

632522
/**
@@ -711,7 +601,6 @@ abstract class AbstractScanner implements Scanner {
711601
appendToken(new SyntheticToken(type, tokenStart)..beforeSynthetic = tail);
712602
begin.endGroup = tail;
713603
prependErrorToken(new UnmatchedToken(begin));
714-
recoveryCount++;
715604
}
716605

717606
/// Return true when at EOF.
@@ -751,26 +640,6 @@ abstract class AbstractScanner implements Scanner {
751640
return firstToken();
752641
}
753642

754-
/// Tokenize a (small) part of the data. Used for recovery "option testing".
755-
///
756-
/// Returns the number of recoveries performed.
757-
int recoveryOptionTokenizer(int next) {
758-
int iterations = 0;
759-
while (!atEndOfFile()) {
760-
while (!identical(next, $EOF)) {
761-
// TODO(jensj): Look at number of lines, tokens, parenthesis stack,
762-
// semi-colon etc, not just number of iterations.
763-
next = bigSwitch(next);
764-
iterations++;
765-
766-
if (iterations > 100) {
767-
break;
768-
}
769-
}
770-
}
771-
return recoveryCount;
772-
}
773-
774643
int bigHeaderSwitch(int next) {
775644
if (!identical(next, $SLASH)) {
776645
return bigSwitch(next);

pkg/_fe_analyzer_shared/lib/src/scanner/error_token.dart

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import '../messages/codes.dart'
1616
templateUnsupportedOperator,
1717
templateUnterminatedString;
1818

19-
import 'recover.dart' show closeBraceFor, closeQuoteFor, openBraceFor;
19+
import 'recover.dart' show closeBraceFor, closeQuoteFor;
2020

2121
import 'scanner.dart' show Token, unicodeReplacementCharacter;
2222

@@ -215,20 +215,3 @@ class UnmatchedToken extends ErrorToken {
215215
Message get assertionMessage =>
216216
templateUnmatchedToken.withArguments(closeBraceFor(begin.lexeme), begin);
217217
}
218-
219-
/// Represents a close brace without a matching open brace.
220-
///
221-
/// In this case, brace means any of `)`, `}`, `]`, parenthesis, curly
222-
/// brace and square brace, respectively.
223-
class UnmatchedEndToken extends ErrorToken {
224-
final Token endToken;
225-
226-
UnmatchedEndToken(Token endToken)
227-
: this.endToken = endToken,
228-
super(endToken.charOffset);
229-
230-
String toString() => "UnmatchedEndToken(${endToken.lexeme})";
231-
232-
Message get assertionMessage => templateUnmatchedToken.withArguments(
233-
openBraceFor(endToken.lexeme), endToken);
234-
}

pkg/_fe_analyzer_shared/lib/src/scanner/errors.dart

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import '../base/errors.dart' show ErrorCode, ErrorSeverity, ErrorType;
6-
7-
import '../messages/codes.dart'
8-
show Code, codeUnexpectedDollarInString, codeUnmatchedToken;
9-
10-
import 'error_token.dart'
11-
show ErrorToken, UnmatchedEndToken, UnsupportedOperator;
12-
13-
import 'token_constants.dart' show BAD_INPUT_TOKEN;
14-
5+
import '../base/errors.dart';
6+
import '../messages/codes.dart';
7+
import 'error_token.dart';
8+
import 'token_constants.dart';
159
import 'token.dart' show Token, TokenType;
1610

1711
/**
@@ -25,13 +19,6 @@ class ScannerErrorCode extends ErrorCode {
2519
static const ScannerErrorCode EXPECTED_TOKEN =
2620
const ScannerErrorCode('EXPECTED_TOKEN', "Expected to find '{0}'.");
2721

28-
/**
29-
* Parameters:
30-
* 0: the token that was unexpected but found
31-
*/
32-
static const ScannerErrorCode UNEXPECTED_TOKEN =
33-
const ScannerErrorCode('UNEXPECTED_TOKEN', "Unexpected text '{0}'.");
34-
3522
/**
3623
* Parameters:
3724
* 0: the illegal character
@@ -163,11 +150,6 @@ void translateErrorToken(ErrorToken token, ReportError reportError) {
163150

164151
default:
165152
if (errorCode == codeUnmatchedToken) {
166-
if (token is UnmatchedEndToken) {
167-
charOffset = token.endToken.charOffset;
168-
return _makeError(
169-
ScannerErrorCode.UNEXPECTED_TOKEN, [token.endToken.lexeme]);
170-
}
171153
charOffset = token.begin.endToken.charOffset;
172154
TokenType type = token.begin?.type;
173155
if (type == TokenType.OPEN_CURLY_BRACKET ||

pkg/_fe_analyzer_shared/lib/src/scanner/recover.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,6 @@ String closeBraceFor(String openBrace) {
7070
}[openBrace];
7171
}
7272

73-
String openBraceFor(String closeBrace) {
74-
return const {
75-
')': '(',
76-
']': '[',
77-
'}': '{',
78-
}[closeBrace];
79-
}
80-
8173
String closeQuoteFor(String openQuote) {
8274
return const {
8375
'"': '"',

pkg/_fe_analyzer_shared/lib/src/scanner/string_scanner.dart

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@ class StringScanner extends AbstractScanner {
3434
: string = ensureZeroTermination(string),
3535
super(configuration, includeComments, languageVersionChanged);
3636

37-
StringScanner.recoveryOptionScanner(StringScanner copyFrom)
38-
: super.recoveryOptionScanner(copyFrom) {
39-
string = copyFrom.string;
40-
scanOffset = copyFrom.scanOffset;
41-
}
42-
43-
StringScanner createRecoveryOptionScanner() {
44-
return new StringScanner.recoveryOptionScanner(this);
45-
}
46-
4737
static String ensureZeroTermination(String string) {
4838
return (string.isEmpty || string.codeUnitAt(string.length - 1) != 0)
4939
// TODO(lry): abort instead of copying the array, or warn?

pkg/_fe_analyzer_shared/lib/src/scanner/utf8_bytes_scanner.dart

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,6 @@ class Utf8BytesScanner extends AbstractScanner {
9797
}
9898
}
9999

100-
Utf8BytesScanner.createRecoveryOptionScanner(Utf8BytesScanner copyFrom)
101-
: super.recoveryOptionScanner(copyFrom) {
102-
this.bytes = copyFrom.bytes;
103-
this.byteOffset = copyFrom.byteOffset;
104-
this.scanSlack = copyFrom.scanSlack;
105-
this.scanSlackOffset = copyFrom.scanSlackOffset;
106-
this.utf8Slack = copyFrom.utf8Slack;
107-
}
108-
109-
Utf8BytesScanner createRecoveryOptionScanner() {
110-
return new Utf8BytesScanner.createRecoveryOptionScanner(this);
111-
}
112-
113100
bool containsBomAt(int offset) {
114101
const List<int> BOM_UTF8 = const [0xEF, 0xBB, 0xBF];
115102

pkg/analyzer/lib/error/error.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,6 @@ const List<ErrorCode> errorCodeValues = [
681681
ScannerErrorCode.MISSING_QUOTE,
682682
ScannerErrorCode.UNABLE_GET_CONTENT,
683683
ScannerErrorCode.UNEXPECTED_DOLLAR_IN_STRING,
684-
ScannerErrorCode.UNEXPECTED_TOKEN,
685684
ScannerErrorCode.UNSUPPORTED_OPERATOR,
686685
ScannerErrorCode.UNTERMINATED_MULTI_LINE_COMMENT,
687686
ScannerErrorCode.UNTERMINATED_STRING_LITERAL,

pkg/analyzer/lib/src/dart/scanner/scanner.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class Scanner {
133133
void reportError(
134134
ScannerErrorCode errorCode, int offset, List<Object> arguments) {
135135
_errorListener
136-
?.onError(AnalysisError(source, offset, 1, errorCode, arguments));
136+
.onError(AnalysisError(source, offset, 1, errorCode, arguments));
137137
}
138138

139139
void setSourceStart(int line, int column) {

0 commit comments

Comments
 (0)