| 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/base/jenkins_smi_hash.dart'; | 6 import 'package:front_end/src/base/jenkins_smi_hash.dart'; |
| 7 import 'package:front_end/src/fasta/scanner/error_token.dart' as fasta; | 7 import 'package:front_end/src/fasta/scanner/error_token.dart' as fasta; |
| 8 import 'package:front_end/src/fasta/scanner/keyword.dart' as fasta; | 8 import 'package:front_end/src/fasta/scanner/keyword.dart' as fasta; |
| 9 import 'package:front_end/src/fasta/scanner/string_scanner.dart' as fasta; | 9 import 'package:front_end/src/fasta/scanner/string_scanner.dart' as fasta; |
| 10 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; | 10 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 @override | 218 @override |
| 219 @failingTest | 219 @failingTest |
| 220 void test_comment_multi_unterminated() { | 220 void test_comment_multi_unterminated() { |
| 221 // TODO(paulberry,ahe): see UnimplementedError("distinguish unterminated | 221 // TODO(paulberry,ahe): see UnimplementedError("distinguish unterminated |
| 222 // errors") | 222 // errors") |
| 223 super.test_comment_multi_unterminated(); | 223 super.test_comment_multi_unterminated(); |
| 224 } | 224 } |
| 225 | 225 |
| 226 @override | 226 @override |
| 227 @failingTest | 227 @failingTest |
| 228 void test_comment_single() { | |
| 229 // TODO(paulberry,ahe): See TODO comment below in _translateTokenInfoKind(). | |
| 230 super.test_comment_single(); | |
| 231 } | |
| 232 | |
| 233 @override | |
| 234 @failingTest | |
| 235 void test_double_missingDigitInExponent() { | 228 void test_double_missingDigitInExponent() { |
| 236 // TODO(paulberry,ahe): see UnimplementedError("distinguish unterminated | 229 // TODO(paulberry,ahe): see UnimplementedError("distinguish unterminated |
| 237 // errors") | 230 // errors") |
| 238 super.test_double_missingDigitInExponent(); | 231 super.test_double_missingDigitInExponent(); |
| 239 } | 232 } |
| 240 | 233 |
| 241 @override | 234 @override |
| 242 @failingTest | 235 @failingTest |
| 243 void test_hexidecimal_missingDigit() { | 236 void test_hexidecimal_missingDigit() { |
| 244 // TODO(paulberry,ahe): see UnimplementedError("distinguish unterminated | 237 // TODO(paulberry,ahe): see UnimplementedError("distinguish unterminated |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 CommentToken currentCommentHead; | 384 CommentToken currentCommentHead; |
| 392 CommentToken currentCommentTail; | 385 CommentToken currentCommentTail; |
| 393 while (true) { | 386 while (true) { |
| 394 if (token is fasta.ErrorToken) { | 387 if (token is fasta.ErrorToken) { |
| 395 var error = _translateErrorToken(token, source.length); | 388 var error = _translateErrorToken(token, source.length); |
| 396 if (error != null) { | 389 if (error != null) { |
| 397 listener.errors.add(error); | 390 listener.errors.add(error); |
| 398 } | 391 } |
| 399 } else if (token is fasta.StringToken && | 392 } else if (token is fasta.StringToken && |
| 400 token.info.kind == fasta.COMMENT_TOKEN) { | 393 token.info.kind == fasta.COMMENT_TOKEN) { |
| 401 var translatedToken = _translateToken(token, null) as CommentToken; | 394 // TODO(paulberry,ahe): It would be nice if the scanner gave us an |
| 395 // easier way to distinguish between the two types of comment. |
| 396 var type = token.value.startsWith('/*') |
| 397 ? TokenType.MULTI_LINE_COMMENT |
| 398 : TokenType.SINGLE_LINE_COMMENT; |
| 399 var translatedToken = |
| 400 new CommentToken(type, token.value, token.charOffset); |
| 402 if (currentCommentHead == null) { | 401 if (currentCommentHead == null) { |
| 403 currentCommentHead = currentCommentTail = translatedToken; | 402 currentCommentHead = currentCommentTail = translatedToken; |
| 404 } else { | 403 } else { |
| 405 currentCommentTail.setNext(translatedToken); | 404 currentCommentTail.setNext(translatedToken); |
| 406 currentCommentTail = translatedToken; | 405 currentCommentTail = translatedToken; |
| 407 } | 406 } |
| 408 } else { | 407 } else { |
| 409 var translatedToken = _translateToken(token, currentCommentHead); | 408 var translatedToken = _translateToken(token, currentCommentHead); |
| 410 translatedToken.setNext(translatedToken); | 409 translatedToken.setNext(translatedToken); |
| 411 currentCommentHead = currentCommentTail = null; | 410 currentCommentHead = currentCommentTail = null; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 } | 483 } |
| 485 | 484 |
| 486 Token makeBeginToken() { | 485 Token makeBeginToken() { |
| 487 if (comment == null) { | 486 if (comment == null) { |
| 488 return new BeginToken(type, offset); | 487 return new BeginToken(type, offset); |
| 489 } else { | 488 } else { |
| 490 return new BeginTokenWithComment(type, offset, comment); | 489 return new BeginTokenWithComment(type, offset, comment); |
| 491 } | 490 } |
| 492 } | 491 } |
| 493 | 492 |
| 494 Token makeCommentToken() { | |
| 495 return new CommentToken(type, token.value, offset); | |
| 496 } | |
| 497 | |
| 498 if (token is fasta.StringToken) { | 493 if (token is fasta.StringToken) { |
| 499 if (token.info.kind == fasta.COMMENT_TOKEN) { | 494 return makeStringToken(token.value); |
| 500 return makeCommentToken(); | |
| 501 } else { | |
| 502 return makeStringToken(token.value); | |
| 503 } | |
| 504 } else if (token is fasta.KeywordToken) { | 495 } else if (token is fasta.KeywordToken) { |
| 505 return makeKeywordToken(_translateKeyword(token.keyword.syntax)); | 496 return makeKeywordToken(_translateKeyword(token.keyword.syntax)); |
| 506 } else if (token is fasta.SymbolToken) { | 497 } else if (token is fasta.SymbolToken) { |
| 507 if (token is fasta.BeginGroupToken) { | 498 if (token is fasta.BeginGroupToken) { |
| 508 if (type == TokenType.LT) { | 499 if (type == TokenType.LT) { |
| 509 return makeStringToken(token.value); | 500 return makeStringToken(token.value); |
| 510 } else { | 501 } else { |
| 511 return makeBeginToken(); | 502 return makeBeginToken(); |
| 512 } | 503 } |
| 513 } else { | 504 } else { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 case fasta.TILDE_SLASH_EQ_TOKEN: | 637 case fasta.TILDE_SLASH_EQ_TOKEN: |
| 647 return TokenType.TILDE_SLASH_EQ; | 638 return TokenType.TILDE_SLASH_EQ; |
| 648 case fasta.TILDE_SLASH_TOKEN: | 639 case fasta.TILDE_SLASH_TOKEN: |
| 649 return TokenType.TILDE_SLASH; | 640 return TokenType.TILDE_SLASH; |
| 650 case fasta.PERCENT_EQ_TOKEN: | 641 case fasta.PERCENT_EQ_TOKEN: |
| 651 return TokenType.PERCENT_EQ; | 642 return TokenType.PERCENT_EQ; |
| 652 case fasta.GT_GT_TOKEN: | 643 case fasta.GT_GT_TOKEN: |
| 653 return TokenType.GT_GT; | 644 return TokenType.GT_GT; |
| 654 case fasta.CARET_EQ_TOKEN: | 645 case fasta.CARET_EQ_TOKEN: |
| 655 return TokenType.CARET_EQ; | 646 return TokenType.CARET_EQ; |
| 656 case fasta.COMMENT_TOKEN: | |
| 657 // TODO(paulberry,ahe): how to distinguish multi-line from | |
| 658 // single-line comments? Causes a failure in test_comment_single(). | |
| 659 return TokenType.MULTI_LINE_COMMENT; | |
| 660 case fasta.STRING_INTERPOLATION_IDENTIFIER_TOKEN: | 647 case fasta.STRING_INTERPOLATION_IDENTIFIER_TOKEN: |
| 661 return TokenType.STRING_INTERPOLATION_IDENTIFIER; | 648 return TokenType.STRING_INTERPOLATION_IDENTIFIER; |
| 662 case fasta.QUESTION_PERIOD_TOKEN: | 649 case fasta.QUESTION_PERIOD_TOKEN: |
| 663 return TokenType.QUESTION_PERIOD; | 650 return TokenType.QUESTION_PERIOD; |
| 664 case fasta.QUESTION_QUESTION_TOKEN: | 651 case fasta.QUESTION_QUESTION_TOKEN: |
| 665 return TokenType.QUESTION_QUESTION; | 652 return TokenType.QUESTION_QUESTION; |
| 666 case fasta.QUESTION_QUESTION_EQ_TOKEN: | 653 case fasta.QUESTION_QUESTION_EQ_TOKEN: |
| 667 return TokenType.QUESTION_QUESTION_EQ; | 654 return TokenType.QUESTION_QUESTION_EQ; |
| 668 default: | 655 default: |
| 669 throw new UnimplementedError('$kind'); | 656 throw new UnimplementedError('$kind'); |
| (...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1870 _TestScanner(CharacterReader reader, [this.listener]) : super(reader); | 1857 _TestScanner(CharacterReader reader, [this.listener]) : super(reader); |
| 1871 | 1858 |
| 1872 @override | 1859 @override |
| 1873 void reportError( | 1860 void reportError( |
| 1874 ScannerErrorCode errorCode, int offset, List<Object> arguments) { | 1861 ScannerErrorCode errorCode, int offset, List<Object> arguments) { |
| 1875 if (listener != null) { | 1862 if (listener != null) { |
| 1876 listener.errors.add(new _TestError(offset, 1, errorCode, arguments)); | 1863 listener.errors.add(new _TestError(offset, 1, errorCode, arguments)); |
| 1877 } | 1864 } |
| 1878 } | 1865 } |
| 1879 } | 1866 } |
| OLD | NEW |