OLD | NEW |
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/scanner/error_token.dart'; | 7 import 'package:front_end/src/fasta/scanner/error_token.dart'; |
7 import 'package:front_end/src/fasta/scanner/token.dart'; | 8 import 'package:front_end/src/fasta/scanner/token.dart'; |
8 import 'package:front_end/src/fasta/scanner/token_constants.dart'; | 9 import 'package:front_end/src/fasta/scanner/token_constants.dart'; |
9 | 10 |
10 /** | 11 /** |
11 * The error codes used for errors detected by the scanner. | 12 * The error codes used for errors detected by the scanner. |
12 */ | 13 */ |
13 class ScannerErrorCode extends ErrorCode { | 14 class ScannerErrorCode extends ErrorCode { |
14 /** | 15 /** |
15 * Parameters: | 16 * Parameters: |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // Analyzer never generates an error message past the end of the input, | 83 // Analyzer never generates an error message past the end of the input, |
83 // since such an error would not be visible in an editor. | 84 // since such an error would not be visible in an editor. |
84 // TODO(paulberry,ahe): would it make sense to replicate this behavior | 85 // TODO(paulberry,ahe): would it make sense to replicate this behavior |
85 // in fasta, or move it elsewhere in analyzer? | 86 // in fasta, or move it elsewhere in analyzer? |
86 charOffset--; | 87 charOffset--; |
87 } | 88 } |
88 reportError(errorCode, charOffset, arguments); | 89 reportError(errorCode, charOffset, arguments); |
89 } | 90 } |
90 | 91 |
91 var errorCode = token.errorCode; | 92 var errorCode = token.errorCode; |
92 switch (errorCode) { | 93 switch (errorCode.analyzerCode) { |
93 case ErrorKind.UnterminatedString: | 94 case "UNTERMINATED_STRING_LITERAL": |
94 // TODO(paulberry,ahe): Fasta reports the error location as the entire | 95 // TODO(paulberry,ahe): Fasta reports the error location as the entire |
95 // string; analyzer expects the end of the string. | 96 // string; analyzer expects the end of the string. |
96 charOffset = endOffset; | 97 charOffset = endOffset; |
97 return _makeError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, null); | 98 return _makeError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, null); |
98 case ErrorKind.UnmatchedToken: | 99 |
99 return null; | 100 case "UNTERMINATED_MULTI_LINE_COMMENT": |
100 case ErrorKind.UnterminatedComment: | |
101 // TODO(paulberry,ahe): Fasta reports the error location as the entire | 101 // TODO(paulberry,ahe): Fasta reports the error location as the entire |
102 // comment; analyzer expects the end of the comment. | 102 // comment; analyzer expects the end of the comment. |
103 charOffset = endOffset; | 103 charOffset = endOffset; |
104 return _makeError(ScannerErrorCode.UNTERMINATED_MULTI_LINE_COMMENT, null); | 104 return _makeError(ScannerErrorCode.UNTERMINATED_MULTI_LINE_COMMENT, null); |
105 case ErrorKind.MissingExponent: | 105 |
| 106 case "MISSING_DIGIT": |
106 // TODO(paulberry,ahe): Fasta reports the error location as the entire | 107 // TODO(paulberry,ahe): Fasta reports the error location as the entire |
107 // number; analyzer expects the end of the number. | 108 // number; analyzer expects the end of the number. |
108 charOffset = endOffset - 1; | 109 charOffset = endOffset - 1; |
109 return _makeError(ScannerErrorCode.MISSING_DIGIT, null); | 110 return _makeError(ScannerErrorCode.MISSING_DIGIT, null); |
110 case ErrorKind.ExpectedHexDigit: | 111 |
| 112 case "MISSING_HEX_DIGIT": |
111 // TODO(paulberry,ahe): Fasta reports the error location as the entire | 113 // TODO(paulberry,ahe): Fasta reports the error location as the entire |
112 // number; analyzer expects the end of the number. | 114 // number; analyzer expects the end of the number. |
113 charOffset = endOffset - 1; | 115 charOffset = endOffset - 1; |
114 return _makeError(ScannerErrorCode.MISSING_HEX_DIGIT, null); | 116 return _makeError(ScannerErrorCode.MISSING_HEX_DIGIT, null); |
115 case ErrorKind.NonAsciiIdentifier: | 117 |
116 case ErrorKind.NonAsciiWhitespace: | 118 case "ILLEGAL_CHARACTER": |
117 return _makeError(ScannerErrorCode.ILLEGAL_CHARACTER, [token.character]); | 119 return _makeError(ScannerErrorCode.ILLEGAL_CHARACTER, [token.character]); |
118 case ErrorKind.UnexpectedDollarInString: | 120 |
119 return null; | |
120 default: | 121 default: |
| 122 if (errorCode == codeUnmatchedToken || |
| 123 errorCode == codeUnexpectedDollarInString) { |
| 124 return null; |
| 125 } |
121 throw new UnimplementedError('$errorCode'); | 126 throw new UnimplementedError('$errorCode'); |
122 } | 127 } |
123 } | 128 } |
124 | 129 |
125 /** | 130 /** |
126 * Determines whether the given [charOffset], which came from the non-EOF token | 131 * Determines whether the given [charOffset], which came from the non-EOF token |
127 * [token], represents the end of the input. | 132 * [token], represents the end of the input. |
128 */ | 133 */ |
129 bool _isAtEnd(Token token, int charOffset) { | 134 bool _isAtEnd(Token token, int charOffset) { |
130 while (true) { | 135 while (true) { |
131 // Skip to the next token. | 136 // Skip to the next token. |
132 token = token.next; | 137 token = token.next; |
133 // If we've found an EOF token, its charOffset indicates where the end of | 138 // If we've found an EOF token, its charOffset indicates where the end of |
134 // the input is. | 139 // the input is. |
135 if (token.isEof) return token.charOffset == charOffset; | 140 if (token.isEof) return token.charOffset == charOffset; |
136 // If we've found a non-error token, then we know there is additional input | 141 // If we've found a non-error token, then we know there is additional input |
137 // text after [charOffset]. | 142 // text after [charOffset]. |
138 if (token.info.kind != BAD_INPUT_TOKEN) return false; | 143 if (token.info.kind != BAD_INPUT_TOKEN) return false; |
139 // Otherwise keep looking. | 144 // Otherwise keep looking. |
140 } | 145 } |
141 } | 146 } |
OLD | NEW |