| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 complete_ = true; | 464 complete_ = true; |
| 465 } | 465 } |
| 466 | 466 |
| 467 private: | 467 private: |
| 468 JavaScriptScanner* scanner_; | 468 JavaScriptScanner* scanner_; |
| 469 bool complete_; | 469 bool complete_; |
| 470 }; | 470 }; |
| 471 | 471 |
| 472 explicit JavaScriptScanner(UnicodeCache* scanner_contants); | 472 explicit JavaScriptScanner(UnicodeCache* scanner_contants); |
| 473 | 473 |
| 474 void Initialize(UC16CharacterStream* source); |
| 475 |
| 474 // Returns the next token. | 476 // Returns the next token. |
| 475 Token::Value Next(); | 477 Token::Value Next(); |
| 476 | 478 |
| 477 // Returns true if there was a line terminator before the peek'ed token, | 479 // Returns true if there was a line terminator before the peek'ed token, |
| 478 // possibly inside a multi-line comment. | 480 // possibly inside a multi-line comment. |
| 479 bool HasAnyLineTerminatorBeforeNext() const { | 481 bool HasAnyLineTerminatorBeforeNext() const { |
| 480 return has_line_terminator_before_next_ || | 482 return has_line_terminator_before_next_ || |
| 481 has_multiline_comment_before_next_; | 483 has_multiline_comment_before_next_; |
| 482 } | 484 } |
| 483 | 485 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 // If the escape sequence cannot be decoded the result is kBadChar. | 530 // If the escape sequence cannot be decoded the result is kBadChar. |
| 529 uc32 ScanIdentifierUnicodeEscape(); | 531 uc32 ScanIdentifierUnicodeEscape(); |
| 530 | 532 |
| 531 // Start position of the octal literal last scanned. | 533 // Start position of the octal literal last scanned. |
| 532 Location octal_pos_; | 534 Location octal_pos_; |
| 533 | 535 |
| 534 // Whether there is a line terminator whitespace character after | 536 // Whether there is a line terminator whitespace character after |
| 535 // the current token, and before the next. Does not count newlines | 537 // the current token, and before the next. Does not count newlines |
| 536 // inside multiline comments. | 538 // inside multiline comments. |
| 537 bool has_line_terminator_before_next_; | 539 bool has_line_terminator_before_next_; |
| 538 // Whether there is a multi-line comment that containins a | 540 // Whether there is a multi-line comment that contains a |
| 539 // line-terminator after the current token, and before the next. | 541 // line-terminator after the current token, and before the next. |
| 540 bool has_multiline_comment_before_next_; | 542 bool has_multiline_comment_before_next_; |
| 541 }; | 543 }; |
| 542 | 544 |
| 543 | 545 |
| 544 // ---------------------------------------------------------------------------- | 546 // ---------------------------------------------------------------------------- |
| 545 // Keyword matching state machine. | 547 // Keyword matching state machine. |
| 546 | 548 |
| 547 class KeywordMatcher { | 549 class KeywordMatcher { |
| 548 // Incrementally recognize keywords. | 550 // Incrementally recognize keywords. |
| 549 // | 551 // |
| 550 // Recognized keywords: | 552 // Recognized as keywords: |
| 551 // break case catch const* continue debugger* default delete do else | 553 // break, case, catch, const*, continue, debugger, default, delete, do, |
| 552 // finally false for function if in instanceof native* new null | 554 // else, finally, false, for, function, if, in, instanceof, new, null, |
| 553 // return switch this throw true try typeof var void while with | 555 // return, switch, this, throw, true, try, typeof, var, void, while, with. |
| 554 // | 556 // |
| 555 // *: Actually "future reserved keywords". These are the only ones we | 557 // Recognized as Future Reserved Keywords (normal and strict mode): |
| 556 // recognize, the remaining are allowed as identifiers. | 558 // class, enum, export, extends, implements, import, interface, |
| 557 // In ES5 strict mode, we should disallow all reserved keywords. | 559 // let, package, private, private, protected, public, public, |
| 560 // static, yield. |
| 561 // |
| 562 // *: Actually a "future reserved keyword". It's the only one we are |
| 563 // recognizing outside of ES5 strict mode, the remaining are allowed |
| 564 // as identifiers. |
| 565 // |
| 558 public: | 566 public: |
| 559 KeywordMatcher() | 567 KeywordMatcher() |
| 560 : state_(INITIAL), | 568 : state_(INITIAL), |
| 561 token_(Token::IDENTIFIER), | 569 token_(Token::IDENTIFIER), |
| 562 keyword_(NULL), | 570 keyword_(NULL), |
| 563 counter_(0), | 571 counter_(0), |
| 564 keyword_token_(Token::ILLEGAL) {} | 572 keyword_token_(Token::ILLEGAL) {} |
| 565 | 573 |
| 566 Token::Value token() { return token_; } | 574 Token::Value token() { return token_; } |
| 567 | 575 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 // keyword with the current prefix). | 677 // keyword with the current prefix). |
| 670 const char* keyword_; | 678 const char* keyword_; |
| 671 int counter_; | 679 int counter_; |
| 672 Token::Value keyword_token_; | 680 Token::Value keyword_token_; |
| 673 }; | 681 }; |
| 674 | 682 |
| 675 | 683 |
| 676 } } // namespace v8::internal | 684 } } // namespace v8::internal |
| 677 | 685 |
| 678 #endif // V8_SCANNER_BASE_H_ | 686 #endif // V8_SCANNER_BASE_H_ |
| OLD | NEW |