| 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; |
| 11 final bool includeComments; |
| 11 | 12 |
| 12 /** Since the input is UTF8, some characters are represented by more | 13 /** Since the input is UTF8, some characters are represented by more |
| 13 * than one byte. [extraCharOffset] tracks the difference. */ | 14 * than one byte. [extraCharOffset] tracks the difference. */ |
| 14 int extraCharOffset; | 15 int extraCharOffset; |
| 15 Link<BeginGroupToken> groupingStack = const EmptyLink<BeginGroupToken>(); | 16 Link<BeginGroupToken> groupingStack = const EmptyLink<BeginGroupToken>(); |
| 16 | 17 |
| 17 ArrayBasedScanner() | 18 ArrayBasedScanner(this.includeComments) |
| 18 : this.extraCharOffset = 0, | 19 : this.extraCharOffset = 0, |
| 19 this.tokenStart = -1, | 20 this.tokenStart = -1, |
| 20 this.byteOffset = -1, | 21 this.byteOffset = -1, |
| 21 this.tokens = new Token(EOF_INFO, -1) { | 22 this.tokens = new Token(EOF_INFO, -1) { |
| 22 this.tail = this.tokens; | 23 this.tail = this.tokens; |
| 23 } | 24 } |
| 24 | 25 |
| 25 int advance() { | 26 int advance() { |
| 26 int next = nextByte(); | 27 int next = nextByte(); |
| 27 return next; | 28 return next; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 if (groupingStack.head.kind === LT_TOKEN) { | 154 if (groupingStack.head.kind === LT_TOKEN) { |
| 154 groupingStack = groupingStack.tail; | 155 groupingStack = groupingStack.tail; |
| 155 } | 156 } |
| 156 if (groupingStack.isEmpty()) return; | 157 if (groupingStack.isEmpty()) return; |
| 157 if (groupingStack.head.kind === LT_TOKEN) { | 158 if (groupingStack.head.kind === LT_TOKEN) { |
| 158 groupingStack.head.endGroup = tail; | 159 groupingStack.head.endGroup = tail; |
| 159 groupingStack = groupingStack.tail; | 160 groupingStack = groupingStack.tail; |
| 160 } | 161 } |
| 161 } | 162 } |
| 162 | 163 |
| 164 void appendComment() { |
| 165 if (!includeComments) return; |
| 166 SourceString value = utf8String(tokenStart, -1); |
| 167 appendByteStringToken(COMMENT_INFO, value); |
| 168 } |
| 169 |
| 163 void discardOpenLt() { | 170 void discardOpenLt() { |
| 164 while (!groupingStack.isEmpty() && groupingStack.head.kind === LT_TOKEN) { | 171 while (!groupingStack.isEmpty() && groupingStack.head.kind === LT_TOKEN) { |
| 165 groupingStack = groupingStack.tail; | 172 groupingStack = groupingStack.tail; |
| 166 } | 173 } |
| 167 } | 174 } |
| 168 | 175 |
| 169 // TODO(ahe): make class abstract instead of adding an abstract method. | 176 // TODO(ahe): make class abstract instead of adding an abstract method. |
| 170 abstract peek(); | 177 abstract peek(); |
| 171 } | 178 } |
| OLD | NEW |