@@ -36,6 +36,7 @@ idl_info *search_namespace(idl_info& info, const std::string name_space);
36
36
void parse_thrift_type_name (const std::string& type_name,
37
37
std::string& type_prefix,
38
38
std::string& real_type_name);
39
+ std::vector<std::string> parse_thrift_variable (const std::string& str, char sep);
39
40
40
41
bool Parser::parse (const std::string& proto_file, idl_info& info)
41
42
{
@@ -108,7 +109,8 @@ bool Parser::parse(const std::string& proto_file, idl_info& info)
108
109
else if (this ->check_multi_comments_begin (line))
109
110
{
110
111
state = (state & PARSER_ST_OUTSIDE_COMMENT_MASK) + PARSER_ST_INSIDE_COMMENT;
111
- continue ;
112
+ if (line.empty ())
113
+ continue ;
112
114
}
113
115
114
116
if (this ->is_thrift == false )
@@ -743,14 +745,18 @@ bool Parser::parse_rpc_param_thrift(const std::string& file_name_prefix,
743
745
std::string idl_type;
744
746
if (left_b + 1 < str.size ())
745
747
{
746
- auto bb = SGenUtil::split_skip_string (str.substr (left_b + 1 ), ' ,' );
748
+ auto bb = parse_thrift_variable (str.substr (left_b + 1 ), ' ,' );
747
749
for (const auto & ele : bb)
748
750
{
749
- auto filedparam = SGenUtil::split_skip_string (ele, ' :' );
751
+ auto single_line = SGenUtil::split_skip_string (ele, ' \n ' );
752
+ if (single_line.size () != 1 )
753
+ continue ;
754
+
755
+ auto filedparam = SGenUtil::split_skip_string (single_line[0 ], ' :' );
750
756
if (filedparam.size () != 2 )
751
757
continue ;
752
758
753
- auto typevar = SGenUtil::split_skip_string (filedparam[1 ], ' ' );
759
+ auto typevar = parse_thrift_variable (filedparam[1 ], ' ' );
754
760
if (typevar.size () != 2 )
755
761
continue ;
756
762
@@ -777,6 +783,7 @@ bool Parser::parse_service_thrift(const std::string& file_name_prefix,
777
783
return false ;
778
784
779
785
std::string valid_block = block.substr (st + 1 , ed - st - 1 );
786
+
780
787
auto arr = split_thrift_rpc (valid_block);
781
788
782
789
for (const auto & ele : arr)
@@ -861,9 +868,25 @@ void Parser::check_single_comments(std::string& line)
861
868
size_t pos = line.find (" #" );
862
869
if (pos == std::string::npos)
863
870
pos = line.find (" //" );
864
-
865
871
if (pos != std::string::npos)
872
+ {
866
873
line.resize (pos);
874
+ return ;
875
+ }
876
+
877
+ if (pos == std::string::npos)
878
+ pos = line.find (" /*" );
879
+
880
+ size_t end;
881
+ while (pos != std::string::npos)
882
+ {
883
+ end = line.find (" */" , pos + 2 );
884
+ if (end == std::string::npos)
885
+ return ; // multi_comments can handle this, except for 'a/*\n'
886
+
887
+ line.erase (pos, end - pos + 2 );
888
+ pos = line.find (" /*" , pos);
889
+ }
867
890
}
868
891
869
892
bool Parser::parse_enum_thrift (const std::string& block, Descriptor& desc)
@@ -1321,3 +1344,51 @@ int Parser::find_valid(const std::string& line)
1321
1344
return 0 ;
1322
1345
}
1323
1346
1347
+ std::vector<std::string> parse_thrift_variable (const std::string& str, char sep)
1348
+ {
1349
+ std::vector<std::string> res;
1350
+ if (sep == ' \" ' )
1351
+ return res;
1352
+
1353
+ const char *cursor = str.c_str ();
1354
+ const char *start = cursor;
1355
+
1356
+ bool in_map = false ;
1357
+ std::string param;
1358
+
1359
+ while (*cursor)
1360
+ {
1361
+ if (*cursor == ' \" ' )
1362
+ {
1363
+ cursor = SGenUtil::skip_string (++cursor);
1364
+ if (!*cursor)
1365
+ break ;
1366
+ }
1367
+ else if (*cursor == sep)
1368
+ {
1369
+ param = std::string (start, cursor);
1370
+
1371
+ if (in_map == false &&
1372
+ param.find (" map" ) != std::string::npos &&
1373
+ param.find (" <" ) != std::string::npos)
1374
+ {
1375
+ in_map = true ;
1376
+ cursor++;
1377
+ continue ;
1378
+ }
1379
+
1380
+ if (start < cursor)
1381
+ res.emplace_back (param);
1382
+
1383
+ start = cursor + 1 ;
1384
+ in_map = false ;
1385
+ }
1386
+
1387
+ cursor++;
1388
+ }
1389
+
1390
+ if (start < cursor)
1391
+ res.emplace_back (start, cursor);
1392
+
1393
+ return res;
1394
+ }
0 commit comments