Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: pkg/front_end/lib/src/fasta/parser/token_stream_rewriter.dart

Issue 2970273004: Deprecate all diagnostics methods that use strings. (Closed)
Patch Set: Merged with 4df146dd9a465d63344330bf3e45524b927c92ec Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/front_end/lib/src/fasta/modifier.dart ('k') | pkg/front_end/lib/src/fasta/quote.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'package:front_end/src/fasta/errors.dart'; 5 import 'package:front_end/src/fasta/deprecated_problems.dart';
6 import 'package:front_end/src/scanner/token.dart' show BeginToken, Token; 6 import 'package:front_end/src/scanner/token.dart' show BeginToken, Token;
7 7
8 /// Provides the capability of inserting tokens into a token stream by rewriting 8 /// Provides the capability of inserting tokens into a token stream by rewriting
9 /// the previous token to point to the inserted token. 9 /// the previous token to point to the inserted token.
10 /// 10 ///
11 /// This class has been designed to take advantage of "previousToken" pointers 11 /// This class has been designed to take advantage of "previousToken" pointers
12 /// when they are present, but not to depend on them. When they are not 12 /// when they are present, but not to depend on them. When they are not
13 /// present, it uses heuristics to try to find the find the previous token as 13 /// present, it uses heuristics to try to find the find the previous token as
14 /// quickly as possible by walking through tokens starting at the start of the 14 /// quickly as possible by walking through tokens starting at the start of the
15 /// file. 15 /// file.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // if it makes sense to do so. 67 // if it makes sense to do so.
68 if (_lastPreviousToken != null && 68 if (_lastPreviousToken != null &&
69 target.charOffset >= _lastPreviousToken.charOffset) { 69 target.charOffset >= _lastPreviousToken.charOffset) {
70 Token previous = _scanForPreviousToken(target, _lastPreviousToken); 70 Token previous = _scanForPreviousToken(target, _lastPreviousToken);
71 if (previous != null) return previous; 71 if (previous != null) return previous;
72 } 72 }
73 73
74 // Otherwise scan forward from the start of the token stream. 74 // Otherwise scan forward from the start of the token stream.
75 Token previous = _scanForPreviousToken(target, _head); 75 Token previous = _scanForPreviousToken(target, _head);
76 if (previous == null) { 76 if (previous == null) {
77 internalError('Could not find previous token'); 77 deprecated_internalProblem('Could not find previous token');
78 } 78 }
79 return previous; 79 return previous;
80 } 80 }
81 81
82 /// Searches for the token that immediately precedes [target], using [pos] as 82 /// Searches for the token that immediately precedes [target], using [pos] as
83 /// a starting point. 83 /// a starting point.
84 /// 84 ///
85 /// Uses heuristics to skip matching `{}`, `[]`, `()`, and `<>` if possible. 85 /// Uses heuristics to skip matching `{}`, `[]`, `()`, and `<>` if possible.
86 /// 86 ///
87 /// If no such token is found, returns `null`. 87 /// If no such token is found, returns `null`.
88 Token _scanForPreviousToken(Token target, Token pos) { 88 Token _scanForPreviousToken(Token target, Token pos) {
89 while (!identical(pos.next, target)) { 89 while (!identical(pos.next, target)) {
90 Token nextPos; 90 Token nextPos;
91 if (pos is BeginToken && 91 if (pos is BeginToken &&
92 pos.endGroup != null && 92 pos.endGroup != null &&
93 pos.endGroup.charOffset < target.charOffset) { 93 pos.endGroup.charOffset < target.charOffset) {
94 nextPos = pos.endGroup; 94 nextPos = pos.endGroup;
95 } else { 95 } else {
96 nextPos = pos.next; 96 nextPos = pos.next;
97 if (nextPos == null || nextPos.charOffset > target.charOffset) { 97 if (nextPos == null || nextPos.charOffset > target.charOffset) {
98 return null; 98 return null;
99 } 99 }
100 } 100 }
101 pos = nextPos; 101 pos = nextPos;
102 } 102 }
103 return pos; 103 return pos;
104 } 104 }
105 } 105 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/modifier.dart ('k') | pkg/front_end/lib/src/fasta/quote.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698