| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Features shared by parsing and pre-parsing scanners. | 5 // Features shared by parsing and pre-parsing scanners. |
| 6 | 6 |
| 7 #ifndef V8_PARSING_SCANNER_H_ | 7 #ifndef V8_PARSING_SCANNER_H_ |
| 8 #define V8_PARSING_SCANNER_H_ | 8 #define V8_PARSING_SCANNER_H_ |
| 9 | 9 |
| 10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 // Returns the next token and advances input. | 202 // Returns the next token and advances input. |
| 203 Token::Value Next(); | 203 Token::Value Next(); |
| 204 // Returns the token following peek() | 204 // Returns the token following peek() |
| 205 Token::Value PeekAhead(); | 205 Token::Value PeekAhead(); |
| 206 // Returns the current token again. | 206 // Returns the current token again. |
| 207 Token::Value current_token() { return current_.token; } | 207 Token::Value current_token() { return current_.token; } |
| 208 // Returns the location information for the current token | 208 // Returns the location information for the current token |
| 209 // (the token last returned by Next()). | 209 // (the token last returned by Next()). |
| 210 Location location() const { return current_.location; } | 210 Location location() const { return current_.location; } |
| 211 | 211 |
| 212 // This error is specifically an invalid hex or unicode escape sequence. |
| 212 bool has_error() const { return scanner_error_ != MessageTemplate::kNone; } | 213 bool has_error() const { return scanner_error_ != MessageTemplate::kNone; } |
| 213 MessageTemplate::Template error() const { return scanner_error_; } | 214 MessageTemplate::Template error() const { return scanner_error_; } |
| 214 Location error_location() const { return scanner_error_location_; } | 215 Location error_location() const { return scanner_error_location_; } |
| 215 | 216 |
| 217 bool has_invalid_template_escape() const { |
| 218 return invalid_template_escape_message_ != MessageTemplate::kNone; |
| 219 } |
| 220 MessageTemplate::Template invalid_template_escape_message() const { |
| 221 return invalid_template_escape_message_; |
| 222 } |
| 223 Location invalid_template_escape_location() const { |
| 224 return invalid_template_escape_location_; |
| 225 } |
| 226 |
| 227 void clear_invalid_template_escape() { |
| 228 DCHECK(has_invalid_template_escape()); |
| 229 invalid_template_escape_message_ = MessageTemplate::kNone; |
| 230 invalid_template_escape_location_ = Location::invalid(); |
| 231 } |
| 232 |
| 216 // Similar functions for the upcoming token. | 233 // Similar functions for the upcoming token. |
| 217 | 234 |
| 218 // One token look-ahead (past the token returned by Next()). | 235 // One token look-ahead (past the token returned by Next()). |
| 219 Token::Value peek() const { return next_.token; } | 236 Token::Value peek() const { return next_.token; } |
| 220 | 237 |
| 221 Location peek_location() const { return next_.location; } | 238 Location peek_location() const { return next_.location; } |
| 222 | 239 |
| 223 bool literal_contains_escapes() const { | 240 bool literal_contains_escapes() const { |
| 224 return LiteralContainsEscapes(current_); | 241 return LiteralContainsEscapes(current_); |
| 225 } | 242 } |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 current_.literal_chars = NULL; | 476 current_.literal_chars = NULL; |
| 460 current_.raw_literal_chars = NULL; | 477 current_.raw_literal_chars = NULL; |
| 461 next_.token = Token::UNINITIALIZED; | 478 next_.token = Token::UNINITIALIZED; |
| 462 next_.literal_chars = NULL; | 479 next_.literal_chars = NULL; |
| 463 next_.raw_literal_chars = NULL; | 480 next_.raw_literal_chars = NULL; |
| 464 next_next_.token = Token::UNINITIALIZED; | 481 next_next_.token = Token::UNINITIALIZED; |
| 465 next_next_.literal_chars = NULL; | 482 next_next_.literal_chars = NULL; |
| 466 next_next_.raw_literal_chars = NULL; | 483 next_next_.raw_literal_chars = NULL; |
| 467 found_html_comment_ = false; | 484 found_html_comment_ = false; |
| 468 scanner_error_ = MessageTemplate::kNone; | 485 scanner_error_ = MessageTemplate::kNone; |
| 486 invalid_template_escape_message_ = MessageTemplate::kNone; |
| 469 } | 487 } |
| 470 | 488 |
| 471 void ReportScannerError(const Location& location, | 489 void ReportScannerError(const Location& location, |
| 472 MessageTemplate::Template error) { | 490 MessageTemplate::Template error) { |
| 473 if (has_error()) return; | 491 if (has_error()) return; |
| 474 scanner_error_ = error; | 492 scanner_error_ = error; |
| 475 scanner_error_location_ = location; | 493 scanner_error_location_ = location; |
| 476 } | 494 } |
| 477 | 495 |
| 478 void ReportScannerError(int pos, MessageTemplate::Template error) { | 496 void ReportScannerError(int pos, MessageTemplate::Template error) { |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 // Whether there is a multi-line comment that contains a | 767 // Whether there is a multi-line comment that contains a |
| 750 // line-terminator after the current token, and before the next. | 768 // line-terminator after the current token, and before the next. |
| 751 bool has_multiline_comment_before_next_; | 769 bool has_multiline_comment_before_next_; |
| 752 bool has_line_terminator_after_next_; | 770 bool has_line_terminator_after_next_; |
| 753 | 771 |
| 754 // Whether this scanner encountered an HTML comment. | 772 // Whether this scanner encountered an HTML comment. |
| 755 bool found_html_comment_; | 773 bool found_html_comment_; |
| 756 | 774 |
| 757 MessageTemplate::Template scanner_error_; | 775 MessageTemplate::Template scanner_error_; |
| 758 Location scanner_error_location_; | 776 Location scanner_error_location_; |
| 777 |
| 778 MessageTemplate::Template invalid_template_escape_message_; |
| 779 Location invalid_template_escape_location_; |
| 759 }; | 780 }; |
| 760 | 781 |
| 761 } // namespace internal | 782 } // namespace internal |
| 762 } // namespace v8 | 783 } // namespace v8 |
| 763 | 784 |
| 764 #endif // V8_PARSING_SCANNER_H_ | 785 #endif // V8_PARSING_SCANNER_H_ |
| OLD | NEW |