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

Side by Side Diff: pkg/front_end/lib/src/scanner/errors.dart

Issue 2996673002: translate missing ">" fasta error code to analyzer error (Closed)
Patch Set: Created 3 years, 4 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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/base/errors.dart'; 5 import 'package:front_end/src/base/errors.dart';
6 import 'package:front_end/src/fasta/fasta_codes.dart'; 6 import 'package:front_end/src/fasta/fasta_codes.dart';
7 import 'package:front_end/src/fasta/scanner/error_token.dart'; 7 import 'package:front_end/src/fasta/scanner/error_token.dart';
8 import 'package:front_end/src/scanner/token.dart' show Token, TokenType; 8 import 'package:front_end/src/scanner/token.dart' show Token, TokenType;
9 import 'package:front_end/src/fasta/scanner/token_constants.dart'; 9 import 'package:front_end/src/fasta/scanner/token_constants.dart';
10 10
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 case "MISSING_HEX_DIGIT": 122 case "MISSING_HEX_DIGIT":
123 // TODO(paulberry,ahe): Fasta reports the error location as the entire 123 // TODO(paulberry,ahe): Fasta reports the error location as the entire
124 // number; analyzer expects the end of the number. 124 // number; analyzer expects the end of the number.
125 charOffset = endOffset - 1; 125 charOffset = endOffset - 1;
126 return _makeError(ScannerErrorCode.MISSING_HEX_DIGIT, null); 126 return _makeError(ScannerErrorCode.MISSING_HEX_DIGIT, null);
127 127
128 case "ILLEGAL_CHARACTER": 128 case "ILLEGAL_CHARACTER":
129 return _makeError(ScannerErrorCode.ILLEGAL_CHARACTER, [token.character]); 129 return _makeError(ScannerErrorCode.ILLEGAL_CHARACTER, [token.character]);
130 130
131 default: 131 default:
132 if (errorCode == codeUnmatchedToken) { 132 if (errorCode == codeUnmatchedToken) {
ahe 2017/08/09 07:04:41 Perhaps we should start thinking about how to simp
danrubel 2017/08/11 18:06:50 Good ideas. I will address these in a future CL.
133 TokenType type = token.begin?.type; 133 TokenType type = token.begin?.type;
134 if (type == TokenType.OPEN_CURLY_BRACKET || 134 if (type == TokenType.OPEN_CURLY_BRACKET ||
135 type == TokenType.STRING_INTERPOLATION_EXPRESSION) { 135 type == TokenType.STRING_INTERPOLATION_EXPRESSION) {
136 return _makeError(ScannerErrorCode.EXPECTED_TOKEN, ['}']); 136 return _makeError(ScannerErrorCode.EXPECTED_TOKEN, ['}']);
137 } 137 }
138 if (type == TokenType.OPEN_SQUARE_BRACKET) { 138 if (type == TokenType.OPEN_SQUARE_BRACKET) {
139 return _makeError(ScannerErrorCode.EXPECTED_TOKEN, [']']); 139 return _makeError(ScannerErrorCode.EXPECTED_TOKEN, [']']);
140 } 140 }
141 if (type == TokenType.OPEN_PAREN) { 141 if (type == TokenType.OPEN_PAREN) {
142 return _makeError(ScannerErrorCode.EXPECTED_TOKEN, [')']); 142 return _makeError(ScannerErrorCode.EXPECTED_TOKEN, [')']);
143 } 143 }
144 if (type == TokenType.LT) {
145 return _makeError(ScannerErrorCode.EXPECTED_TOKEN, ['>']);
146 }
144 } else if (errorCode == codeUnexpectedDollarInString) { 147 } else if (errorCode == codeUnexpectedDollarInString) {
145 return _makeError(ScannerErrorCode.MISSING_IDENTIFIER, null); 148 return _makeError(ScannerErrorCode.MISSING_IDENTIFIER, null);
146 } 149 }
147 throw new UnimplementedError('$errorCode'); 150 throw new UnimplementedError('$errorCode');
148 } 151 }
149 } 152 }
150 153
151 /** 154 /**
152 * Determines whether the given [charOffset], which came from the non-EOF token 155 * Determines whether the given [charOffset], which came from the non-EOF token
153 * [token], represents the end of the input. 156 * [token], represents the end of the input.
154 */ 157 */
155 bool _isAtEnd(Token token, int charOffset) { 158 bool _isAtEnd(Token token, int charOffset) {
156 while (true) { 159 while (true) {
157 // Skip to the next token. 160 // Skip to the next token.
158 token = token.next; 161 token = token.next;
159 // If we've found an EOF token, its charOffset indicates where the end of 162 // If we've found an EOF token, its charOffset indicates where the end of
160 // the input is. 163 // the input is.
161 if (token.isEof) return token.charOffset == charOffset; 164 if (token.isEof) return token.charOffset == charOffset;
162 // If we've found a non-error token, then we know there is additional input 165 // If we've found a non-error token, then we know there is additional input
163 // text after [charOffset]. 166 // text after [charOffset].
164 if (token.type.kind != BAD_INPUT_TOKEN) return false; 167 if (token.type.kind != BAD_INPUT_TOKEN) return false;
165 // Otherwise keep looking. 168 // Otherwise keep looking.
166 } 169 }
167 } 170 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698