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

Side by Side Diff: src/lexer/lexer.re

Issue 26971006: Fix fetching tokens in lexer. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years, 2 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
« 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 #include <fcntl.h> 1 #include <fcntl.h>
2 #include <stdio.h> 2 #include <stdio.h>
3 #include <stddef.h> 3 #include <stddef.h>
4 #include <stdlib.h> 4 #include <stdlib.h>
5 #include <string.h> 5 #include <string.h>
6 6
7 // TODO: 7 // TODO:
8 // - SpiderMonkey compatibility hack: " --> something" is treated 8 // - SpiderMonkey compatibility hack: " --> something" is treated
9 // as a single line comment. 9 // as a single line comment.
10 // - An identifier cannot start immediately after a number. 10 // - An identifier cannot start immediately after a number.
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 ExperimentalScanner::~ExperimentalScanner() { 336 ExperimentalScanner::~ExperimentalScanner() {
337 fclose(file_); 337 fclose(file_);
338 } 338 }
339 339
340 340
341 void ExperimentalScanner::FillTokens() { 341 void ExperimentalScanner::FillTokens() {
342 current_ = 0; 342 current_ = 0;
343 fetched_ = 0; 343 fetched_ = 0;
344 uint8_t chars[BUFFER_SIZE]; 344 uint8_t chars[BUFFER_SIZE];
345 int n = static_cast<int>(fread(&chars, 1, BUFFER_SIZE, file_)); 345 int n = static_cast<int>(fread(&chars, 1, BUFFER_SIZE, file_));
346 scanner_->push(chars, n); 346 for (int i = n; i < BUFFER_SIZE; i++) chars[i] = 0;
347 scanner_->push(chars, BUFFER_SIZE);
347 } 348 }
348 349
349 350
350 Token::Value ExperimentalScanner::Next(int* beg_pos, int* end_pos) { 351 Token::Value ExperimentalScanner::Next(int* beg_pos, int* end_pos) {
351 if (current_ == fetched_) { 352 while (current_ == fetched_) {
352 FillTokens(); 353 FillTokens();
353 } 354 }
354 *beg_pos = beg_[current_]; 355 *beg_pos = beg_[current_];
355 *end_pos = end_[current_]; 356 *end_pos = end_[current_];
356 Token::Value res = token_[current_]; 357 Token::Value res = token_[current_];
357 if (token_[current_] != Token::Token::EOS && 358 if (token_[current_] != Token::Token::EOS &&
358 token_[current_] != Token::ILLEGAL) { 359 token_[current_] != Token::ILLEGAL) {
359 current_++; 360 current_++;
360 } 361 }
361 return res; 362 return res;
362 } 363 }
363 364
364 365
365 void ExperimentalScanner::Record(Token::Value token, int beg, int end) { 366 void ExperimentalScanner::Record(Token::Value token, int beg, int end) {
366 if (token == Token::EOS) end--; 367 if (token == Token::EOS) end--;
367 token_[fetched_] = token; 368 token_[fetched_] = token;
368 beg_[fetched_] = beg; 369 beg_[fetched_] = beg;
369 end_[fetched_] = end; 370 end_[fetched_] = end;
370 fetched_++; 371 fetched_++;
371 } 372 }
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