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

Unified Diff: pkg/front_end/lib/src/scanner/errors.dart

Issue 2923113002: translate remaining fasta scanner error codes (Closed)
Patch Set: address comments Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/front_end/lib/src/fasta/scanner/recover.dart ('k') | pkg/front_end/test/scanner_fasta_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/scanner/errors.dart
diff --git a/pkg/front_end/lib/src/scanner/errors.dart b/pkg/front_end/lib/src/scanner/errors.dart
index ca2a20972639926508bfc0aea952ad0044896006..93b7fb0d26f87e3896c2763cf5b583906d9a231a 100644
--- a/pkg/front_end/lib/src/scanner/errors.dart
+++ b/pkg/front_end/lib/src/scanner/errors.dart
@@ -5,13 +5,20 @@
import 'package:front_end/src/base/errors.dart';
import 'package:front_end/src/fasta/fasta_codes.dart';
import 'package:front_end/src/fasta/scanner/error_token.dart';
-import 'package:front_end/src/scanner/token.dart' show Token;
+import 'package:front_end/src/scanner/token.dart' show Token, TokenType;
import 'package:front_end/src/fasta/scanner/token_constants.dart';
/**
* The error codes used for errors detected by the scanner.
*/
class ScannerErrorCode extends ErrorCode {
+ /**
+ * Parameters:
+ * 0: the token that was expected but not found
+ */
+ static const ScannerErrorCode EXPECTED_TOKEN =
+ const ScannerErrorCode('EXPECTED_TOKEN', "Expected to find '{0}'.");
+
/**
* Parameters:
* 0: the illegal character
@@ -25,6 +32,9 @@ class ScannerErrorCode extends ErrorCode {
static const ScannerErrorCode MISSING_HEX_DIGIT = const ScannerErrorCode(
'MISSING_HEX_DIGIT', "Hexidecimal digit expected.");
+ static const ScannerErrorCode MISSING_IDENTIFIER =
+ const ScannerErrorCode('MISSING_IDENTIFIER', "Expected an identifier.");
+
static const ScannerErrorCode MISSING_QUOTE =
const ScannerErrorCode('MISSING_QUOTE', "Expected quote (' or \").");
@@ -119,9 +129,20 @@ void translateErrorToken(ErrorToken token, ReportError reportError) {
return _makeError(ScannerErrorCode.ILLEGAL_CHARACTER, [token.character]);
default:
- if (errorCode == codeUnmatchedToken ||
- errorCode == codeUnexpectedDollarInString) {
- return null;
+ if (errorCode == codeUnmatchedToken) {
+ TokenType type = token.begin?.type;
+ if (type == TokenType.OPEN_CURLY_BRACKET ||
+ type == TokenType.STRING_INTERPOLATION_EXPRESSION) {
+ return _makeError(ScannerErrorCode.EXPECTED_TOKEN, ['}']);
+ }
+ if (type == TokenType.OPEN_SQUARE_BRACKET) {
+ return _makeError(ScannerErrorCode.EXPECTED_TOKEN, [']']);
+ }
+ if (type == TokenType.OPEN_PAREN) {
+ return _makeError(ScannerErrorCode.EXPECTED_TOKEN, [')']);
+ }
+ } else if (errorCode == codeUnexpectedDollarInString) {
+ return _makeError(ScannerErrorCode.MISSING_IDENTIFIER, null);
}
throw new UnimplementedError('$errorCode');
}
« no previous file with comments | « pkg/front_end/lib/src/fasta/scanner/recover.dart ('k') | pkg/front_end/test/scanner_fasta_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698