Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: lib/compiler/implementation/scanner/array_based_scanner.dart

Issue 10539021: Scanner can include comments in the token stream. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: String interpolation identifier used new token Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 if (groupingStack.head.kind === LT_TOKEN) { 158 if (groupingStack.head.kind === LT_TOKEN) {
158 groupingStack = groupingStack.tail; 159 groupingStack = groupingStack.tail;
159 } 160 }
160 if (groupingStack.isEmpty()) return; 161 if (groupingStack.isEmpty()) return;
161 if (groupingStack.head.kind === LT_TOKEN) { 162 if (groupingStack.head.kind === LT_TOKEN) {
162 groupingStack.head.endGroup = tail; 163 groupingStack.head.endGroup = tail;
163 groupingStack = groupingStack.tail; 164 groupingStack = groupingStack.tail;
164 } 165 }
165 } 166 }
166 167
168 void appendComment() {
169 if (!includeComments) return;
170 SourceString value = utf8String(tokenStart, -1);
171 appendByteStringToken(COMMENT_INFO, value);
172 }
173
167 void discardOpenLt() { 174 void discardOpenLt() {
168 while (!groupingStack.isEmpty() && groupingStack.head.kind === LT_TOKEN) { 175 while (!groupingStack.isEmpty() && groupingStack.head.kind === LT_TOKEN) {
169 groupingStack = groupingStack.tail; 176 groupingStack = groupingStack.tail;
170 } 177 }
171 } 178 }
172 179
173 // TODO(ahe): make class abstract instead of adding an abstract method. 180 // TODO(ahe): make class abstract instead of adding an abstract method.
174 abstract peek(); 181 abstract peek();
175 } 182 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698