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

Side by Side Diff: src/lexer/experimental-scanner.h

Issue 88823004: ExperimentalScanner += SeekForward. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 return 0; // FIXME 174 return 0; // FIXME
175 } 175 }
176 176
177 uc32 ScanOctalEscape(uc32 c, int length) { return 0; } // FIXME 177 uc32 ScanOctalEscape(uc32 c, int length) { return 0; } // FIXME
178 178
179 Location octal_position() const { 179 Location octal_position() const {
180 return Location(0, 0); // FIXME 180 return Location(0, 0); // FIXME
181 } 181 }
182 void clear_octal_position() { } // FIXME 182 void clear_octal_position() { } // FIXME
183 183
184 void SeekForward(int pos) { } // FIXME 184 // Seek forward to the given position. This operation works for simple cases
185 // such as seeking forward until simple delimiter tokens, which is what it is
186 // used for. After this call, we will have the token at the given position as
187 // the "next" token. The "current" token will be invalid. FIXME: for utf-8,
188 // we need to decide if pos is counted in characters or in bytes.
189 virtual void SeekForward(int pos) = 0;
185 190
186 // Scans the input as a regular expression pattern, previous 191 // Scans the input as a regular expression pattern, previous
187 // character(s) must be /(=). Returns true if a pattern is scanned. 192 // character(s) must be /(=). Returns true if a pattern is scanned.
188 virtual bool ScanRegExpPattern(bool seen_equal) = 0; 193 virtual bool ScanRegExpPattern(bool seen_equal) = 0;
189 // Returns true if regexp flags are scanned (always since flags can 194 // Returns true if regexp flags are scanned (always since flags can
190 // be empty). 195 // be empty).
191 virtual bool ScanRegExpFlags() = 0; 196 virtual bool ScanRegExpFlags() = 0;
192 197
193 protected: 198 protected:
194 struct TokenDesc { 199 struct TokenDesc {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 cursor_(NULL), 238 cursor_(NULL),
234 marker_(NULL) { 239 marker_(NULL) {
235 ASSERT(source->IsFlat()); 240 ASSERT(source->IsFlat());
236 SetBufferBasedOnHandle(); 241 SetBufferBasedOnHandle();
237 Scan(); 242 Scan();
238 } 243 }
239 244
240 virtual ~ExperimentalScanner() { } 245 virtual ~ExperimentalScanner() { }
241 246
242 virtual void Scan(); 247 virtual void Scan();
248 virtual void SeekForward(int pos);
243 virtual bool ScanRegExpPattern(bool seen_equal); 249 virtual bool ScanRegExpPattern(bool seen_equal);
244 virtual bool ScanRegExpFlags(); 250 virtual bool ScanRegExpFlags();
245 251
246 virtual void SetBufferBasedOnHandle() { 252 virtual void SetBufferBasedOnHandle() {
247 // We get a raw pointer from the Handle, but we also update it every time 253 // We get a raw pointer from the Handle, but we also update it every time
248 // there is a GC, so it is safe. 254 // there is a GC, so it is safe.
249 DisallowHeapAllocation no_gc; 255 DisallowHeapAllocation no_gc;
250 const Char* new_buffer = GetNewBufferBasedOnHandle(); 256 const Char* new_buffer = GetNewBufferBasedOnHandle();
251 if (new_buffer != buffer_) { 257 if (new_buffer != buffer_) {
252 int start_offset = start_ - buffer_; 258 int start_offset = start_ - buffer_;
(...skipping 24 matching lines...) Expand all
277 Handle<String> source_handle_; 283 Handle<String> source_handle_;
278 const Char* buffer_; 284 const Char* buffer_;
279 const Char* buffer_end_; 285 const Char* buffer_end_;
280 const Char* start_; 286 const Char* start_;
281 const Char* cursor_; 287 const Char* cursor_;
282 const Char* marker_; 288 const Char* marker_;
283 }; 289 };
284 290
285 291
286 template<typename Char> 292 template<typename Char>
293 void ExperimentalScanner<Char>::SeekForward(int pos) {
294 cursor_ = buffer_ + pos;
295 start_ = cursor_;
296 marker_ = cursor_;
297 Scan(); // Fills in next_.
298 }
299
300
301 template<typename Char>
287 bool ExperimentalScanner<Char>::ScanRegExpPattern(bool seen_equal) { 302 bool ExperimentalScanner<Char>::ScanRegExpPattern(bool seen_equal) {
288 // Scan: ('/' | '/=') RegularExpressionBody '/' RegularExpressionFlags 303 // Scan: ('/' | '/=') RegularExpressionBody '/' RegularExpressionFlags
289 bool in_character_class = false; 304 bool in_character_class = false;
290 305
291 // Previous token is either '/' or '/=', in the second case, the 306 // Previous token is either '/' or '/=', in the second case, the
292 // pattern starts at =. 307 // pattern starts at =.
293 next_.beg_pos = (cursor_ - buffer_) - (seen_equal ? 2 : 1); 308 next_.beg_pos = (cursor_ - buffer_) - (seen_equal ? 2 : 1);
294 next_.end_pos = (cursor_ - buffer_) - (seen_equal ? 1 : 0); 309 next_.end_pos = (cursor_ - buffer_) - (seen_equal ? 1 : 0);
295 310
296 // Scan regular expression body: According to ECMA-262, 3rd, 7.8.5, 311 // Scan regular expression body: According to ECMA-262, 3rd, 7.8.5,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 i++; 388 i++;
374 } 389 }
375 } 390 }
376 return i == 6; 391 return i == 6;
377 } 392 }
378 393
379 394
380 } } 395 } }
381 396
382 #endif // V8_LEXER_EXPERIMENTAL_SCANNER_H 397 #endif // V8_LEXER_EXPERIMENTAL_SCANNER_H
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698