diff options
author | deep <[email protected]> | 2024-04-29 14:32:21 +0300 |
---|---|---|
committer | deep <[email protected]> | 2024-04-29 14:40:28 +0300 |
commit | 0b92aadeaf8c1fe98b8b8018a6b956f385d40bb9 (patch) | |
tree | a3cff2663e5c35073aae86aa663a4e7cdb476334 | |
parent | f22ed1308cbbc92cd2049f1f8e0828ae23017f5b (diff) |
YTORM-1042 TProtoVisitor
Новый, кленовый, универсальный обходчик протобуферов. И демонстрационный перевод на него удалятеля полей, который теперь может отрабатывать звёздочки.
4125fab031e612f65a3f4d80448686bbd54e8640
-rw-r--r-- | yt/yt/core/ypath/stack.cpp | 7 | ||||
-rw-r--r-- | yt/yt/core/ypath/stack.h | 2 | ||||
-rw-r--r-- | yt/yt/core/ypath/tokenizer.cpp | 26 | ||||
-rw-r--r-- | yt/yt/core/ypath/tokenizer.h | 21 |
4 files changed, 55 insertions, 1 deletions
diff --git a/yt/yt/core/ypath/stack.cpp b/yt/yt/core/ypath/stack.cpp index c236d47d208..a590402fb10 100644 --- a/yt/yt/core/ypath/stack.cpp +++ b/yt/yt/core/ypath/stack.cpp @@ -86,6 +86,13 @@ TString TYPathStack::ToString(const TYPathStack::TEntry& item) }); } +void TYPathStack::Reset() +{ + PreviousPathLengths_.clear(); + Path_.clear(); + Items_.clear(); +} + //////////////////////////////////////////////////////////////////////////////// } // namespace NYT::NYPath diff --git a/yt/yt/core/ypath/stack.h b/yt/yt/core/ypath/stack.h index e7b8bfa8780..e5b40f2be7c 100644 --- a/yt/yt/core/ypath/stack.h +++ b/yt/yt/core/ypath/stack.h @@ -29,6 +29,8 @@ public: TString GetHumanReadablePath() const; std::optional<TString> TryGetStringifiedLastPathToken() const; + void Reset(); + private: std::vector<size_t> PreviousPathLengths_; TString Path_; diff --git a/yt/yt/core/ypath/tokenizer.cpp b/yt/yt/core/ypath/tokenizer.cpp index 45fa0f40208..6079747cfb0 100644 --- a/yt/yt/core/ypath/tokenizer.cpp +++ b/yt/yt/core/ypath/tokenizer.cpp @@ -211,6 +211,11 @@ ETokenType TTokenizer::GetType() const return Type_; } +ETokenType TTokenizer::GetPreviousType() const +{ + return PreviousType_; +} + TStringBuf TTokenizer::GetToken() const { return Token_; @@ -248,6 +253,27 @@ const TString& TTokenizer::GetLiteralValue() const //////////////////////////////////////////////////////////////////////////////// +TTokenizer::TCheckpoint::TCheckpoint(TTokenizer& tokenizer) + : Tokenizer_(tokenizer) + , Path_(tokenizer.Path_) + , Type_(tokenizer.Type_) + , PreviousType_(tokenizer.PreviousType_) + , Token_(tokenizer.Token_) + , Input_(tokenizer.Input_) +{ } + +TTokenizer::TCheckpoint::~TCheckpoint() +{ + Tokenizer_.Path_ = Path_; + Tokenizer_.Type_ = Type_; + Tokenizer_.PreviousType_ = PreviousType_; + Tokenizer_.Token_ = Token_; + Tokenizer_.Input_ = Input_; + Tokenizer_.LiteralValue_.clear(); +} + +//////////////////////////////////////////////////////////////////////////////// + bool HasPrefix(const TYPath& fullPath, const TYPath& prefixPath) { TTokenizer fullTokenizer(fullPath); diff --git a/yt/yt/core/ypath/tokenizer.h b/yt/yt/core/ypath/tokenizer.h index 46cf2a058d2..57b714a5801 100644 --- a/yt/yt/core/ypath/tokenizer.h +++ b/yt/yt/core/ypath/tokenizer.h @@ -22,6 +22,7 @@ public: ETokenType Advance(); ETokenType GetType() const; + ETokenType GetPreviousType() const; TStringBuf GetToken() const; TStringBuf GetPrefix() const; TStringBuf GetPrefixPlusToken() const; @@ -35,9 +36,27 @@ public: bool Skip(ETokenType expectedType); [[noreturn]] void ThrowUnexpected() const; + // For iterations. Restores tokenizer to current state on destruction. + // Does not restore LiteralValue_. + class TCheckpoint + { + public: + explicit TCheckpoint(TTokenizer& tokenizer); + ~TCheckpoint(); + + private: + TTokenizer& Tokenizer_; + TYPathBuf Path_; + ETokenType Type_; + ETokenType PreviousType_; + TStringBuf Token_; + TStringBuf Input_; + }; + private: - TYPathBuf Path_; + friend class TTokenizer::TCheckpoint; + TYPathBuf Path_; ETokenType Type_; ETokenType PreviousType_; TStringBuf Token_; |