| 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 part of scanner; | 5 part of scanner; |
| 6 | 6 |
| 7 abstract class ArrayBasedScanner extends AbstractScanner { | 7 abstract class ArrayBasedScanner extends AbstractScanner { |
| 8 ArrayBasedScanner(SourceFile file, bool includeComments) | 8 ArrayBasedScanner(SourceFile file, bool includeComments) |
| 9 : super(file, includeComments); | 9 : super(file, includeComments); |
| 10 | 10 |
| 11 /** | 11 /** |
| 12 * The stack of open groups, e.g [: { ... ( .. :] | 12 * The stack of open groups, e.g [: { ... ( .. :] |
| 13 * Each BeginGroupToken has a pointer to the token where the group | 13 * Each BeginGroupToken has a pointer to the token where the group |
| 14 * ends. This field is set when scanning the end group token. | 14 * ends. This field is set when scanning the end group token. |
| 15 */ | 15 */ |
| 16 Link<BeginGroupToken> groupingStack = const Link<BeginGroupToken>(); | 16 Link<BeginGroupToken> groupingStack = const Link<BeginGroupToken>(); |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * Appends a token whose kind is determined by [info] and content is defined | 19 * Appends a token whose kind is determined by [info] and content is defined |
| 20 * by the String [value]. | 20 * by the String [value]. |
| 21 * | 21 * |
| 22 * This method is invoked for class names, field names, method names, types, | 22 * This method is invoked for class names, field names, method names, types, |
| 23 * etc. | 23 * etc. |
| 24 */ | 24 */ |
| 25 void appendStringToken(PrecedenceInfo info, String value) { | 25 void appendStringToken(PrecedenceInfo info, String value) { |
| 26 tail.next = new StringToken.fromString(info, value, tokenStart, true); | 26 tail.next = new StringToken.fromString(info, value, tokenStart, |
| 27 canonicalize: true); |
| 27 tail = tail.next; | 28 tail = tail.next; |
| 28 } | 29 } |
| 29 | 30 |
| 30 /** | 31 /** |
| 31 * Appends a fixed token whose kind and content is determined by [info]. | 32 * Appends a fixed token whose kind and content is determined by [info]. |
| 32 * Appends an *operator* token from [info]. | 33 * Appends an *operator* token from [info]. |
| 33 * | 34 * |
| 34 * An operator token represent operators like ':', '.', ';', '&&', '==', '--', | 35 * An operator token represent operators like ':', '.', ';', '&&', '==', '--', |
| 35 * '=>', etc. | 36 * '=>', etc. |
| 36 */ | 37 */ |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 * This method is used by the scanners to track line breaks and create the | 90 * This method is used by the scanners to track line breaks and create the |
| 90 * [lineStarts] map. | 91 * [lineStarts] map. |
| 91 */ | 92 */ |
| 92 void appendWhiteSpace(int next) { | 93 void appendWhiteSpace(int next) { |
| 93 if (next == $LF && file != null) { | 94 if (next == $LF && file != null) { |
| 94 lineStarts.add(stringOffset + 1); // +1, the line starts after the $LF. | 95 lineStarts.add(stringOffset + 1); // +1, the line starts after the $LF. |
| 95 } | 96 } |
| 96 } | 97 } |
| 97 | 98 |
| 98 /** | 99 /** |
| 99 * Notifies on [$LF] characters in multi-line commends or strings. | 100 * Notifies on [$LF] characters in multi-line comments or strings. |
| 100 * | 101 * |
| 101 * This method is used by the scanners to track line breaks and create the | 102 * This method is used by the scanners to track line breaks and create the |
| 102 * [lineStarts] map. | 103 * [lineStarts] map. |
| 103 */ | 104 */ |
| 104 void lineFeedInMultiline() { | 105 void lineFeedInMultiline() { |
| 105 if (file != null) { | 106 if (file != null) { |
| 106 lineStarts.add(stringOffset + 1); | 107 lineStarts.add(stringOffset + 1); |
| 107 } | 108 } |
| 108 } | 109 } |
| 109 | 110 |
| 110 /** | 111 /** |
| 111 * Appends a token that begins a new group, represented by [value]. | 112 * Appends a token that begins a new group, represented by [value]. |
| 112 * Group begin tokens are '{', '(', '[' and '${'. | 113 * Group begin tokens are '{', '(', '[' and '${'. |
| 113 */ | 114 */ |
| 114 void appendBeginGroup(PrecedenceInfo info) { | 115 void appendBeginGroup(PrecedenceInfo info) { |
| 115 Token token = new BeginGroupToken(info, tokenStart); | 116 Token token = new BeginGroupToken(info, tokenStart); |
| 116 tail.next = token; | 117 tail.next = token; |
| 117 tail = tail.next; | 118 tail = tail.next; |
| 118 | 119 |
| 119 // { ( [ ${ cannot appear inside a type parameters / arguments. | 120 // { ( [ ${ cannot appear inside a type parameters / arguments. |
| 120 if (!identical(info.kind, LT_TOKEN)) discardOpenLt(); | 121 if (!identical(info.kind, LT_TOKEN)) discardOpenLt(); |
| 121 groupingStack = groupingStack.prepend(token); | 122 groupingStack = groupingStack.prepend(token); |
| 122 } | 123 } |
| 123 | 124 |
| 124 /** | 125 /** |
| 125 * Appends a token that begins a ends group, represented by [value]. | 126 * Appends a token that begins an end group, represented by [value]. |
| 126 * It handles the group end tokens '}', ')' and ']'. The tokens '>' and | 127 * It handles the group end tokens '}', ')' and ']'. The tokens '>' and |
| 127 * '>>' are handled separately bo [appendGt] and [appendGtGt]. | 128 * '>>' are handled separately bo [appendGt] and [appendGtGt]. |
| 128 */ | 129 */ |
| 129 int appendEndGroup(PrecedenceInfo info, int openKind) { | 130 int appendEndGroup(PrecedenceInfo info, int openKind) { |
| 130 assert(!identical(openKind, LT_TOKEN)); // openKind is < for > and >> | 131 assert(!identical(openKind, LT_TOKEN)); // openKind is < for > and >> |
| 131 appendPrecedenceToken(info); | 132 appendPrecedenceToken(info); |
| 132 // Don't report unmatched errors for <; it is also the less-than operator. | 133 // Don't report unmatched errors for <; it is also the less-than operator. |
| 133 discardOpenLt(); | 134 discardOpenLt(); |
| 134 if (groupingStack.isEmpty) { | 135 if (groupingStack.isEmpty) { |
| 135 return advance(); | 136 return advance(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 groupingStack = groupingStack.tail; | 188 groupingStack = groupingStack.tail; |
| 188 } | 189 } |
| 189 } | 190 } |
| 190 | 191 |
| 191 void appendComment(start, bool asciiOnly) { | 192 void appendComment(start, bool asciiOnly) { |
| 192 if (!includeComments) return; | 193 if (!includeComments) return; |
| 193 appendSubstringToken(COMMENT_INFO, start, asciiOnly); | 194 appendSubstringToken(COMMENT_INFO, start, asciiOnly); |
| 194 } | 195 } |
| 195 | 196 |
| 196 /** | 197 /** |
| 197 * We call this method to discard '<' from the "grouping" stack | 198 * This method is called to discard '<' from the "grouping" stack. |
| 198 * (maintained by subclasses). | |
| 199 * | 199 * |
| 200 * [PartialParser.skipExpression] relies on the fact that we do not | 200 * [PartialParser.skipExpression] relies on the fact that we do not |
| 201 * create groups for stuff like: | 201 * create groups for stuff like: |
| 202 * [:a = b < c, d = e > f:]. | 202 * [:a = b < c, d = e > f:]. |
| 203 * | 203 * |
| 204 * In other words, this method is called when the scanner recognizes | 204 * In other words, this method is called when the scanner recognizes |
| 205 * something which cannot possibly be part of a type | 205 * something which cannot possibly be part of a type parameter/argument |
| 206 * parameter/argument list. | 206 * list, like the '=' in the above example. |
| 207 */ | 207 */ |
| 208 void discardOpenLt() { | 208 void discardOpenLt() { |
| 209 while (!groupingStack.isEmpty | 209 while (!groupingStack.isEmpty |
| 210 && identical(groupingStack.head.kind, LT_TOKEN)) { | 210 && identical(groupingStack.head.kind, LT_TOKEN)) { |
| 211 groupingStack = groupingStack.tail; | 211 groupingStack = groupingStack.tail; |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 } | 214 } |
| OLD | NEW |