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 licenset hat can be found in the LICENSE file. | 3 // BSD-style licenset hat can be found in the LICENSE file. |
4 | 4 |
5 library fasta.scanner.recover; | 5 library fasta.scanner.recover; |
6 | 6 |
7 import 'token.dart' show StringToken, Token; | 7 import 'token.dart' show StringToken, Token; |
8 | 8 |
9 import 'error_token.dart' show NonAsciiIdentifierToken, ErrorKind, ErrorToken; | 9 import 'error_token.dart' show NonAsciiIdentifierToken, ErrorKind, ErrorToken; |
10 | 10 |
11 import 'precedence.dart' as Precedence; | 11 import 'precedence.dart' as Precedence; |
12 | 12 |
13 import 'precedence.dart' show PrecedenceInfo; | 13 import 'precedence.dart' show PrecedenceInfo; |
14 | 14 |
15 /// Recover from errors in [tokens]. The original sources are provided as | 15 /// Recover from errors in [tokens]. The original sources are provided as |
16 /// [bytes]. [lineStarts] are the beginning character offsets of lines, and | 16 /// [bytes]. [lineStarts] are the beginning character offsets of lines, and |
17 /// must be updated if recovery is performed rewriting the original source | 17 /// must be updated if recovery is performed rewriting the original source |
18 /// code. | 18 /// code. |
19 Token defaultRecoveryStrategy( | 19 Token defaultRecoveryStrategy( |
20 List<int> bytes, Token tokens, List<int> lineStarts) { | 20 List<int> bytes, Token tokens, List<int> lineStarts) { |
21 // See [Parser.reportErrorToken](package:front_end/src/fasta/parser/src/parser
.dart) for how | 21 // See [Parser.reportErrorToken](../parser/src/parser.dart) for how |
22 // it currently handles lexical errors. In addition, notice how the parser | 22 // it currently handles lexical errors. In addition, notice how the parser |
23 // calls [handleInvalidExpression], [handleInvalidFunctionBody], and | 23 // calls [handleInvalidExpression], [handleInvalidFunctionBody], and |
24 // [handleInvalidTypeReference] to allow the listener to recover its internal | 24 // [handleInvalidTypeReference] to allow the listener to recover its internal |
25 // state. See [package:compiler/src/parser/element_listener.dart] for an | 25 // state. See [package:compiler/src/parser/element_listener.dart] for an |
26 // example of how these events are used. | 26 // example of how these events are used. |
27 // | 27 // |
28 // In addition, the scanner will attempt a bit of recovery when braces don't | 28 // In addition, the scanner will attempt a bit of recovery when braces don't |
29 // match up during brace grouping. See | 29 // match up during brace grouping. See |
30 // [ArrayBasedScanner.discardBeginGroupUntil](array_based_scanner.dart). For | 30 // [ArrayBasedScanner.discardBeginGroupUntil](array_based_scanner.dart). For |
31 // more details on brace grouping see | 31 // more details on brace grouping see |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 | 235 |
236 String closeBraceFor(String openBrace) { | 236 String closeBraceFor(String openBrace) { |
237 return const { | 237 return const { |
238 '(': ')', | 238 '(': ')', |
239 '[': ']', | 239 '[': ']', |
240 '{': '}', | 240 '{': '}', |
241 '<': '>', | 241 '<': '>', |
242 r'${': '}', | 242 r'${': '}', |
243 }[openBrace]; | 243 }[openBrace]; |
244 } | 244 } |
OLD | NEW |