aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/cppparser/parser.cpp
diff options
context:
space:
mode:
authorMaxim Yurchuk <maxim-yurchuk@ydb.tech>2024-10-02 18:18:52 +0300
committerGitHub <noreply@github.com>2024-10-02 18:18:52 +0300
commit8030e8b1331b42d4601ddb3375cdc13784afc05a (patch)
tree0c30a132afdea6b1a76eb292544f7031b32bda0c /library/cpp/cppparser/parser.cpp
parent98bb86a058838a0a9430703d9f87c6f925341ba8 (diff)
parent2975ad87b167ca40f48e84941ac1bbb79fb667e6 (diff)
downloadydb-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.cpp34
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;