| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // ---------------------------------------------------------------------------- | 73 // ---------------------------------------------------------------------------- |
| 74 // JavaScriptScanner | 74 // JavaScriptScanner |
| 75 | 75 |
| 76 JavaScriptScanner::JavaScriptScanner(UnicodeCache* scanner_contants) | 76 JavaScriptScanner::JavaScriptScanner(UnicodeCache* scanner_contants) |
| 77 : Scanner(scanner_contants), octal_pos_(Location::invalid()) { } | 77 : Scanner(scanner_contants), octal_pos_(Location::invalid()) { } |
| 78 | 78 |
| 79 | 79 |
| 80 Token::Value JavaScriptScanner::Next() { | 80 Token::Value JavaScriptScanner::Next() { |
| 81 current_ = next_; | 81 current_ = next_; |
| 82 has_line_terminator_before_next_ = false; | 82 has_line_terminator_before_next_ = false; |
| 83 has_multiline_comment_before_next_ = false; |
| 83 Scan(); | 84 Scan(); |
| 84 return current_.token; | 85 return current_.token; |
| 85 } | 86 } |
| 86 | 87 |
| 87 | 88 |
| 88 static inline bool IsByteOrderMark(uc32 c) { | 89 static inline bool IsByteOrderMark(uc32 c) { |
| 89 // The Unicode value U+FFFE is guaranteed never to be assigned as a | 90 // The Unicode value U+FFFE is guaranteed never to be assigned as a |
| 90 // Unicode character; this implies that in a Unicode context the | 91 // Unicode character; this implies that in a Unicode context the |
| 91 // 0xFF, 0xFE byte pattern can only be interpreted as the U+FEFF | 92 // 0xFF, 0xFE byte pattern can only be interpreted as the U+FEFF |
| 92 // character expressed in little-endian byte order (since it could | 93 // character expressed in little-endian byte order (since it could |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 Token::Value JavaScriptScanner::SkipMultiLineComment() { | 157 Token::Value JavaScriptScanner::SkipMultiLineComment() { |
| 157 ASSERT(c0_ == '*'); | 158 ASSERT(c0_ == '*'); |
| 158 Advance(); | 159 Advance(); |
| 159 | 160 |
| 160 while (c0_ >= 0) { | 161 while (c0_ >= 0) { |
| 161 char ch = c0_; | 162 char ch = c0_; |
| 162 Advance(); | 163 Advance(); |
| 163 if (unicode_cache_->IsLineTerminator(ch)) { | 164 if (unicode_cache_->IsLineTerminator(ch)) { |
| 164 // Following ECMA-262, section 7.4, a comment containing | 165 // Following ECMA-262, section 7.4, a comment containing |
| 165 // a newline will make the comment count as a line-terminator. | 166 // a newline will make the comment count as a line-terminator. |
| 166 has_line_terminator_before_next_ = true; | 167 has_multiline_comment_before_next_ = true; |
| 167 } | 168 } |
| 168 // If we have reached the end of the multi-line comment, we | 169 // If we have reached the end of the multi-line comment, we |
| 169 // consume the '/' and insert a whitespace. This way all | 170 // consume the '/' and insert a whitespace. This way all |
| 170 // multi-line comments are treated as whitespace. | 171 // multi-line comments are treated as whitespace. |
| 171 if (ch == '*' && c0_ == '/') { | 172 if (ch == '*' && c0_ == '/') { |
| 172 c0_ = ' '; | 173 c0_ = ' '; |
| 173 return Token::WHITESPACE; | 174 return Token::WHITESPACE; |
| 174 } | 175 } |
| 175 } | 176 } |
| 176 | 177 |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 ASSERT_EQ(next_.location.end_pos, current_pos); | 443 ASSERT_EQ(next_.location.end_pos, current_pos); |
| 443 // Positions inside the lookahead token aren't supported. | 444 // Positions inside the lookahead token aren't supported. |
| 444 ASSERT(pos >= current_pos); | 445 ASSERT(pos >= current_pos); |
| 445 if (pos != current_pos) { | 446 if (pos != current_pos) { |
| 446 source_->SeekForward(pos - source_->pos()); | 447 source_->SeekForward(pos - source_->pos()); |
| 447 Advance(); | 448 Advance(); |
| 448 // This function is only called to seek to the location | 449 // This function is only called to seek to the location |
| 449 // of the end of a function (at the "}" token). It doesn't matter | 450 // of the end of a function (at the "}" token). It doesn't matter |
| 450 // whether there was a line terminator in the part we skip. | 451 // whether there was a line terminator in the part we skip. |
| 451 has_line_terminator_before_next_ = false; | 452 has_line_terminator_before_next_ = false; |
| 453 has_multiline_comment_before_next_ = false; |
| 452 } | 454 } |
| 453 Scan(); | 455 Scan(); |
| 454 } | 456 } |
| 455 | 457 |
| 456 | 458 |
| 457 void JavaScriptScanner::ScanEscape() { | 459 void JavaScriptScanner::ScanEscape() { |
| 458 uc32 c = c0_; | 460 uc32 c = c0_; |
| 459 Advance(); | 461 Advance(); |
| 460 | 462 |
| 461 // Skip escaped newlines. | 463 // Skip escaped newlines. |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 if (MatchKeywordStart(input, "with", 1, Token::WITH)) return; | 945 if (MatchKeywordStart(input, "with", 1, Token::WITH)) return; |
| 944 break; | 946 break; |
| 945 case UNMATCHABLE: | 947 case UNMATCHABLE: |
| 946 break; | 948 break; |
| 947 } | 949 } |
| 948 // On fallthrough, it's a failure. | 950 // On fallthrough, it's a failure. |
| 949 state_ = UNMATCHABLE; | 951 state_ = UNMATCHABLE; |
| 950 } | 952 } |
| 951 | 953 |
| 952 } } // namespace v8::internal | 954 } } // namespace v8::internal |
| OLD | NEW |