aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/cppparser/parser.cpp
diff options
context:
space:
mode:
authorAlexander Smirnov <alex@ydb.tech>2024-10-02 11:40:21 +0000
committerAlexander Smirnov <alex@ydb.tech>2024-10-02 11:40:21 +0000
commit4a43f3fbfda5a2eee2af081bd76ae023afd481db (patch)
treeae27208d4452705b2c0ec19efdcd8132c8e8de20 /library/cpp/cppparser/parser.cpp
parent2a5dadb53a806ed944a3a3e1dfcaef886838360d (diff)
parent2084bac66bb1c8d3013d8ef6c61867726c4188e2 (diff)
downloadydb-4a43f3fbfda5a2eee2af081bd76ae023afd481db.tar.gz
Merge branch 'rightlib' into mergelibs-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 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;