| 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/scanner/token.dart' show Keyword; | 9 import 'package:front_end/src/scanner/token.dart' show Keyword; |
| 10 | 10 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 _analyzerTokenTail = _analyzerTokenHead; | 86 _analyzerTokenTail = _analyzerTokenHead; |
| 87 _beginTokenStack = [null]; | 87 _beginTokenStack = [null]; |
| 88 _endTokenStack = <Token>[null]; | 88 _endTokenStack = <Token>[null]; |
| 89 | 89 |
| 90 while (true) { | 90 while (true) { |
| 91 if (token.type.kind == BAD_INPUT_TOKEN) { | 91 if (token.type.kind == BAD_INPUT_TOKEN) { |
| 92 ErrorToken errorToken = token; | 92 ErrorToken errorToken = token; |
| 93 translateErrorToken(errorToken, reportError); | 93 translateErrorToken(errorToken, reportError); |
| 94 } else { | 94 } else { |
| 95 var translatedToken = translateToken( | 95 var translatedToken = translateToken( |
| 96 token, translateCommentTokens(token.precedingCommentTokens)); | 96 token, translateCommentTokens(token.precedingComments)); |
| 97 _matchGroups(token, translatedToken); | 97 _matchGroups(token, translatedToken); |
| 98 translatedToken.setNext(translatedToken); | 98 translatedToken.setNext(translatedToken); |
| 99 _analyzerTokenTail.setNext(translatedToken); | 99 _analyzerTokenTail.setNext(translatedToken); |
| 100 translatedToken.previous = _analyzerTokenTail; | 100 translatedToken.previous = _analyzerTokenTail; |
| 101 _analyzerTokenTail = translatedToken; | 101 _analyzerTokenTail = translatedToken; |
| 102 } | 102 } |
| 103 if (token.isEof) { | 103 if (token.isEof) { |
| 104 return _analyzerTokenHead.next; | 104 return _analyzerTokenHead.next; |
| 105 } | 105 } |
| 106 token = token.next; | 106 token = token.next; |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 /// Handles an error found during [convertTokens]. | 110 /// Handles an error found during [convertTokens]. |
| 111 /// | 111 /// |
| 112 /// Intended to be overridden by derived classes; by default, does nothing. | 112 /// Intended to be overridden by derived classes; by default, does nothing. |
| 113 void reportError(analyzer.ScannerErrorCode errorCode, int offset, | 113 void reportError(analyzer.ScannerErrorCode errorCode, int offset, |
| 114 List<Object> arguments) {} | 114 List<Object> arguments) {} |
| 115 | 115 |
| 116 /// Translates a sequence of fasta comment tokens to the corresponding | 116 /// Translates a sequence of fasta comment tokens to the corresponding |
| 117 /// analyzer tokens. | 117 /// analyzer tokens. |
| 118 analyzer.CommentToken translateCommentTokens(Token token) { | 118 analyzer.CommentToken translateCommentTokens(analyzer.Token token) { |
| 119 analyzer.CommentToken head; | 119 analyzer.CommentToken head; |
| 120 if (token != null) { | 120 if (token != null) { |
| 121 head = toAnalyzerCommentToken(token); | 121 head = toAnalyzerCommentToken(token); |
| 122 analyzer.CommentToken tail = head; | 122 analyzer.CommentToken tail = head; |
| 123 token = token.next; | 123 token = token.next; |
| 124 while (token != null) { | 124 while (token != null) { |
| 125 tail = tail.setNext(toAnalyzerCommentToken(token)); | 125 tail = tail.setNext(toAnalyzerCommentToken(token)); |
| 126 token = token.next; | 126 token = token.next; |
| 127 } | 127 } |
| 128 } | 128 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 // tokens as appropriate. | 225 // tokens as appropriate. |
| 226 if (translatedToken is BeginGroupToken && | 226 if (translatedToken is BeginGroupToken && |
| 227 analyzerToken is analyzer.BeginToken && | 227 analyzerToken is analyzer.BeginToken && |
| 228 analyzerToken.endToken != null) { | 228 analyzerToken.endToken != null) { |
| 229 angleBracketStack.clear(); | 229 angleBracketStack.clear(); |
| 230 beginTokenStack.add(translatedToken); | 230 beginTokenStack.add(translatedToken); |
| 231 endTokenStack.add(analyzerToken.endToken); | 231 endTokenStack.add(analyzerToken.endToken); |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 | 234 |
| 235 Token translateComments(analyzer.Token token) { | 235 analyzer.Token translateComments(analyzer.Token token) { |
| 236 if (token == null) { | 236 if (token == null) { |
| 237 return null; | 237 return null; |
| 238 } | 238 } |
| 239 Token head = fromAnalyzerToken(token); | 239 Token head = fromAnalyzerToken(token); |
| 240 Token tail = head; | 240 Token tail = head; |
| 241 token = token.next; | 241 token = token.next; |
| 242 while (token != null) { | 242 while (token != null) { |
| 243 tail.next = fromAnalyzerToken(token); | 243 tail.next = fromAnalyzerToken(token); |
| 244 tail.next.previousToken = tail; // ignore: deprecated_member_use | 244 tail.next.previous = tail; // ignore: deprecated_member_use |
| 245 tail = tail.next; | 245 tail = tail.next; |
| 246 token = token.next; | 246 token = token.next; |
| 247 } | 247 } |
| 248 return head; | 248 return head; |
| 249 } | 249 } |
| 250 | 250 |
| 251 analyzer.Token translateAndAppend(analyzer.Token analyzerToken) { | 251 analyzer.Token translateAndAppend(analyzer.Token analyzerToken) { |
| 252 var token = fromAnalyzerToken(analyzerToken); | 252 var token = fromAnalyzerToken(analyzerToken); |
| 253 token.precedingCommentTokens = | 253 token.precedingComments = |
| 254 translateComments(analyzerToken.precedingComments); | 254 translateComments(analyzerToken.precedingComments); |
| 255 tokenTail.next = token; | 255 tokenTail.next = token; |
| 256 tokenTail.next.previousToken = tokenTail; // ignore: deprecated_member_use | 256 tokenTail.next.previous = tokenTail; // ignore: deprecated_member_use |
| 257 tokenTail = token; | 257 tokenTail = token; |
| 258 matchGroups(analyzerToken, token); | 258 matchGroups(analyzerToken, token); |
| 259 return analyzerToken.next; | 259 return analyzerToken.next; |
| 260 } | 260 } |
| 261 | 261 |
| 262 while (true) { | 262 while (true) { |
| 263 // TODO(paulberry): join up begingroup/endgroup. | 263 // TODO(paulberry): join up begingroup/endgroup. |
| 264 if (analyzerToken.type == TokenType.EOF) { | 264 if (analyzerToken.type == TokenType.EOF) { |
| 265 tokenTail.next = new SymbolToken.eof(analyzerToken.offset); | 265 SymbolToken eof = new SymbolToken.eof(analyzerToken.offset); |
| 266 tokenTail.next.previousToken = tokenTail; // ignore: deprecated_member_use | 266 tokenTail.next = eof; |
| 267 tokenTail.next.precedingCommentTokens = | 267 eof.previous = tokenTail; // ignore: deprecated_member_use |
| 268 eof.precedingComments = |
| 268 translateComments(analyzerToken.precedingComments); | 269 translateComments(analyzerToken.precedingComments); |
| 269 tokenTail.next.next = tokenTail.next; | 270 eof.next = eof; |
| 270 return tokenHead.next; | 271 return tokenHead.next; |
| 271 } | 272 } |
| 272 analyzerToken = translateAndAppend(analyzerToken); | 273 analyzerToken = translateAndAppend(analyzerToken); |
| 273 } | 274 } |
| 274 } | 275 } |
| 275 | 276 |
| 276 /// Converts a single analyzer token into a Fasta token. | 277 /// Converts a single analyzer token into a Fasta token. |
| 277 Token fromAnalyzerToken(analyzer.Token token) { | 278 Token fromAnalyzerToken(analyzer.Token token) { |
| 278 Token beginGroup(TokenType type) => new BeginGroupToken(type, token.offset); | 279 Token beginGroup(TokenType type) => new BeginGroupToken(type, token.offset); |
| 279 Token string(TokenType type) => | 280 Token string(TokenType type) => |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 "hide": analyzer.Keyword.HIDE, | 591 "hide": analyzer.Keyword.HIDE, |
| 591 "native": analyzer.Keyword.NATIVE, | 592 "native": analyzer.Keyword.NATIVE, |
| 592 "of": analyzer.Keyword.OF, | 593 "of": analyzer.Keyword.OF, |
| 593 "on": analyzer.Keyword.ON, | 594 "on": analyzer.Keyword.ON, |
| 594 "patch": analyzer.Keyword.PATCH, | 595 "patch": analyzer.Keyword.PATCH, |
| 595 "show": analyzer.Keyword.SHOW, | 596 "show": analyzer.Keyword.SHOW, |
| 596 "source": analyzer.Keyword.SOURCE, | 597 "source": analyzer.Keyword.SOURCE, |
| 597 "sync": analyzer.Keyword.SYNC, | 598 "sync": analyzer.Keyword.SYNC, |
| 598 "yield": analyzer.Keyword.YIELD, | 599 "yield": analyzer.Keyword.YIELD, |
| 599 }; | 600 }; |
| OLD | NEW |