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