diff options
author | Maxim Yurchuk <maxim-yurchuk@ydb.tech> | 2024-10-02 18:18:52 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-02 18:18:52 +0300 |
commit | 8030e8b1331b42d4601ddb3375cdc13784afc05a (patch) | |
tree | 0c30a132afdea6b1a76eb292544f7031b32bda0c /library/cpp/cppparser/parser.cpp | |
parent | 98bb86a058838a0a9430703d9f87c6f925341ba8 (diff) | |
parent | 2975ad87b167ca40f48e84941ac1bbb79fb667e6 (diff) | |
download | ydb-8030e8b1331b42d4601ddb3375cdc13784afc05a.tar.gz |
Merge pull request #9972 from ydb-platform/mergelibs-241002-1139
Library import 241002-1139
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 3bd968b4594..70fb6a87356 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; |