| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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.scanner.array_based_scanner; | 5 library fasta.scanner.array_based_scanner; |
| 6 | 6 |
| 7 import 'error_token.dart' show ErrorToken, UnmatchedToken; | 7 import 'error_token.dart' show ErrorToken, UnmatchedToken; |
| 8 | 8 |
| 9 import '../../scanner/token.dart' | 9 import '../../scanner/token.dart' |
| 10 show | 10 show BeginToken, Keyword, KeywordToken, SyntheticToken, Token, TokenType; |
| 11 BeginToken, | |
| 12 BeginTokenWithComment, | |
| 13 Keyword, | |
| 14 KeywordTokenWithComment, | |
| 15 SyntheticToken, | |
| 16 Token, | |
| 17 TokenType, | |
| 18 TokenWithComment; | |
| 19 | 11 |
| 20 import '../../scanner/token.dart' as analyzer show StringToken; | 12 import '../../scanner/token.dart' as analyzer show StringToken; |
| 21 | 13 |
| 22 import 'token_constants.dart' | 14 import 'token_constants.dart' |
| 23 show | 15 show |
| 24 LT_TOKEN, | 16 LT_TOKEN, |
| 25 OPEN_CURLY_BRACKET_TOKEN, | 17 OPEN_CURLY_BRACKET_TOKEN, |
| 26 OPEN_PAREN_TOKEN, | 18 OPEN_PAREN_TOKEN, |
| 27 STRING_INTERPOLATION_TOKEN; | 19 STRING_INTERPOLATION_TOKEN; |
| 28 | 20 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 48 Link<BeginToken> groupingStack = const Link<BeginToken>(); | 40 Link<BeginToken> groupingStack = const Link<BeginToken>(); |
| 49 | 41 |
| 50 /** | 42 /** |
| 51 * Appends a fixed token whose kind and content is determined by [type]. | 43 * Appends a fixed token whose kind and content is determined by [type]. |
| 52 * Appends an *operator* token from [type]. | 44 * Appends an *operator* token from [type]. |
| 53 * | 45 * |
| 54 * An operator token represent operators like ':', '.', ';', '&&', '==', '--', | 46 * An operator token represent operators like ':', '.', ';', '&&', '==', '--', |
| 55 * '=>', etc. | 47 * '=>', etc. |
| 56 */ | 48 */ |
| 57 void appendPrecedenceToken(TokenType type) { | 49 void appendPrecedenceToken(TokenType type) { |
| 58 appendToken(new TokenWithComment(type, tokenStart, comments)); | 50 appendToken(new Token(type, tokenStart, comments)); |
| 59 } | 51 } |
| 60 | 52 |
| 61 /** | 53 /** |
| 62 * Appends a fixed token based on whether the current char is [choice] or not. | 54 * Appends a fixed token based on whether the current char is [choice] or not. |
| 63 * If the current char is [choice] a fixed token whose kind and content | 55 * If the current char is [choice] a fixed token whose kind and content |
| 64 * is determined by [yes] is appended, otherwise a fixed token whose kind | 56 * is determined by [yes] is appended, otherwise a fixed token whose kind |
| 65 * and content is determined by [no] is appended. | 57 * and content is determined by [no] is appended. |
| 66 */ | 58 */ |
| 67 int select(int choice, TokenType yes, TokenType no) { | 59 int select(int choice, TokenType yes, TokenType no) { |
| 68 int next = advance(); | 60 int next = advance(); |
| 69 if (identical(next, choice)) { | 61 if (identical(next, choice)) { |
| 70 appendPrecedenceToken(yes); | 62 appendPrecedenceToken(yes); |
| 71 return advance(); | 63 return advance(); |
| 72 } else { | 64 } else { |
| 73 appendPrecedenceToken(no); | 65 appendPrecedenceToken(no); |
| 74 return next; | 66 return next; |
| 75 } | 67 } |
| 76 } | 68 } |
| 77 | 69 |
| 78 /** | 70 /** |
| 79 * Appends a keyword token whose kind is determined by [keyword]. | 71 * Appends a keyword token whose kind is determined by [keyword]. |
| 80 */ | 72 */ |
| 81 void appendKeywordToken(Keyword keyword) { | 73 void appendKeywordToken(Keyword keyword) { |
| 82 String syntax = keyword.lexeme; | 74 String syntax = keyword.lexeme; |
| 83 // Type parameters and arguments cannot contain 'this'. | 75 // Type parameters and arguments cannot contain 'this'. |
| 84 if (identical(syntax, 'this')) { | 76 if (identical(syntax, 'this')) { |
| 85 discardOpenLt(); | 77 discardOpenLt(); |
| 86 } | 78 } |
| 87 appendToken(new KeywordTokenWithComment(keyword, tokenStart, comments)); | 79 appendToken(new KeywordToken(keyword, tokenStart, comments)); |
| 88 } | 80 } |
| 89 | 81 |
| 90 void appendEofToken() { | 82 void appendEofToken() { |
| 91 beginToken(); | 83 beginToken(); |
| 92 discardOpenLt(); | 84 discardOpenLt(); |
| 93 while (!groupingStack.isEmpty) { | 85 while (!groupingStack.isEmpty) { |
| 94 unmatchedBeginGroup(groupingStack.head); | 86 unmatchedBeginGroup(groupingStack.head); |
| 95 groupingStack = groupingStack.tail; | 87 groupingStack = groupingStack.tail; |
| 96 } | 88 } |
| 97 appendToken(new Token.eof(tokenStart, comments)); | 89 appendToken(new Token.eof(tokenStart, comments)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 118 */ | 110 */ |
| 119 void lineFeedInMultiline() { | 111 void lineFeedInMultiline() { |
| 120 lineStarts.add(stringOffset + 1); | 112 lineStarts.add(stringOffset + 1); |
| 121 } | 113 } |
| 122 | 114 |
| 123 /** | 115 /** |
| 124 * Appends a token that begins a new group, represented by [type]. | 116 * Appends a token that begins a new group, represented by [type]. |
| 125 * Group begin tokens are '{', '(', '[', '<' and '${'. | 117 * Group begin tokens are '{', '(', '[', '<' and '${'. |
| 126 */ | 118 */ |
| 127 void appendBeginGroup(TokenType type) { | 119 void appendBeginGroup(TokenType type) { |
| 128 Token token = new BeginTokenWithComment(type, tokenStart, comments); | 120 Token token = new BeginToken(type, tokenStart, comments); |
| 129 appendToken(token); | 121 appendToken(token); |
| 130 | 122 |
| 131 // { [ ${ cannot appear inside a type parameters / arguments. | 123 // { [ ${ cannot appear inside a type parameters / arguments. |
| 132 if (!identical(type.kind, LT_TOKEN) && | 124 if (!identical(type.kind, LT_TOKEN) && |
| 133 !identical(type.kind, OPEN_PAREN_TOKEN)) { | 125 !identical(type.kind, OPEN_PAREN_TOKEN)) { |
| 134 discardOpenLt(); | 126 discardOpenLt(); |
| 135 } | 127 } |
| 136 groupingStack = groupingStack.prepend(token); | 128 groupingStack = groupingStack.prepend(token); |
| 137 } | 129 } |
| 138 | 130 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 // | | 359 // | |
| 368 // next | 360 // next |
| 369 // v | 361 // v |
| 370 // EOF | 362 // EOF |
| 371 TokenType type = closeBraceInfoFor(begin); | 363 TokenType type = closeBraceInfoFor(begin); |
| 372 appendToken(new SyntheticToken(type, tokenStart)); | 364 appendToken(new SyntheticToken(type, tokenStart)); |
| 373 begin.endGroup = tail; | 365 begin.endGroup = tail; |
| 374 appendErrorToken(new UnmatchedToken(begin)); | 366 appendErrorToken(new UnmatchedToken(begin)); |
| 375 } | 367 } |
| 376 } | 368 } |
| OLD | NEW |