diff options
author | swarmer <swarmer@yandex-team.com> | 2024-09-30 22:24:38 +0300 |
---|---|---|
committer | swarmer <swarmer@yandex-team.com> | 2024-09-30 22:35:54 +0300 |
commit | 803c95f77d7e098750be07c125e78f892ec7c169 (patch) | |
tree | d69fd2dbf013c998844350fc99b20929ab0ac9f2 /library/cpp/cppparser/parser.cpp | |
parent | a6718e3c426bdd6f17af1f4f68f5a6a9b13f47be (diff) | |
download | ydb-803c95f77d7e098750be07c125e78f892ec7c169.tar.gz |
enum_parser: support digit separators in numeric literals
commit_hash:9791d25e9ea02f73329f9755f7c70f335c612121
Diffstat (limited to 'library/cpp/cppparser/parser.cpp')
-rw-r--r-- | library/cpp/cppparser/parser.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/library/cpp/cppparser/parser.cpp b/library/cpp/cppparser/parser.cpp index 3bd968b459..70fb6a8735 100644 --- a/library/cpp/cppparser/parser.cpp +++ b/library/cpp/cppparser/parser.cpp @@ -1,4 +1,5 @@ #include <util/generic/hash.h> +#include <util/string/ascii.h> #include <util/string/cast.h> #include <util/generic/hash_set.h> #include <util/generic/yexception.h> @@ -127,6 +128,10 @@ private: break; case '\'': + if (QuoteCharIsADigitSeparator()) { + Text_.Data += ch; + break; + } Action(ch); State_ = Character; @@ -356,6 +361,35 @@ private: } } + // digit separator in integral literal (ex. 73'709'550'592) + bool QuoteCharIsADigitSeparator() const { + const TStringBuf data = Text_.Data; + if (data.empty()) { + return false; + } + if (!IsAsciiHex(data.back())) { + return false; + } + // check for char literal prefix (ex. `u8'$'`) + static constexpr TStringBuf literalPrefixes[] { + "u8", + "u", + "U", + "L", + }; + for (const TStringBuf& literalPrefix : literalPrefixes) { + if (TStringBuf prev; data.BeforeSuffix(literalPrefix, prev)) { + if (!prev.empty() && (IsAsciiAlnum(prev.back()) || prev.back() == '_' || prev.back() == '$')) { + // some macro name ends with an `u8` sequence + continue; + } + // it is a prefixed character literal + return false; + } + } + return true; + } + inline void Action(char ch) { Action(); Text_.Data += ch; |