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: src/lexer/lexer.re

Issue 43883003: Experimental scanner: HTML comments. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years, 1 month 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 | « src/lexer/lexer.h ('k') | 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 // Portions of this code based on re2c: 1 // Portions of this code based on re2c:
2 // (re2c/examples/push.re) 2 // (re2c/examples/push.re)
3 // Copyright 2013 the V8 project authors. All rights reserved. 3 // Copyright 2013 the V8 project authors. All rights reserved.
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "parser.h" 49 #include "parser.h"
50 #include "platform.h" 50 #include "platform.h"
51 #include "preparser.h" 51 #include "preparser.h"
52 #include "runtime.h" 52 #include "runtime.h"
53 #include "scanner-character-streams.h" 53 #include "scanner-character-streams.h"
54 #include "scopeinfo.h" 54 #include "scopeinfo.h"
55 #include "string-stream.h" 55 #include "string-stream.h"
56 56
57 57
58 // TODO: 58 // TODO:
59 // - SpiderMonkey compatibility hack: " --> something" is treated
60 // as a single line comment.
61 // - Run-time lexing modifications: harmony number literals, keywords depending 59 // - Run-time lexing modifications: harmony number literals, keywords depending
62 // on harmony_modules, harmony_scoping 60 // on harmony_modules, harmony_scoping
63 // - Escaping the string literals (like the baseline does) 61 // - Escaping the string literals (like the baseline does)
64 // - Error recovery after illegal tokens. 62 // - Error recovery after illegal tokens.
65 63
66 enum Condition { 64 enum Condition {
67 kConditionNormal, 65 kConditionNormal,
68 kConditionDoubleQuoteString, 66 kConditionDoubleQuoteString,
69 kConditionSingleQuoteString, 67 kConditionSingleQuoteString,
70 kConditionIdentifier, 68 kConditionIdentifier,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 c = (c | 0x20) - ('a' - '0'); // detect 0x11..0x16 and 0x31..0x36. 106 c = (c | 0x20) - ('a' - '0'); // detect 0x11..0x16 and 0x31..0x36.
109 if (static_cast<unsigned>(c) <= 5) return c + 10; 107 if (static_cast<unsigned>(c) <= 5) return c + 10;
110 return -1; 108 return -1;
111 } 109 }
112 110
113 } 111 }
114 112
115 #define PUSH_TOKEN(T) { send(T); SKIP(); } 113 #define PUSH_TOKEN(T) { send(T); SKIP(); }
116 #define PUSH_TOKEN_LOOKAHEAD(T) { --cursor_; send(T); SKIP(); } 114 #define PUSH_TOKEN_LOOKAHEAD(T) { --cursor_; send(T); SKIP(); }
117 #define PUSH_EOF_AND_RETURN() { send(Token::EOS); eof_ = true; return 1;} 115 #define PUSH_EOF_AND_RETURN() { send(Token::EOS); eof_ = true; return 1;}
118 #define PUSH_LINE_TERMINATOR() { SKIP(); } 116 #define PUSH_LINE_TERMINATOR() { just_seen_line_terminator_ = true; SKIP(); }
119 #define TERMINATE_ILLEGAL() { send(Token::ILLEGAL); send(Token::EOS); return 1; } 117 #define TERMINATE_ILLEGAL() { send(Token::ILLEGAL); send(Token::EOS); return 1; }
120 118
121 #define YYCTYPE uint8_t 119 #define YYCTYPE uint8_t
122 120
123 PushScanner::PushScanner(ExperimentalScanner* sink, UnicodeCache* unicode_cache) 121 PushScanner::PushScanner(ExperimentalScanner* sink, UnicodeCache* unicode_cache)
124 : unicode_cache_(unicode_cache), 122 : unicode_cache_(unicode_cache),
125 eof_(false), 123 eof_(false),
126 state_(-1), 124 state_(-1),
127 condition_(kConditionNormal), 125 condition_(kConditionNormal),
128 limit_(NULL), 126 limit_(NULL),
129 start_(NULL), 127 start_(NULL),
130 cursor_(NULL), 128 cursor_(NULL),
131 marker_(NULL), 129 marker_(NULL),
132 real_start_(0), 130 real_start_(0),
133 buffer_(NULL), 131 buffer_(NULL),
134 buffer_end_(NULL), 132 buffer_end_(NULL),
135 yych(0), 133 yych(0),
136 yyaccept(0), 134 yyaccept(0),
135 just_seen_line_terminator_(true),
137 sink_(sink) { 136 sink_(sink) {
138 137
139 } 138 }
140 139
141 PushScanner::~PushScanner() { 140 PushScanner::~PushScanner() {
142 } 141 }
143 142
144 143
145 uc32 PushScanner::ScanHexNumber(int length) { 144 uc32 PushScanner::ScanHexNumber(int length) {
146 // We have seen \uXXXX, let's see what it is. 145 // We have seen \uXXXX, let's see what it is.
(...skipping 20 matching lines...) Expand all
167 } 166 }
168 167
169 void PushScanner::send(Token::Value token) { 168 void PushScanner::send(Token::Value token) {
170 int beg = (start_ - buffer_) + real_start_; 169 int beg = (start_ - buffer_) + real_start_;
171 int end = (cursor_ - buffer_) + real_start_; 170 int end = (cursor_ - buffer_) + real_start_;
172 if (FLAG_trace_lexer) { 171 if (FLAG_trace_lexer) {
173 printf("got %s at (%d, %d): ", Token::Name(token), beg, end); 172 printf("got %s at (%d, %d): ", Token::Name(token), beg, end);
174 for (uint8_t* s = start_; s != cursor_; s++) printf("%c", (char)*s); 173 for (uint8_t* s = start_; s != cursor_; s++) printf("%c", (char)*s);
175 printf(".\n"); 174 printf(".\n");
176 } 175 }
176 just_seen_line_terminator_ = false;
177 sink_->Record(token, beg, end); 177 sink_->Record(token, beg, end);
178 } 178 }
179 179
180 uint32_t PushScanner::push(const void *input, int input_size) { 180 uint32_t PushScanner::push(const void *input, int input_size) {
181 if (FLAG_trace_lexer) { 181 if (FLAG_trace_lexer) {
182 printf( 182 printf(
183 "scanner is receiving a new data batch of length %d\n" 183 "scanner is receiving a new data batch of length %d\n"
184 "scanner continues with saved state_ = %d\n", 184 "scanner continues with saved state_ = %d\n",
185 input_size, 185 input_size,
186 state_); 186 state_);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 <Normal> "%=" { PUSH_TOKEN(Token::ASSIGN_MOD); } 324 <Normal> "%=" { PUSH_TOKEN(Token::ASSIGN_MOD); }
325 325
326 <Normal> "===" { PUSH_TOKEN(Token::EQ_STRICT); } 326 <Normal> "===" { PUSH_TOKEN(Token::EQ_STRICT); }
327 <Normal> "==" { PUSH_TOKEN(Token::EQ); } 327 <Normal> "==" { PUSH_TOKEN(Token::EQ); }
328 <Normal> "=" { PUSH_TOKEN(Token::ASSIGN); } 328 <Normal> "=" { PUSH_TOKEN(Token::ASSIGN); }
329 <Normal> "!==" { PUSH_TOKEN(Token::NE_STRICT); } 329 <Normal> "!==" { PUSH_TOKEN(Token::NE_STRICT); }
330 <Normal> "!=" { PUSH_TOKEN(Token::NE); } 330 <Normal> "!=" { PUSH_TOKEN(Token::NE); }
331 <Normal> "!" { PUSH_TOKEN(Token::NOT); } 331 <Normal> "!" { PUSH_TOKEN(Token::NOT); }
332 332
333 <Normal> "//" :=> SingleLineComment 333 <Normal> "//" :=> SingleLineComment
334 <Normal> whitespace? "-->" { if (just_seen_line_terminator_) { YYSETCONDITIO N(kConditionSingleLineComment); goto yy0; } else { --cursor_; send(Token::DEC); start_ = cursor_; goto yy0; } }
334 <Normal> "/*" :=> MultiLineComment 335 <Normal> "/*" :=> MultiLineComment
335 <Normal> "<!--" :=> HtmlComment 336 <Normal> "<!--" :=> HtmlComment
336 337
337 <Normal> ">>>=" { PUSH_TOKEN(Token::ASSIGN_SHR); } 338 <Normal> ">>>=" { PUSH_TOKEN(Token::ASSIGN_SHR); }
338 <Normal> ">>>" { PUSH_TOKEN(Token::SHR); } 339 <Normal> ">>>" { PUSH_TOKEN(Token::SHR); }
339 <Normal> "<<=" { PUSH_TOKEN(Token::ASSIGN_SHL); } 340 <Normal> "<<=" { PUSH_TOKEN(Token::ASSIGN_SHL); }
340 <Normal> ">>=" { PUSH_TOKEN(Token::ASSIGN_SAR); } 341 <Normal> ">>=" { PUSH_TOKEN(Token::ASSIGN_SAR); }
341 <Normal> "<=" { PUSH_TOKEN(Token::LTE); } 342 <Normal> "<=" { PUSH_TOKEN(Token::LTE); }
342 <Normal> ">=" { PUSH_TOKEN(Token::GTE); } 343 <Normal> ">=" { PUSH_TOKEN(Token::GTE); }
343 <Normal> "<<" { PUSH_TOKEN(Token::SHL); } 344 <Normal> "<<" { PUSH_TOKEN(Token::SHL); }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 <SingleLineComment> line_terminator { PUSH_LINE_TERMINATOR();} 426 <SingleLineComment> line_terminator { PUSH_LINE_TERMINATOR();}
426 <SingleLineComment> eof { PUSH_TOKEN(Token::EOS); } 427 <SingleLineComment> eof { PUSH_TOKEN(Token::EOS); }
427 <SingleLineComment> any { goto yy0; } 428 <SingleLineComment> any { goto yy0; }
428 429
429 <MultiLineComment> [*][//] { PUSH_LINE_TERMINATOR();} 430 <MultiLineComment> [*][//] { PUSH_LINE_TERMINATOR();}
430 <MultiLineComment> eof { TERMINATE_ILLEGAL(); } 431 <MultiLineComment> eof { TERMINATE_ILLEGAL(); }
431 <MultiLineComment> any { goto yy0; } 432 <MultiLineComment> any { goto yy0; }
432 433
433 <HtmlComment> eof { TERMINATE_ILLEGAL(); } 434 <HtmlComment> eof { TERMINATE_ILLEGAL(); }
434 <HtmlComment> "-->" { PUSH_LINE_TERMINATOR();} 435 <HtmlComment> "-->" { PUSH_LINE_TERMINATOR();}
436 <HtmlComment> line_terminator+ { PUSH_LINE_TERMINATOR();}
435 <HtmlComment> any { goto yy0; } 437 <HtmlComment> any { goto yy0; }
436 */ 438 */
437 439
438 fill: 440 fill:
439 int unfinished_size = cursor_ - start_; 441 int unfinished_size = cursor_ - start_;
440 if (FLAG_trace_lexer) { 442 if (FLAG_trace_lexer) {
441 printf( 443 printf(
442 "scanner needs a refill. Exiting for now with:\n" 444 "scanner needs a refill. Exiting for now with:\n"
443 " saved fill state_ = %d\n" 445 " saved fill state_ = %d\n"
444 " unfinished token size = %d\n", 446 " unfinished token size = %d\n",
(...skipping 16 matching lines...) Expand all
461 size_t start_offset = start_ - buffer_; 463 size_t start_offset = start_ - buffer_;
462 memmove(buffer_, start_, limit_ - start_); 464 memmove(buffer_, start_, limit_ - start_);
463 marker_ -= start_offset; 465 marker_ -= start_offset;
464 cursor_ -= start_offset; 466 cursor_ -= start_offset;
465 limit_ -= start_offset; 467 limit_ -= start_offset;
466 start_ -= start_offset; 468 start_ -= start_offset;
467 real_start_ += start_offset; 469 real_start_ += start_offset;
468 } 470 }
469 return 0; 471 return 0;
470 } 472 }
OLDNEW
« no previous file with comments | « src/lexer/lexer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698