| 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 library fasta.analyzer.token_utils; | 5 library fasta.analyzer.token_utils; |
| 6 | 6 |
| 7 import 'package:front_end/src/fasta/parser/error_kind.dart' show ErrorKind; | 7 import 'package:front_end/src/fasta/parser/error_kind.dart' show ErrorKind; |
| 8 | 8 |
| 9 import 'package:front_end/src/fasta/scanner/error_token.dart' show ErrorToken; | 9 import 'package:front_end/src/fasta/scanner/error_token.dart' show ErrorToken; |
| 10 | 10 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 } | 231 } |
| 232 | 232 |
| 233 /// Converts a stream of Analyzer tokens (starting with [token] and continuing | 233 /// Converts a stream of Analyzer tokens (starting with [token] and continuing |
| 234 /// to EOF) to a stream of Fasta tokens. | 234 /// to EOF) to a stream of Fasta tokens. |
| 235 /// | 235 /// |
| 236 /// TODO(paulberry): Analyzer tokens do not record error conditions, so a round | 236 /// TODO(paulberry): Analyzer tokens do not record error conditions, so a round |
| 237 /// trip through this function and [toAnalyzerTokenStream] will lose error | 237 /// trip through this function and [toAnalyzerTokenStream] will lose error |
| 238 /// information. | 238 /// information. |
| 239 Token fromAnalyzerTokenStream(analyzer.Token analyzerToken) { | 239 Token fromAnalyzerTokenStream(analyzer.Token analyzerToken) { |
| 240 Token tokenHead = new SymbolToken(EOF_INFO, -1); | 240 Token tokenHead = new SymbolToken(EOF_INFO, -1); |
| 241 tokenHead.previous = tokenHead; |
| 241 Token tokenTail = tokenHead; | 242 Token tokenTail = tokenHead; |
| 242 | 243 |
| 243 // Both fasta and analyzer have links from a "BeginToken" to its matching | 244 // Both fasta and analyzer have links from a "BeginToken" to its matching |
| 244 // "EndToken" in a group (like parentheses and braces). However, only fasta | 245 // "EndToken" in a group (like parentheses and braces). However, only fasta |
| 245 // makes these links for angle brackets. We use these stacks to map the | 246 // makes these links for angle brackets. We use these stacks to map the |
| 246 // links from the analyzer token stream into equivalent links in the fasta | 247 // links from the analyzer token stream into equivalent links in the fasta |
| 247 // token stream, and to create the links that fasta expects for angle | 248 // token stream, and to create the links that fasta expects for angle |
| 248 // brackets. | 249 // brackets. |
| 249 | 250 |
| 250 // Note: beginTokenStack and endTokenStack are seeded with a sentinel value | 251 // Note: beginTokenStack and endTokenStack are seeded with a sentinel value |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 return analyzerToken.next; | 310 return analyzerToken.next; |
| 310 } | 311 } |
| 311 | 312 |
| 312 while (true) { | 313 while (true) { |
| 313 // TODO(paulberry): join up begingroup/endgroup. | 314 // TODO(paulberry): join up begingroup/endgroup. |
| 314 if (analyzerToken.type == TokenType.EOF) { | 315 if (analyzerToken.type == TokenType.EOF) { |
| 315 tokenTail.next = new SymbolToken(EOF_INFO, analyzerToken.offset); | 316 tokenTail.next = new SymbolToken(EOF_INFO, analyzerToken.offset); |
| 316 tokenTail.next.previousToken = tokenTail; | 317 tokenTail.next.previousToken = tokenTail; |
| 317 tokenTail.next.precedingCommentTokens = | 318 tokenTail.next.precedingCommentTokens = |
| 318 translateComments(analyzerToken.precedingComments); | 319 translateComments(analyzerToken.precedingComments); |
| 320 tokenTail.next.next = tokenTail.next; |
| 319 return tokenHead.next; | 321 return tokenHead.next; |
| 320 } | 322 } |
| 321 analyzerToken = translateAndAppend(analyzerToken); | 323 analyzerToken = translateAndAppend(analyzerToken); |
| 322 } | 324 } |
| 323 } | 325 } |
| 324 | 326 |
| 325 /// Converts a single analyzer token into a Fasta token. | 327 /// Converts a single analyzer token into a Fasta token. |
| 326 Token fromAnalyzerToken(analyzer.Token token) { | 328 Token fromAnalyzerToken(analyzer.Token token) { |
| 327 Token beginGroup(PrecedenceInfo info) => | 329 Token beginGroup(PrecedenceInfo info) => |
| 328 new BeginGroupToken(info, token.offset); | 330 new BeginGroupToken(info, token.offset); |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 case PERIOD_PERIOD_PERIOD_TOKEN: | 804 case PERIOD_PERIOD_PERIOD_TOKEN: |
| 803 return TokenType.PERIOD_PERIOD_PERIOD; | 805 return TokenType.PERIOD_PERIOD_PERIOD; |
| 804 // case GENERIC_METHOD_TYPE_LIST_TOKEN: | 806 // case GENERIC_METHOD_TYPE_LIST_TOKEN: |
| 805 // return TokenType.GENERIC_METHOD_TYPE_LIST; | 807 // return TokenType.GENERIC_METHOD_TYPE_LIST; |
| 806 // case GENERIC_METHOD_TYPE_ASSIGN_TOKEN: | 808 // case GENERIC_METHOD_TYPE_ASSIGN_TOKEN: |
| 807 // return TokenType.GENERIC_METHOD_TYPE_ASSIGN; | 809 // return TokenType.GENERIC_METHOD_TYPE_ASSIGN; |
| 808 default: | 810 default: |
| 809 return internalError("Unhandled token ${token.info}"); | 811 return internalError("Unhandled token ${token.info}"); |
| 810 } | 812 } |
| 811 } | 813 } |
| OLD | NEW |