Skip to content

Commit 9f44341

Browse files
authored
Handle non-ascii in comments (#8902)
1 parent fd7dfdf commit 9f44341

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

ydb/library/yql/sql/v1/proto_parser/proto_parser.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace NSQLTranslationV1 {
3232

3333
using namespace NSQLv1Generated;
3434

35-
void ValidateMessages(const google::protobuf::Message* msg1, const google::protobuf::Message* msg2, bool& hasNonAscii) {
35+
void ValidateMessagesImpl(const google::protobuf::Message* msg1, const google::protobuf::Message* msg2, bool hasNonAscii) {
3636
YQL_ENSURE(!msg1 == !msg2);
3737
if (!msg1) {
3838
return;
@@ -47,7 +47,6 @@ void ValidateMessages(const google::protobuf::Message* msg1, const google::proto
4747
const bool isEof2 = token2.GetId() == Max<ui32>();
4848
YQL_ENSURE(isEof1 == isEof2);
4949
YQL_ENSURE(token1.GetValue() == token2.GetValue());
50-
hasNonAscii = hasNonAscii || AnyOf(token1.GetValue(), [](char c) { return !isascii(c);});
5150
if (!isEof1) {
5251
YQL_ENSURE(token1.GetLine() == token2.GetLine());
5352
if (!hasNonAscii) {
@@ -66,12 +65,17 @@ void ValidateMessages(const google::protobuf::Message* msg1, const google::proto
6665
if (field1.IsMessage()) {
6766
YQL_ENSURE(field1.Size() == field2.Size());
6867
for (size_t j = 0; j < field1.Size(); ++j) {
69-
ValidateMessages(field1.template Get<NProtoBuf::Message>(j), field2.template Get<NProtoBuf::Message>(j), hasNonAscii);
68+
ValidateMessagesImpl(field1.template Get<NProtoBuf::Message>(j), field2.template Get<NProtoBuf::Message>(j), hasNonAscii);
7069
}
7170
}
7271
}
7372
}
7473

74+
void ValidateMessages(const TString& query, const google::protobuf::Message* msg1, const google::protobuf::Message* msg2) {
75+
const bool hasNonAscii = AnyOf(query, [](char c) { return !isascii(c);});
76+
return ValidateMessagesImpl(msg1, msg2, hasNonAscii);
77+
}
78+
7579
google::protobuf::Message* SqlAST(const TString& query, const TString& queryName, TIssues& err,
7680
size_t maxErrors, bool ansiLexer, bool anlr4Parser, bool testAntlr4, google::protobuf::Arena* arena) {
7781
YQL_ENSURE(arena);
@@ -85,8 +89,7 @@ google::protobuf::Message* SqlAST(const TString& query, const TString& queryName
8589
if (testAntlr4) {
8690
NProtoAST::TProtoASTBuilder<NALPAnsiAntlr4::SQLv1Antlr4Parser, NALPAnsiAntlr4::SQLv1Antlr4Lexer> builder(query, queryName, arena);
8791
auto res2 = builder.BuildAST(collector);
88-
bool hasNonAscii = false;
89-
ValidateMessages(res, res2, hasNonAscii);
92+
ValidateMessages(query, res, res2);
9093
}
9194

9295
return res;
@@ -96,8 +99,7 @@ google::protobuf::Message* SqlAST(const TString& query, const TString& queryName
9699
if (testAntlr4) {
97100
NProtoAST::TProtoASTBuilder<NALPDefaultAntlr4::SQLv1Antlr4Parser, NALPDefaultAntlr4::SQLv1Antlr4Lexer> builder(query, queryName, arena);
98101
auto res2 = builder.BuildAST(collector);
99-
bool hasNonAscii = false;
100-
ValidateMessages(res, res2, hasNonAscii);
102+
ValidateMessages(query, res, res2);
101103
}
102104

103105
return res;
@@ -122,8 +124,7 @@ google::protobuf::Message* SqlAST(const TString& query, const TString& queryName
122124
if (testAntlr4) {
123125
NProtoAST::TProtoASTBuilder<NALPAnsiAntlr4::SQLv1Antlr4Parser, NALPAnsiAntlr4::SQLv1Antlr4Lexer> builder(query, queryName, arena);
124126
auto res2 = builder.BuildAST(err);
125-
bool hasNonAscii = false;
126-
ValidateMessages(res, res2, hasNonAscii);
127+
ValidateMessages(query, res, res2);
127128
}
128129

129130
return res;
@@ -133,8 +134,7 @@ google::protobuf::Message* SqlAST(const TString& query, const TString& queryName
133134
if (testAntlr4) {
134135
NProtoAST::TProtoASTBuilder<NALPDefaultAntlr4::SQLv1Antlr4Parser, NALPDefaultAntlr4::SQLv1Antlr4Lexer> builder(query, queryName, arena);
135136
auto res2 = builder.BuildAST(err);
136-
bool hasNonAscii = false;
137-
ValidateMessages(res, res2, hasNonAscii);
137+
ValidateMessages(query, res, res2);
138138
}
139139

140140
return res;

0 commit comments

Comments
 (0)