OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 'dart:convert' show UTF8; | 5 import 'dart:convert' show UTF8; |
6 | 6 |
7 import 'package:front_end/src/fasta/scanner/precedence.dart' | 7 import 'package:front_end/src/fasta/scanner/precedence.dart' |
8 show BAD_INPUT_INFO, EOF_INFO; | 8 show BAD_INPUT_INFO, EOF_INFO; |
9 import 'package:front_end/src/fasta/scanner/recover.dart' | 9 import 'package:front_end/src/fasta/scanner/recover.dart' |
10 show defaultRecoveryStrategy; | 10 show defaultRecoveryStrategy; |
(...skipping 29 matching lines...) Expand all Loading... |
40 if (genericMethodComments) { | 40 if (genericMethodComments) { |
41 // Fasta doesn't support generic method comments. | 41 // Fasta doesn't support generic method comments. |
42 // TODO(danrubel): once the analyzer toolchain no longer needs generic | 42 // TODO(danrubel): once the analyzer toolchain no longer needs generic |
43 // method comments, remove tests that exercise them. | 43 // method comments, remove tests that exercise them. |
44 fail('No generic method comment support in Fasta'); | 44 fail('No generic method comment support in Fasta'); |
45 } | 45 } |
46 // Note: Fasta always supports lazy assignment operators (`&&=` and `||=`), | 46 // Note: Fasta always supports lazy assignment operators (`&&=` and `||=`), |
47 // so we can ignore the `lazyAssignmentOperators` flag. | 47 // so we can ignore the `lazyAssignmentOperators` flag. |
48 // TODO(danrubel): once lazyAssignmentOperators are fully supported by | 48 // TODO(danrubel): once lazyAssignmentOperators are fully supported by |
49 // Dart, remove this flag. | 49 // Dart, remove this flag. |
50 fasta.ScannerResult result = fasta.scanString(source, | 50 fasta.ScannerResult result = fasta.scanString(source, includeComments: true, |
51 includeComments: true, | |
52 recover: ((List<int> bytes, fasta.Token tokens, List<int> lineStarts) { | 51 recover: ((List<int> bytes, fasta.Token tokens, List<int> lineStarts) { |
53 // perform recovery as a separate step | 52 // perform recovery as a separate step |
54 // so that the token stream can be validated before and after recovery | 53 // so that the token stream can be validated before and after recovery |
55 return tokens; | 54 return tokens; |
56 })); | 55 })); |
57 fasta.Token tokens = result.tokens; | 56 fasta.Token tokens = result.tokens; |
58 assertValidTokenStream(tokens); | 57 assertValidTokenStream(tokens); |
59 assertValidBeginTokens(tokens); | 58 assertValidBeginTokens(tokens); |
60 if (result.hasErrors) { | 59 if (result.hasErrors) { |
61 List<int> bytes = UTF8.encode(source); | 60 List<int> bytes = UTF8.encode(source); |
62 tokens = defaultRecoveryStrategy(bytes, tokens, result.lineStarts); | 61 tokens = defaultRecoveryStrategy(bytes, tokens, result.lineStarts); |
63 assertValidTokenStream(tokens, errorsFirst: true); | 62 assertValidTokenStream(tokens, errorsFirst: true); |
64 } | 63 } |
65 return extractErrors(tokens, listener); | 64 return extractErrors(tokens, listener); |
66 } | 65 } |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 } else if (token is fasta.UnmatchedToken) { | 392 } else if (token is fasta.UnmatchedToken) { |
394 expect(lastClosedGroup?.endGroup?.next, same(token), | 393 expect(lastClosedGroup?.endGroup?.next, same(token), |
395 reason: 'Unexpected error token for group: $lastClosedGroup'); | 394 reason: 'Unexpected error token for group: $lastClosedGroup'); |
396 expect(token.begin, lastClosedGroup); | 395 expect(token.begin, lastClosedGroup); |
397 } | 396 } |
398 token = token.next; | 397 token = token.next; |
399 } | 398 } |
400 expect(openerStack, isEmpty, reason: 'Missing closers'); | 399 expect(openerStack, isEmpty, reason: 'Missing closers'); |
401 } | 400 } |
402 } | 401 } |
OLD | NEW |