| 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/scanner/error_token.dart' show ErrorToken; | 7 import 'package:front_end/src/fasta/scanner/error_token.dart' show ErrorToken; |
| 8 | 8 |
| 9 import 'package:front_end/src/fasta/scanner/keyword.dart' show Keyword; | 9 import 'package:front_end/src/fasta/scanner/keyword.dart' show Keyword; |
| 10 | 10 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 /// fasta may contain synthetic tokens from error recovery that are not mapped | 147 /// fasta may contain synthetic tokens from error recovery that are not mapped |
| 148 /// to the analyzer token stream. We use [_beginTokenStack] and | 148 /// to the analyzer token stream. We use [_beginTokenStack] and |
| 149 /// [_endTokenStack] to create the appropriate links for non-synthetic tokens | 149 /// [_endTokenStack] to create the appropriate links for non-synthetic tokens |
| 150 /// in the way analyzer expects. | 150 /// in the way analyzer expects. |
| 151 void _matchGroups(Token token, analyzer.Token translatedToken) { | 151 void _matchGroups(Token token, analyzer.Token translatedToken) { |
| 152 if (identical(_endTokenStack.last, token)) { | 152 if (identical(_endTokenStack.last, token)) { |
| 153 _beginTokenStack.last.endToken = translatedToken; | 153 _beginTokenStack.last.endToken = translatedToken; |
| 154 _beginTokenStack.removeLast(); | 154 _beginTokenStack.removeLast(); |
| 155 _endTokenStack.removeLast(); | 155 _endTokenStack.removeLast(); |
| 156 } | 156 } |
| 157 // Synthetic end tokens use the same offset as the begin token. | 157 // Synthetic end tokens have a length of zero. |
| 158 if (translatedToken is analyzer.BeginToken && | 158 if (translatedToken is analyzer.BeginToken && |
| 159 token is BeginGroupToken && | 159 token is BeginGroupToken && |
| 160 token.endGroup != null && | 160 token.endGroup != null && |
| 161 token.endGroup.charOffset != token.charOffset) { | 161 token.endGroup.charOffset != token.charOffset) { |
| 162 _beginTokenStack.add(translatedToken); | 162 _beginTokenStack.add(translatedToken); |
| 163 _endTokenStack.add(token.endGroup); | 163 _endTokenStack.add(token.endGroup); |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 | 167 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 229 |
| 230 Token translateComments(analyzer.Token token) { | 230 Token translateComments(analyzer.Token token) { |
| 231 if (token == null) { | 231 if (token == null) { |
| 232 return null; | 232 return null; |
| 233 } | 233 } |
| 234 Token head = fromAnalyzerToken(token); | 234 Token head = fromAnalyzerToken(token); |
| 235 Token tail = head; | 235 Token tail = head; |
| 236 token = token.next; | 236 token = token.next; |
| 237 while (token != null) { | 237 while (token != null) { |
| 238 tail.next = fromAnalyzerToken(token); | 238 tail.next = fromAnalyzerToken(token); |
| 239 tail.next.previousToken = tail; | 239 tail.next.previous = tail; |
| 240 tail = tail.next; | 240 tail = tail.next; |
| 241 token = token.next; | 241 token = token.next; |
| 242 } | 242 } |
| 243 return head; | 243 return head; |
| 244 } | 244 } |
| 245 | 245 |
| 246 analyzer.Token translateAndAppend(analyzer.Token analyzerToken) { | 246 analyzer.Token translateAndAppend(analyzer.Token analyzerToken) { |
| 247 var token = fromAnalyzerToken(analyzerToken); | 247 var token = fromAnalyzerToken(analyzerToken); |
| 248 token.precedingCommentTokens = | 248 token.precedingCommentTokens = |
| 249 translateComments(analyzerToken.precedingComments); | 249 translateComments(analyzerToken.precedingComments); |
| 250 tokenTail.next = token; | 250 tokenTail.next = token; |
| 251 tokenTail.next.previousToken = tokenTail; | 251 tokenTail.next.previous = tokenTail; |
| 252 tokenTail = token; | 252 tokenTail = token; |
| 253 matchGroups(analyzerToken, token); | 253 matchGroups(analyzerToken, token); |
| 254 return analyzerToken.next; | 254 return analyzerToken.next; |
| 255 } | 255 } |
| 256 | 256 |
| 257 while (true) { | 257 while (true) { |
| 258 // TODO(paulberry): join up begingroup/endgroup. | 258 // TODO(paulberry): join up begingroup/endgroup. |
| 259 if (analyzerToken.type == TokenType.EOF) { | 259 if (analyzerToken.type == TokenType.EOF) { |
| 260 tokenTail.next = new SymbolToken.eof(analyzerToken.offset); | 260 tokenTail.next = new SymbolToken.eof(analyzerToken.offset); |
| 261 tokenTail.next.previousToken = tokenTail; | 261 tokenTail.next.previous = tokenTail; |
| 262 tokenTail.next.precedingCommentTokens = | 262 tokenTail.next.precedingCommentTokens = |
| 263 translateComments(analyzerToken.precedingComments); | 263 translateComments(analyzerToken.precedingComments); |
| 264 tokenTail.next.next = tokenTail.next; | 264 tokenTail.next.next = tokenTail.next; |
| 265 return tokenHead.next; | 265 return tokenHead.next; |
| 266 } | 266 } |
| 267 analyzerToken = translateAndAppend(analyzerToken); | 267 analyzerToken = translateAndAppend(analyzerToken); |
| 268 } | 268 } |
| 269 } | 269 } |
| 270 | 270 |
| 271 /// Converts a single analyzer token into a Fasta token. | 271 /// Converts a single analyzer token into a Fasta token. |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 case PERIOD_PERIOD_PERIOD_TOKEN: | 732 case PERIOD_PERIOD_PERIOD_TOKEN: |
| 733 return TokenType.PERIOD_PERIOD_PERIOD; | 733 return TokenType.PERIOD_PERIOD_PERIOD; |
| 734 // case GENERIC_METHOD_TYPE_LIST_TOKEN: | 734 // case GENERIC_METHOD_TYPE_LIST_TOKEN: |
| 735 // return TokenType.GENERIC_METHOD_TYPE_LIST; | 735 // return TokenType.GENERIC_METHOD_TYPE_LIST; |
| 736 // case GENERIC_METHOD_TYPE_ASSIGN_TOKEN: | 736 // case GENERIC_METHOD_TYPE_ASSIGN_TOKEN: |
| 737 // return TokenType.GENERIC_METHOD_TYPE_ASSIGN; | 737 // return TokenType.GENERIC_METHOD_TYPE_ASSIGN; |
| 738 default: | 738 default: |
| 739 return internalError("Unhandled token ${token.info}"); | 739 return internalError("Unhandled token ${token.info}"); |
| 740 } | 740 } |
| 741 } | 741 } |
| OLD | NEW |