| 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 class ArrayBasedScanner<S extends SourceString> extends AbstractScanner<S> { | 5 class ArrayBasedScanner<S extends SourceString> extends AbstractScanner<S> { |
| 6 int get charOffset() => byteOffset + extraCharOffset; | 6 int get charOffset() => byteOffset + extraCharOffset; |
| 7 final Token tokens; | 7 final Token tokens; |
| 8 Token tail; | 8 Token tail; |
| 9 int tokenStart; | 9 int tokenStart; |
| 10 int byteOffset; | 10 int byteOffset; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 tail.next = new Token(info, tokenStart); | 42 tail.next = new Token(info, tokenStart); |
| 43 tail = tail.next; | 43 tail = tail.next; |
| 44 } | 44 } |
| 45 | 45 |
| 46 void appendStringToken(PrecedenceInfo info, String value) { | 46 void appendStringToken(PrecedenceInfo info, String value) { |
| 47 tail.next = new StringToken(info, value, tokenStart); | 47 tail.next = new StringToken(info, value, tokenStart); |
| 48 tail = tail.next; | 48 tail = tail.next; |
| 49 } | 49 } |
| 50 | 50 |
| 51 void appendKeywordToken(Keyword keyword) { | 51 void appendKeywordToken(Keyword keyword) { |
| 52 String syntax = keyword.syntax; |
| 53 |
| 54 // Type parameters and arguments cannot contain 'this' or 'super'. |
| 55 if (syntax === 'this' || syntax === 'super') discardOpenLt(); |
| 52 tail.next = new KeywordToken(keyword, tokenStart); | 56 tail.next = new KeywordToken(keyword, tokenStart); |
| 53 tail = tail.next; | 57 tail = tail.next; |
| 54 } | 58 } |
| 55 | 59 |
| 56 void appendEofToken() { | 60 void appendEofToken() { |
| 57 tail.next = new Token(EOF_INFO, charOffset); | 61 tail.next = new Token(EOF_INFO, charOffset); |
| 58 tail = tail.next; | 62 tail = tail.next; |
| 59 // EOF points to itself so there's always infinite look-ahead. | 63 // EOF points to itself so there's always infinite look-ahead. |
| 60 tail.next = tail; | 64 tail.next = tail; |
| 61 discardOpenLt(); | 65 discardOpenLt(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 83 } | 87 } |
| 84 | 88 |
| 85 void appendWhiteSpace(int next) { | 89 void appendWhiteSpace(int next) { |
| 86 // Do nothing, we don't collect white space. | 90 // Do nothing, we don't collect white space. |
| 87 } | 91 } |
| 88 | 92 |
| 89 void appendBeginGroup(PrecedenceInfo info, String value) { | 93 void appendBeginGroup(PrecedenceInfo info, String value) { |
| 90 Token token = new BeginGroupToken(info, value, tokenStart); | 94 Token token = new BeginGroupToken(info, value, tokenStart); |
| 91 tail.next = token; | 95 tail.next = token; |
| 92 tail = tail.next; | 96 tail = tail.next; |
| 93 while (info.kind !== LT_TOKEN && | 97 if (info.kind !== LT_TOKEN) discardOpenLt(); |
| 94 !groupingStack.isEmpty() && | |
| 95 groupingStack.head.kind === LT_TOKEN) { | |
| 96 groupingStack = groupingStack.tail; | |
| 97 } | |
| 98 groupingStack = groupingStack.prepend(token); | 98 groupingStack = groupingStack.prepend(token); |
| 99 } | 99 } |
| 100 | 100 |
| 101 int appendEndGroup(PrecedenceInfo info, String value, int openKind) { | 101 int appendEndGroup(PrecedenceInfo info, String value, int openKind) { |
| 102 assert(openKind !== LT_TOKEN); | 102 assert(openKind !== LT_TOKEN); |
| 103 appendStringToken(info, value); | 103 appendStringToken(info, value); |
| 104 discardOpenLt(); | 104 discardOpenLt(); |
| 105 if (groupingStack.isEmpty()) { | 105 if (groupingStack.isEmpty()) { |
| 106 return advance(); | 106 return advance(); |
| 107 } | 107 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 166 |
| 167 void discardOpenLt() { | 167 void discardOpenLt() { |
| 168 while (!groupingStack.isEmpty() && groupingStack.head.kind === LT_TOKEN) { | 168 while (!groupingStack.isEmpty() && groupingStack.head.kind === LT_TOKEN) { |
| 169 groupingStack = groupingStack.tail; | 169 groupingStack = groupingStack.tail; |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 // TODO(ahe): make class abstract instead of adding an abstract method. | 173 // TODO(ahe): make class abstract instead of adding an abstract method. |
| 174 abstract peek(); | 174 abstract peek(); |
| 175 } | 175 } |
| OLD | NEW |