| 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/scanner/error_token.dart'; | 6 import 'package:front_end/src/fasta/scanner/error_token.dart'; |
| 7 import 'package:front_end/src/fasta/scanner/token.dart'; | 7 import 'package:front_end/src/fasta/scanner/token.dart'; |
| 8 import 'package:front_end/src/fasta/scanner/token_constants.dart'; | 8 import 'package:front_end/src/fasta/scanner/token_constants.dart'; |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 case ErrorKind.UnmatchedToken: | 98 case ErrorKind.UnmatchedToken: |
| 99 return null; | 99 return null; |
| 100 case ErrorKind.UnterminatedComment: | 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 case ErrorKind.MissingExponent: |
| 106 // TODO(paulberry,ahe): Fasta reports the error location as the entire | 106 // TODO(paulberry,ahe): Fasta reports the error location as the entire |
| 107 // number; analyzer expects the end of the number. | 107 // number; analyzer expects the end of the number. |
| 108 charOffset = endOffset; | 108 charOffset = endOffset - 1; |
| 109 return _makeError(ScannerErrorCode.MISSING_DIGIT, null); | 109 return _makeError(ScannerErrorCode.MISSING_DIGIT, null); |
| 110 case ErrorKind.ExpectedHexDigit: | 110 case ErrorKind.ExpectedHexDigit: |
| 111 // TODO(paulberry,ahe): Fasta reports the error location as the entire | 111 // TODO(paulberry,ahe): Fasta reports the error location as the entire |
| 112 // number; analyzer expects the end of the number. | 112 // number; analyzer expects the end of the number. |
| 113 charOffset = endOffset; | 113 charOffset = endOffset - 1; |
| 114 return _makeError(ScannerErrorCode.MISSING_HEX_DIGIT, null); | 114 return _makeError(ScannerErrorCode.MISSING_HEX_DIGIT, null); |
| 115 case ErrorKind.NonAsciiIdentifier: | 115 case ErrorKind.NonAsciiIdentifier: |
| 116 case ErrorKind.NonAsciiWhitespace: | 116 case ErrorKind.NonAsciiWhitespace: |
| 117 return _makeError(ScannerErrorCode.ILLEGAL_CHARACTER, [token.character]); | 117 return _makeError(ScannerErrorCode.ILLEGAL_CHARACTER, [token.character]); |
| 118 case ErrorKind.UnexpectedDollarInString: | 118 case ErrorKind.UnexpectedDollarInString: |
| 119 return null; | 119 return null; |
| 120 default: | 120 default: |
| 121 throw new UnimplementedError('$errorCode'); | 121 throw new UnimplementedError('$errorCode'); |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 | 124 |
| 125 /** | 125 /** |
| 126 * Determines whether the given [charOffset], which came from the non-EOF token | 126 * Determines whether the given [charOffset], which came from the non-EOF token |
| 127 * [token], represents the end of the input. | 127 * [token], represents the end of the input. |
| 128 */ | 128 */ |
| 129 bool _isAtEnd(Token token, int charOffset) { | 129 bool _isAtEnd(Token token, int charOffset) { |
| 130 while (true) { | 130 while (true) { |
| 131 // Skip to the next token. | 131 // Skip to the next token. |
| 132 token = token.next; | 132 token = token.next; |
| 133 // If we've found an EOF token, its charOffset indicates where the end of | 133 // If we've found an EOF token, its charOffset indicates where the end of |
| 134 // the input is. | 134 // the input is. |
| 135 if (token.isEof) return token.charOffset == charOffset; | 135 if (token.isEof) return token.charOffset == charOffset; |
| 136 // If we've found a non-error token, then we know there is additional input | 136 // If we've found a non-error token, then we know there is additional input |
| 137 // text after [charOffset]. | 137 // text after [charOffset]. |
| 138 if (token.info.kind != BAD_INPUT_TOKEN) return false; | 138 if (token.info.kind != BAD_INPUT_TOKEN) return false; |
| 139 // Otherwise keep looking. | 139 // Otherwise keep looking. |
| 140 } | 140 } |
| 141 } | 141 } |
| OLD | NEW |