| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 void Scanner::LiteralScope::Complete() { | 315 void Scanner::LiteralScope::Complete() { |
| 316 scanner_->TerminateLiteral(); | 316 scanner_->TerminateLiteral(); |
| 317 complete_ = true; | 317 complete_ = true; |
| 318 } | 318 } |
| 319 | 319 |
| 320 | 320 |
| 321 // ---------------------------------------------------------------------------- | 321 // ---------------------------------------------------------------------------- |
| 322 // V8JavaScriptScanner | 322 // V8JavaScriptScanner |
| 323 | 323 |
| 324 | 324 |
| 325 void V8JavaScriptScanner::Initialize(UC16CharacterStream* source, | 325 void V8JavaScriptScanner::Initialize(UC16CharacterStream* source) { |
| 326 int literal_flags) { | |
| 327 source_ = source; | 326 source_ = source; |
| 328 literal_flags_ = literal_flags | kLiteralIdentifier; | |
| 329 // Need to capture identifiers in order to recognize "get" and "set" | 327 // Need to capture identifiers in order to recognize "get" and "set" |
| 330 // in object literals. | 328 // in object literals. |
| 331 Init(); | 329 Init(); |
| 332 // Skip initial whitespace allowing HTML comment ends just like | 330 // Skip initial whitespace allowing HTML comment ends just like |
| 333 // after a newline and scan first token. | 331 // after a newline and scan first token. |
| 334 has_line_terminator_before_next_ = true; | 332 has_line_terminator_before_next_ = true; |
| 335 SkipWhiteSpace(); | 333 SkipWhiteSpace(); |
| 336 Scan(); | 334 Scan(); |
| 337 } | 335 } |
| 338 | 336 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 368 int start_position = source_pos(); | 366 int start_position = source_pos(); |
| 369 // JSON WhiteSpace is tab, carrige-return, newline and space. | 367 // JSON WhiteSpace is tab, carrige-return, newline and space. |
| 370 while (c0_ == ' ' || c0_ == '\n' || c0_ == '\r' || c0_ == '\t') { | 368 while (c0_ == ' ' || c0_ == '\n' || c0_ == '\r' || c0_ == '\t') { |
| 371 Advance(); | 369 Advance(); |
| 372 } | 370 } |
| 373 return source_pos() != start_position; | 371 return source_pos() != start_position; |
| 374 } | 372 } |
| 375 | 373 |
| 376 | 374 |
| 377 void JsonScanner::ScanJson() { | 375 void JsonScanner::ScanJson() { |
| 378 next_.literal_chars = Vector<const char>(); | 376 next_.literal_chars = NULL; |
| 379 Token::Value token; | 377 Token::Value token; |
| 380 do { | 378 do { |
| 381 // Remember the position of the next token | 379 // Remember the position of the next token |
| 382 next_.location.beg_pos = source_pos(); | 380 next_.location.beg_pos = source_pos(); |
| 383 switch (c0_) { | 381 switch (c0_) { |
| 384 case '\t': | 382 case '\t': |
| 385 case '\r': | 383 case '\r': |
| 386 case '\n': | 384 case '\n': |
| 387 case ' ': | 385 case ' ': |
| 388 Advance(); | 386 Advance(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 | 448 |
| 451 next_.location.end_pos = source_pos(); | 449 next_.location.end_pos = source_pos(); |
| 452 next_.token = token; | 450 next_.token = token; |
| 453 } | 451 } |
| 454 | 452 |
| 455 | 453 |
| 456 Token::Value JsonScanner::ScanJsonString() { | 454 Token::Value JsonScanner::ScanJsonString() { |
| 457 ASSERT_EQ('"', c0_); | 455 ASSERT_EQ('"', c0_); |
| 458 Advance(); | 456 Advance(); |
| 459 LiteralScope literal(this); | 457 LiteralScope literal(this); |
| 460 while (c0_ != '"' && c0_ > 0) { | 458 while (c0_ != '"') { |
| 461 // Check for control character (0x00-0x1f) or unterminated string (<0). | 459 // Check for control character (0x00-0x1f) or unterminated string (<0). |
| 462 if (c0_ < 0x20) return Token::ILLEGAL; | 460 if (c0_ < 0x20) return Token::ILLEGAL; |
| 463 if (c0_ != '\\') { | 461 if (c0_ != '\\') { |
| 464 AddLiteralCharAdvance(); | 462 AddLiteralCharAdvance(); |
| 465 } else { | 463 } else { |
| 466 Advance(); | 464 Advance(); |
| 467 switch (c0_) { | 465 switch (c0_) { |
| 468 case '"': | 466 case '"': |
| 469 case '\\': | 467 case '\\': |
| 470 case '/': | 468 case '/': |
| (...skipping 26 matching lines...) Expand all Loading... |
| 497 } | 495 } |
| 498 AddLiteralChar(value); | 496 AddLiteralChar(value); |
| 499 break; | 497 break; |
| 500 } | 498 } |
| 501 default: | 499 default: |
| 502 return Token::ILLEGAL; | 500 return Token::ILLEGAL; |
| 503 } | 501 } |
| 504 Advance(); | 502 Advance(); |
| 505 } | 503 } |
| 506 } | 504 } |
| 507 if (c0_ != '"') { | |
| 508 return Token::ILLEGAL; | |
| 509 } | |
| 510 literal.Complete(); | 505 literal.Complete(); |
| 511 Advance(); | 506 Advance(); |
| 512 return Token::STRING; | 507 return Token::STRING; |
| 513 } | 508 } |
| 514 | 509 |
| 515 | 510 |
| 516 Token::Value JsonScanner::ScanJsonNumber() { | 511 Token::Value JsonScanner::ScanJsonNumber() { |
| 517 LiteralScope literal(this); | 512 LiteralScope literal(this); |
| 518 if (c0_ == '-') AddLiteralCharAdvance(); | 513 if (c0_ == '-') AddLiteralCharAdvance(); |
| 519 if (c0_ == '0') { | 514 if (c0_ == '0') { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 Advance(); | 550 Advance(); |
| 556 text++; | 551 text++; |
| 557 } | 552 } |
| 558 if (scanner_constants_->IsIdentifierPart(c0_)) return Token::ILLEGAL; | 553 if (scanner_constants_->IsIdentifierPart(c0_)) return Token::ILLEGAL; |
| 559 literal.Complete(); | 554 literal.Complete(); |
| 560 return token; | 555 return token; |
| 561 } | 556 } |
| 562 | 557 |
| 563 | 558 |
| 564 } } // namespace v8::internal | 559 } } // namespace v8::internal |
| OLD | NEW |