Index: src/scanner.h |
diff --git a/src/scanner.h b/src/scanner.h |
index 5162fbec12d0bfec37a7c8847e7a6400b84b58c0..4e1dbac91f3af6f4833ae2089f7aa25d83cfc9eb 100644 |
--- a/src/scanner.h |
+++ b/src/scanner.h |
@@ -89,6 +89,10 @@ class Utf16CharacterStream { |
// Must not be used right after calling SeekForward. |
virtual void PushBack(int32_t code_unit) = 0; |
+ virtual bool SetBookmark(); |
+ virtual bool CanResetToBookmark(); |
+ virtual bool ResetToBookmark(); |
+ |
protected: |
static const uc32 kEndOfInput = -1; |
@@ -268,6 +272,17 @@ class LiteralBuffer { |
Handle<String> Internalize(Isolate* isolate) const; |
+ void CopyFrom(const LiteralBuffer* other) { |
+ if (other == nullptr) { |
+ Reset(); |
+ } else { |
+ is_one_byte_ = other->is_one_byte_; |
+ position_ = other->position_; |
+ backing_store_.Dispose(); |
+ backing_store_ = other->backing_store_.Clone(); |
+ } |
+ } |
+ |
private: |
static const int kInitialCapacity = 16; |
static const int kGrowthFactory = 4; |
@@ -342,6 +357,24 @@ class Scanner { |
bool complete_; |
}; |
+ // Scoped helper for a re-settable bookmark. |
+ class BookmarkScope { |
+ public: |
+ explicit BookmarkScope(Scanner* scanner) : scanner_(scanner) { |
+ DCHECK_NOT_NULL(scanner_); |
+ } |
+ ~BookmarkScope() { scanner_->DropBookmark(); } |
+ |
+ bool Set() { return scanner_->SetBookmark(); } |
+ bool Reset() { return scanner_->ResetToBookmark(); } |
+ bool CanReset() { return scanner_->CanResetBookmark(); } |
+ bool HasBeenSet() { return scanner_->BookmarkHasBeenSet(); } |
+ bool HasBeenReset() { return scanner_->BookmarkHasBeenReset(); } |
+ |
+ private: |
+ Scanner* scanner_; |
+ }; |
+ |
// Representation of an interval of source positions. |
struct Location { |
Location(int b, int e) : beg_pos(b), end_pos(e) { } |
@@ -509,6 +542,14 @@ class Scanner { |
current_.raw_literal_chars = NULL; |
} |
+ // Support BookmarkScope functionality. |
+ bool SetBookmark(); |
+ bool ResetToBookmark(); |
+ bool CanResetBookmark(); |
+ bool BookmarkHasBeenSet(); |
+ bool BookmarkHasBeenReset(); |
+ void DropBookmark(); |
+ |
// Literal buffer support |
inline void StartLiteral() { |
LiteralBuffer* free_buffer = (current_.literal_chars == &literal_buffer1_) ? |
@@ -711,6 +752,18 @@ class Scanner { |
TokenDesc current_; // desc for current token (as returned by Next()) |
TokenDesc next_; // desc for next token (one token look-ahead) |
+ // Variables for Scanner::BookmarkScope and the *Bookmark implementation. |
+ // These variables contain the scanner state when a bookmark is set. |
+ // We will use bookmark_c0_ as a 'control' variable, where: |
+ // - bookmark_c0_ >= 0: A bookmark has been set and this contains c0_. |
+ // - bookmark_c0_ == -1: No bookmark has been set. |
+ // - bookmark_c0_ == -2: The bookmark has been applied (ResetToBookmark). |
+ TokenDesc bookmark_current_; |
+ TokenDesc bookmark_next_; |
+ uc32 bookmark_c0_; |
+ LiteralBuffer bookmark_literal_; |
+ LiteralBuffer bookmark_raw_literal_; |
marja
2015/04/22 16:40:56
Hmm, why can't we just retroactively recover all t
vogelheim
2015/04/22 17:08:35
Yeah... I went a bit trial-and-error here and didn
|
+ |
// Input stream. Must be initialized to an Utf16CharacterStream. |
Utf16CharacterStream* source_; |