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 abstract | 5 abstract |
6 class ArrayBasedScanner<S extends SourceString> extends AbstractScanner<S> { | 6 class ArrayBasedScanner<S extends SourceString> extends AbstractScanner<S> { |
7 int get charOffset => byteOffset + extraCharOffset; | 7 int get charOffset => byteOffset + extraCharOffset; |
8 final Token tokens; | 8 final Token tokens; |
9 Token tail; | 9 Token tail; |
10 int tokenStart; | 10 int tokenStart; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 tail.next = new KeywordToken(keyword, tokenStart); | 58 tail.next = new KeywordToken(keyword, tokenStart); |
59 tail = tail.next; | 59 tail = tail.next; |
60 } | 60 } |
61 | 61 |
62 void appendEofToken() { | 62 void appendEofToken() { |
63 tail.next = new Token(EOF_INFO, charOffset); | 63 tail.next = new Token(EOF_INFO, charOffset); |
64 tail = tail.next; | 64 tail = tail.next; |
65 // EOF points to itself so there's always infinite look-ahead. | 65 // EOF points to itself so there's always infinite look-ahead. |
66 tail.next = tail; | 66 tail.next = tail; |
67 discardOpenLt(); | 67 discardOpenLt(); |
68 while (!groupingStack.isEmpty()) { | 68 while (!groupingStack.isEmpty) { |
69 BeginGroupToken begin = groupingStack.head; | 69 BeginGroupToken begin = groupingStack.head; |
70 begin.endGroup = tail; | 70 begin.endGroup = tail; |
71 groupingStack = groupingStack.tail; | 71 groupingStack = groupingStack.tail; |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 void beginToken() { | 75 void beginToken() { |
76 tokenStart = charOffset; | 76 tokenStart = charOffset; |
77 } | 77 } |
78 | 78 |
(...skipping 18 matching lines...) Expand all Loading... |
97 tail.next = token; | 97 tail.next = token; |
98 tail = tail.next; | 98 tail = tail.next; |
99 if (!identical(info.kind, LT_TOKEN)) discardOpenLt(); | 99 if (!identical(info.kind, LT_TOKEN)) discardOpenLt(); |
100 groupingStack = groupingStack.prepend(token); | 100 groupingStack = groupingStack.prepend(token); |
101 } | 101 } |
102 | 102 |
103 int appendEndGroup(PrecedenceInfo info, String value, int openKind) { | 103 int appendEndGroup(PrecedenceInfo info, String value, int openKind) { |
104 assert(!identical(openKind, LT_TOKEN)); | 104 assert(!identical(openKind, LT_TOKEN)); |
105 appendStringToken(info, value); | 105 appendStringToken(info, value); |
106 discardOpenLt(); | 106 discardOpenLt(); |
107 if (groupingStack.isEmpty()) { | 107 if (groupingStack.isEmpty) { |
108 return advance(); | 108 return advance(); |
109 } | 109 } |
110 BeginGroupToken begin = groupingStack.head; | 110 BeginGroupToken begin = groupingStack.head; |
111 if (!identical(begin.kind, openKind)) { | 111 if (!identical(begin.kind, openKind)) { |
112 if (!identical(openKind, OPEN_CURLY_BRACKET_TOKEN) || | 112 if (!identical(openKind, OPEN_CURLY_BRACKET_TOKEN) || |
113 !identical(begin.kind, STRING_INTERPOLATION_TOKEN)) { | 113 !identical(begin.kind, STRING_INTERPOLATION_TOKEN)) { |
114 // Not ending string interpolation. | 114 // Not ending string interpolation. |
115 return error(new SourceString('Unmatched ${begin.stringValue}')); | 115 return error(new SourceString('Unmatched ${begin.stringValue}')); |
116 } | 116 } |
117 // We're ending an interpolated expression. | 117 // We're ending an interpolated expression. |
118 begin.endGroup = tail; | 118 begin.endGroup = tail; |
119 groupingStack = groupingStack.tail; | 119 groupingStack = groupingStack.tail; |
120 // Using "start-of-text" to signal that we're back in string | 120 // Using "start-of-text" to signal that we're back in string |
121 // scanning mode. | 121 // scanning mode. |
122 return $STX; | 122 return $STX; |
123 } | 123 } |
124 begin.endGroup = tail; | 124 begin.endGroup = tail; |
125 groupingStack = groupingStack.tail; | 125 groupingStack = groupingStack.tail; |
126 return advance(); | 126 return advance(); |
127 } | 127 } |
128 | 128 |
129 void appendGt(PrecedenceInfo info, String value) { | 129 void appendGt(PrecedenceInfo info, String value) { |
130 appendStringToken(info, value); | 130 appendStringToken(info, value); |
131 if (groupingStack.isEmpty()) return; | 131 if (groupingStack.isEmpty) return; |
132 if (identical(groupingStack.head.kind, LT_TOKEN)) { | 132 if (identical(groupingStack.head.kind, LT_TOKEN)) { |
133 groupingStack.head.endGroup = tail; | 133 groupingStack.head.endGroup = tail; |
134 groupingStack = groupingStack.tail; | 134 groupingStack = groupingStack.tail; |
135 } | 135 } |
136 } | 136 } |
137 | 137 |
138 void appendGtGt(PrecedenceInfo info, String value) { | 138 void appendGtGt(PrecedenceInfo info, String value) { |
139 appendStringToken(info, value); | 139 appendStringToken(info, value); |
140 if (groupingStack.isEmpty()) return; | 140 if (groupingStack.isEmpty) return; |
141 if (identical(groupingStack.head.kind, LT_TOKEN)) { | 141 if (identical(groupingStack.head.kind, LT_TOKEN)) { |
142 groupingStack = groupingStack.tail; | 142 groupingStack = groupingStack.tail; |
143 } | 143 } |
144 if (groupingStack.isEmpty()) return; | 144 if (groupingStack.isEmpty) return; |
145 if (identical(groupingStack.head.kind, LT_TOKEN)) { | 145 if (identical(groupingStack.head.kind, LT_TOKEN)) { |
146 groupingStack.head.endGroup = tail; | 146 groupingStack.head.endGroup = tail; |
147 groupingStack = groupingStack.tail; | 147 groupingStack = groupingStack.tail; |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 void appendGtGtGt(PrecedenceInfo info, String value) { | 151 void appendGtGtGt(PrecedenceInfo info, String value) { |
152 appendStringToken(info, value); | 152 appendStringToken(info, value); |
153 if (groupingStack.isEmpty()) return; | 153 if (groupingStack.isEmpty) return; |
154 if (identical(groupingStack.head.kind, LT_TOKEN)) { | 154 if (identical(groupingStack.head.kind, LT_TOKEN)) { |
155 groupingStack = groupingStack.tail; | 155 groupingStack = groupingStack.tail; |
156 } | 156 } |
157 if (groupingStack.isEmpty()) return; | 157 if (groupingStack.isEmpty) return; |
158 if (identical(groupingStack.head.kind, LT_TOKEN)) { | 158 if (identical(groupingStack.head.kind, LT_TOKEN)) { |
159 groupingStack = groupingStack.tail; | 159 groupingStack = groupingStack.tail; |
160 } | 160 } |
161 if (groupingStack.isEmpty()) return; | 161 if (groupingStack.isEmpty) return; |
162 if (identical(groupingStack.head.kind, LT_TOKEN)) { | 162 if (identical(groupingStack.head.kind, LT_TOKEN)) { |
163 groupingStack.head.endGroup = tail; | 163 groupingStack.head.endGroup = tail; |
164 groupingStack = groupingStack.tail; | 164 groupingStack = groupingStack.tail; |
165 } | 165 } |
166 } | 166 } |
167 | 167 |
168 void appendComment() { | 168 void appendComment() { |
169 if (!includeComments) return; | 169 if (!includeComments) return; |
170 SourceString value = utf8String(tokenStart, -1); | 170 SourceString value = utf8String(tokenStart, -1); |
171 appendByteStringToken(COMMENT_INFO, value); | 171 appendByteStringToken(COMMENT_INFO, value); |
172 } | 172 } |
173 | 173 |
174 void discardOpenLt() { | 174 void discardOpenLt() { |
175 while (!groupingStack.isEmpty() | 175 while (!groupingStack.isEmpty |
176 && identical(groupingStack.head.kind, LT_TOKEN)) { | 176 && identical(groupingStack.head.kind, LT_TOKEN)) { |
177 groupingStack = groupingStack.tail; | 177 groupingStack = groupingStack.tail; |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 // TODO(ahe): make class abstract instead of adding an abstract method. | 181 // TODO(ahe): make class abstract instead of adding an abstract method. |
182 abstract peek(); | 182 abstract peek(); |
183 } | 183 } |
OLD | NEW |