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

Side by Side Diff: dart/frog/leg/scanner/array_based_scanner.dart

Issue 8805008: Various scanner fixes: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased and update language.status Created 9 years 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
« no previous file with comments | « no previous file | dart/frog/leg/scanner/byte_array_scanner.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 AbstractScanner<S> { 5 class ArrayBasedScanner<S> 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 tail.next = token; 76 tail.next = token;
77 tail = tail.next; 77 tail = tail.next;
78 while (kind !== LT_TOKEN && 78 while (kind !== LT_TOKEN &&
79 !groupingStack.isEmpty() && 79 !groupingStack.isEmpty() &&
80 groupingStack.head.kind === LT_TOKEN) { 80 groupingStack.head.kind === LT_TOKEN) {
81 groupingStack = groupingStack.tail; 81 groupingStack = groupingStack.tail;
82 } 82 }
83 groupingStack = groupingStack.prepend(token); 83 groupingStack = groupingStack.prepend(token);
84 } 84 }
85 85
86 void appendEndGroup(int kind, String value, int openKind) { 86 int appendEndGroup(int kind, String value, int openKind) {
87 Token oldTail = tail; 87 assert(openKind !== LT_TOKEN);
88 appendStringToken(kind, value); 88 appendStringToken(kind, value);
89 if (groupingStack.isEmpty()) { 89 if (groupingStack.isEmpty()) {
90 if (openKind === LT_TOKEN) return;
91 throw new MalformedInputException('Unmatched $value'); 90 throw new MalformedInputException('Unmatched $value');
92 } 91 }
93 while (openKind !== LT_TOKEN && 92 discardOpenLt();
94 !groupingStack.isEmpty() && 93 BeginGroupToken begin = groupingStack.head;
95 groupingStack.head.kind === LT_TOKEN) { 94 if (begin.kind !== openKind) {
95 if (openKind !== OPEN_CURLY_BRACKET_TOKEN ||
96 begin.kind !== STRING_INTERPOLATION_TOKEN) {
97 // Not ending string interpolation.
98 throw new MalformedInputException('Unmatched ${begin.stringValue}');
99 }
100 // We're ending an interpolated expression.
101 begin.endGroup = tail;
102 groupingStack = groupingStack.tail;
103 // Using "start-of-text" to signal that we're back in string
104 // scanning mode.
105 return $STX;
106 }
107 begin.endGroup = tail;
108 groupingStack = groupingStack.tail;
109 return advance();
110 }
111
112 void appendGt(int kind, String value) {
113 appendStringToken(kind, value);
114 if (groupingStack.isEmpty()) return;
115 if (groupingStack.head.kind === LT_TOKEN) {
116 groupingStack.head.endGroup = tail;
96 groupingStack = groupingStack.tail; 117 groupingStack = groupingStack.tail;
97 } 118 }
98 if (groupingStack.head.kind !== openKind) {
99 if (openKind === LT_TOKEN) return;
100 throw new MalformedInputException('Unmatched $value');
101 }
102 groupingStack.head.endGroup = oldTail.next;
103 groupingStack = groupingStack.tail;
104 } 119 }
105 120
106 void appendGtGt(int kind, String value) { 121 void appendGtGt(int kind, String value) {
107 Token oldTail = tail;
108 appendStringToken(kind, value); 122 appendStringToken(kind, value);
109 if (groupingStack.isEmpty()) return; 123 if (groupingStack.isEmpty()) return;
110 if (groupingStack.head.kind === LT_TOKEN) { 124 if (groupingStack.head.kind === LT_TOKEN) {
111 groupingStack = groupingStack.tail; 125 groupingStack = groupingStack.tail;
112 } 126 }
113 if (groupingStack.isEmpty()) return; 127 if (groupingStack.isEmpty()) return;
114 if (groupingStack.head.kind === LT_TOKEN) { 128 if (groupingStack.head.kind === LT_TOKEN) {
115 groupingStack.head.endGroup = oldTail.next; 129 groupingStack.head.endGroup = tail;
116 groupingStack = groupingStack.tail; 130 groupingStack = groupingStack.tail;
117 } 131 }
118 } 132 }
119 133
120 void appendGtGtGt(int kind, String value) { 134 void appendGtGtGt(int kind, String value) {
121 Token oldTail = tail;
122 appendStringToken(kind, value); 135 appendStringToken(kind, value);
123 if (groupingStack.isEmpty()) return; 136 if (groupingStack.isEmpty()) return;
124 if (groupingStack.head.kind === LT_TOKEN) { 137 if (groupingStack.head.kind === LT_TOKEN) {
125 groupingStack = groupingStack.tail; 138 groupingStack = groupingStack.tail;
126 } 139 }
127 if (groupingStack.isEmpty()) return; 140 if (groupingStack.isEmpty()) return;
128 if (groupingStack.head.kind === LT_TOKEN) { 141 if (groupingStack.head.kind === LT_TOKEN) {
129 groupingStack = groupingStack.tail; 142 groupingStack = groupingStack.tail;
130 } 143 }
131 if (groupingStack.isEmpty()) return; 144 if (groupingStack.isEmpty()) return;
132 if (groupingStack.head.kind === LT_TOKEN) { 145 if (groupingStack.head.kind === LT_TOKEN) {
133 groupingStack.head.endGroup = oldTail.next; 146 groupingStack.head.endGroup = tail;
134 groupingStack = groupingStack.tail; 147 groupingStack = groupingStack.tail;
135 } 148 }
136 } 149 }
150
151 void discardOpenLt() {
152 while (!groupingStack.isEmpty() && groupingStack.head.kind === LT_TOKEN) {
153 groupingStack = groupingStack.tail;
154 }
155 }
137 } 156 }
OLDNEW
« no previous file with comments | « no previous file | dart/frog/leg/scanner/byte_array_scanner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698