aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yson/token.cpp
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/yson/token.cpp
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/yson/token.cpp')
-rw-r--r--library/cpp/yson/token.cpp418
1 files changed, 209 insertions, 209 deletions
diff --git a/library/cpp/yson/token.cpp b/library/cpp/yson/token.cpp
index c8584c8c2e..13c6f170bb 100644
--- a/library/cpp/yson/token.cpp
+++ b/library/cpp/yson/token.cpp
@@ -4,233 +4,233 @@
#include <util/string/printf.h>
namespace NYson {
- ////////////////////////////////////////////////////////////////////////////////
-
- ETokenType CharToTokenType(char ch) {
- switch (ch) {
- case ';':
- return ETokenType::Semicolon;
- case '=':
- return ETokenType::Equals;
- case '{':
- return ETokenType::LeftBrace;
- case '}':
- return ETokenType::RightBrace;
- case '#':
- return ETokenType::Hash;
- case '[':
- return ETokenType::LeftBracket;
- case ']':
- return ETokenType::RightBracket;
- case '<':
- return ETokenType::LeftAngle;
- case '>':
- return ETokenType::RightAngle;
- case '(':
- return ETokenType::LeftParenthesis;
- case ')':
- return ETokenType::RightParenthesis;
- case '+':
- return ETokenType::Plus;
- case ':':
- return ETokenType::Colon;
- case ',':
- return ETokenType::Comma;
- default:
- return ETokenType::EndOfStream;
- }
- }
-
- char TokenTypeToChar(ETokenType type) {
- switch (type) {
- case ETokenType::Semicolon:
- return ';';
- case ETokenType::Equals:
- return '=';
- case ETokenType::Hash:
- return '#';
- case ETokenType::LeftBracket:
- return '[';
- case ETokenType::RightBracket:
- return ']';
- case ETokenType::LeftBrace:
- return '{';
- case ETokenType::RightBrace:
- return '}';
- case ETokenType::LeftAngle:
- return '<';
- case ETokenType::RightAngle:
- return '>';
- case ETokenType::LeftParenthesis:
- return '(';
- case ETokenType::RightParenthesis:
- return ')';
- case ETokenType::Plus:
- return '+';
- case ETokenType::Colon:
- return ':';
- case ETokenType::Comma:
- return ',';
- default:
- Y_FAIL("unreachable");
- }
- }
-
- TString TokenTypeToString(ETokenType type) {
+ ////////////////////////////////////////////////////////////////////////////////
+
+ ETokenType CharToTokenType(char ch) {
+ switch (ch) {
+ case ';':
+ return ETokenType::Semicolon;
+ case '=':
+ return ETokenType::Equals;
+ case '{':
+ return ETokenType::LeftBrace;
+ case '}':
+ return ETokenType::RightBrace;
+ case '#':
+ return ETokenType::Hash;
+ case '[':
+ return ETokenType::LeftBracket;
+ case ']':
+ return ETokenType::RightBracket;
+ case '<':
+ return ETokenType::LeftAngle;
+ case '>':
+ return ETokenType::RightAngle;
+ case '(':
+ return ETokenType::LeftParenthesis;
+ case ')':
+ return ETokenType::RightParenthesis;
+ case '+':
+ return ETokenType::Plus;
+ case ':':
+ return ETokenType::Colon;
+ case ',':
+ return ETokenType::Comma;
+ default:
+ return ETokenType::EndOfStream;
+ }
+ }
+
+ char TokenTypeToChar(ETokenType type) {
+ switch (type) {
+ case ETokenType::Semicolon:
+ return ';';
+ case ETokenType::Equals:
+ return '=';
+ case ETokenType::Hash:
+ return '#';
+ case ETokenType::LeftBracket:
+ return '[';
+ case ETokenType::RightBracket:
+ return ']';
+ case ETokenType::LeftBrace:
+ return '{';
+ case ETokenType::RightBrace:
+ return '}';
+ case ETokenType::LeftAngle:
+ return '<';
+ case ETokenType::RightAngle:
+ return '>';
+ case ETokenType::LeftParenthesis:
+ return '(';
+ case ETokenType::RightParenthesis:
+ return ')';
+ case ETokenType::Plus:
+ return '+';
+ case ETokenType::Colon:
+ return ':';
+ case ETokenType::Comma:
+ return ',';
+ default:
+ Y_FAIL("unreachable");
+ }
+ }
+
+ TString TokenTypeToString(ETokenType type) {
return TString(1, TokenTypeToChar(type));
}
- ////////////////////////////////////////////////////////////////////////////////
-
- const TToken TToken::EndOfStream;
-
- TToken::TToken()
- : Type_(ETokenType::EndOfStream)
- , Int64Value(0)
- , Uint64Value(0)
- , DoubleValue(0.0)
- , BooleanValue(false)
- {
- }
-
- TToken::TToken(ETokenType type)
- : Type_(type)
- , Int64Value(0)
- , Uint64Value(0)
- , DoubleValue(0.0)
- , BooleanValue(false)
- {
- switch (type) {
- case ETokenType::String:
- case ETokenType::Int64:
- case ETokenType::Uint64:
- case ETokenType::Double:
- case ETokenType::Boolean:
- Y_FAIL("unreachable");
- default:
- break;
- }
- }
-
- TToken::TToken(const TStringBuf& stringValue)
- : Type_(ETokenType::String)
- , StringValue(stringValue)
- , Int64Value(0)
- , Uint64Value(0)
- , DoubleValue(0.0)
- , BooleanValue(false)
- {
- }
-
- TToken::TToken(i64 int64Value)
- : Type_(ETokenType::Int64)
- , Int64Value(int64Value)
- , Uint64Value(0)
- , DoubleValue(0.0)
- {
- }
-
- TToken::TToken(ui64 uint64Value)
- : Type_(ETokenType::Uint64)
- , Int64Value(0)
- , Uint64Value(uint64Value)
- , DoubleValue(0.0)
- , BooleanValue(false)
- {
- }
-
- TToken::TToken(double doubleValue)
- : Type_(ETokenType::Double)
- , Int64Value(0)
- , Uint64Value(0)
- , DoubleValue(doubleValue)
- , BooleanValue(false)
- {
- }
-
- TToken::TToken(bool booleanValue)
- : Type_(ETokenType::Boolean)
- , Int64Value(0)
- , DoubleValue(0.0)
- , BooleanValue(booleanValue)
- {
- }
-
- bool TToken::IsEmpty() const {
- return Type_ == ETokenType::EndOfStream;
- }
-
- const TStringBuf& TToken::GetStringValue() const {
- CheckType(ETokenType::String);
- return StringValue;
- }
-
- i64 TToken::GetInt64Value() const {
- CheckType(ETokenType::Int64);
- return Int64Value;
- }
-
- ui64 TToken::GetUint64Value() const {
- CheckType(ETokenType::Uint64);
- return Uint64Value;
- }
-
- double TToken::GetDoubleValue() const {
- CheckType(ETokenType::Double);
- return DoubleValue;
- }
-
- bool TToken::GetBooleanValue() const {
- CheckType(ETokenType::Boolean);
- return BooleanValue;
- }
-
- void TToken::CheckType(ETokenType expectedType) const {
- if (Type_ != expectedType) {
- if (Type_ == ETokenType::EndOfStream) {
+ ////////////////////////////////////////////////////////////////////////////////
+
+ const TToken TToken::EndOfStream;
+
+ TToken::TToken()
+ : Type_(ETokenType::EndOfStream)
+ , Int64Value(0)
+ , Uint64Value(0)
+ , DoubleValue(0.0)
+ , BooleanValue(false)
+ {
+ }
+
+ TToken::TToken(ETokenType type)
+ : Type_(type)
+ , Int64Value(0)
+ , Uint64Value(0)
+ , DoubleValue(0.0)
+ , BooleanValue(false)
+ {
+ switch (type) {
+ case ETokenType::String:
+ case ETokenType::Int64:
+ case ETokenType::Uint64:
+ case ETokenType::Double:
+ case ETokenType::Boolean:
+ Y_FAIL("unreachable");
+ default:
+ break;
+ }
+ }
+
+ TToken::TToken(const TStringBuf& stringValue)
+ : Type_(ETokenType::String)
+ , StringValue(stringValue)
+ , Int64Value(0)
+ , Uint64Value(0)
+ , DoubleValue(0.0)
+ , BooleanValue(false)
+ {
+ }
+
+ TToken::TToken(i64 int64Value)
+ : Type_(ETokenType::Int64)
+ , Int64Value(int64Value)
+ , Uint64Value(0)
+ , DoubleValue(0.0)
+ {
+ }
+
+ TToken::TToken(ui64 uint64Value)
+ : Type_(ETokenType::Uint64)
+ , Int64Value(0)
+ , Uint64Value(uint64Value)
+ , DoubleValue(0.0)
+ , BooleanValue(false)
+ {
+ }
+
+ TToken::TToken(double doubleValue)
+ : Type_(ETokenType::Double)
+ , Int64Value(0)
+ , Uint64Value(0)
+ , DoubleValue(doubleValue)
+ , BooleanValue(false)
+ {
+ }
+
+ TToken::TToken(bool booleanValue)
+ : Type_(ETokenType::Boolean)
+ , Int64Value(0)
+ , DoubleValue(0.0)
+ , BooleanValue(booleanValue)
+ {
+ }
+
+ bool TToken::IsEmpty() const {
+ return Type_ == ETokenType::EndOfStream;
+ }
+
+ const TStringBuf& TToken::GetStringValue() const {
+ CheckType(ETokenType::String);
+ return StringValue;
+ }
+
+ i64 TToken::GetInt64Value() const {
+ CheckType(ETokenType::Int64);
+ return Int64Value;
+ }
+
+ ui64 TToken::GetUint64Value() const {
+ CheckType(ETokenType::Uint64);
+ return Uint64Value;
+ }
+
+ double TToken::GetDoubleValue() const {
+ CheckType(ETokenType::Double);
+ return DoubleValue;
+ }
+
+ bool TToken::GetBooleanValue() const {
+ CheckType(ETokenType::Boolean);
+ return BooleanValue;
+ }
+
+ void TToken::CheckType(ETokenType expectedType) const {
+ if (Type_ != expectedType) {
+ if (Type_ == ETokenType::EndOfStream) {
ythrow TYsonException() << "Unexpected end of stream (ExpectedType: " << TokenTypeToString(expectedType) << ")";
- } else {
+ } else {
ythrow TYsonException() << "Unexpected token (Token: '" << ToString(*this)
<< "', Type: " << TokenTypeToString(Type_)
<< ", ExpectedType: " << TokenTypeToString(expectedType) << ")";
- }
+ }
}
}
- void TToken::Reset() {
- Type_ = ETokenType::EndOfStream;
- Int64Value = 0;
- Uint64Value = 0;
- DoubleValue = 0.0;
- StringValue = TStringBuf();
- BooleanValue = false;
- }
+ void TToken::Reset() {
+ Type_ = ETokenType::EndOfStream;
+ Int64Value = 0;
+ Uint64Value = 0;
+ DoubleValue = 0.0;
+ StringValue = TStringBuf();
+ BooleanValue = false;
+ }
- TString ToString(const TToken& token) {
- switch (token.GetType()) {
- case ETokenType::EndOfStream:
- return TString();
+ TString ToString(const TToken& token) {
+ switch (token.GetType()) {
+ case ETokenType::EndOfStream:
+ return TString();
- case ETokenType::String:
- return TString(token.GetStringValue());
+ case ETokenType::String:
+ return TString(token.GetStringValue());
- case ETokenType::Int64:
- return ::ToString(token.GetInt64Value());
+ case ETokenType::Int64:
+ return ::ToString(token.GetInt64Value());
- case ETokenType::Uint64:
- return ::ToString(token.GetUint64Value());
+ case ETokenType::Uint64:
+ return ::ToString(token.GetUint64Value());
- case ETokenType::Double:
- return ::ToString(token.GetDoubleValue());
+ case ETokenType::Double:
+ return ::ToString(token.GetDoubleValue());
- case ETokenType::Boolean:
- return token.GetBooleanValue() ? "true" : "false";
+ case ETokenType::Boolean:
+ return token.GetBooleanValue() ? "true" : "false";
- default:
- return TokenTypeToString(token.GetType());
- }
+ default:
+ return TokenTypeToString(token.GetType());
+ }
}
- ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
} // namespace NYson