File tree Expand file tree Collapse file tree 3 files changed +48
-3
lines changed Expand file tree Collapse file tree 3 files changed +48
-3
lines changed Original file line number Diff line number Diff line change @@ -251,7 +251,7 @@ using namespace cppast;
251251%type <str> optapidecor apidecor apidecortokensq
252252%type <str> identifier optidentifier numbertype typeidentifier varidentifier optname id name operfuncname funcname
253253%type <str> templidentifier templqualifiedid
254- %type <str> doccommentstr
254+ %type <str> doccommentstr optdoccommentstr
255255%type <str> rshift
256256%type <str> macrocall
257257%type <cppEntity> stmt
@@ -675,6 +675,11 @@ doccomment
675675 : doccommentstr [ZZLOG;] { $$ = new cppast::CppDocumentationComment((std::string) $1); }
676676 ;
677677
678+ optdoccommentstr
679+ : [ZZLOG;] { $$ = CppToken{nullptr, 0}; }
680+ | doccommentstr [ZZLOG;] { $$ = $1; }
681+ ;
682+
678683doccommentstr
679684 : tknFreeStandingBlockComment [ZZLOG;] { $$ = $1; }
680685 | tknFreeStandingLineComment [ZZLOG;] { $$ = $1; }
@@ -2068,8 +2073,9 @@ exprlist
20682073 $$ = new std::vector<std::unique_ptr<const cppast::CppExpression>>;
20692074 $$->emplace_back($1);
20702075 }
2071- | exprlist ',' expr %prec COMMA [ZZLOG;] { $1->emplace_back($3); $$ = $1; }
2072- | doccommentstr exprlist [ZZLOG;] { $$ = $2; }
2076+ | exprlist optdoccommentstr ',' optdoccommentstr expr %prec COMMA [ZZLOG;] { $1->emplace_back($5); $$ = $1; }
2077+ | doccommentstr exprlist [ZZLOG;] { $$ = $2; }
2078+ | exprlist doccommentstr [ZZLOG;] { $$ = $1; }
20732079 ;
20742080
20752081optexprlist
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ set(TEST_SNIPPET_EMBEDDED_TESTS
3737 ${CMAKE_CURRENT_LIST_DIR} /unit/disabled-code-test .cpp
3838 ${CMAKE_CURRENT_LIST_DIR} /unit/error-handler-test .cpp
3939 ${CMAKE_CURRENT_LIST_DIR} /unit/expr -test .cpp
40+ ${CMAKE_CURRENT_LIST_DIR} /unit/initializer-list-test .cpp
4041 ${CMAKE_CURRENT_LIST_DIR} /unit/namespace-test .cpp
4142 ${CMAKE_CURRENT_LIST_DIR} /unit/template-test .cpp
4243 ${CMAKE_CURRENT_LIST_DIR} /unit/uniform-init-test .cpp
Original file line number Diff line number Diff line change 1+ // Copyright (C) 2022 Satya Das and CppParser contributors
2+ // SPDX-License-Identifier: MIT
3+
4+ #include < catch/catch.hpp>
5+
6+ #include " cppparser/cppparser.h"
7+
8+ #include " embedded-snippet-test-base.h"
9+
10+ #include < string>
11+
12+ class InitializerListTest : public EmbeddedSnippetTestBase
13+ {
14+ protected:
15+ InitializerListTest ()
16+ : EmbeddedSnippetTestBase(__FILE__)
17+ {
18+ }
19+ };
20+
21+ TEST_CASE_METHOD (InitializerListTest, " docstr in middle" , " [initializerlist]" )
22+ {
23+ #if TEST_CASE_SNIPPET_STARTS_FROM_NEXT_LINE
24+ bool boolArray[] = {false ,
25+ // IGNORABLE COMMENTS HERE
26+ false };
27+ #endif
28+ auto testSnippet = getTestSnippetParseStream (__LINE__ - 2 );
29+
30+ cppparser::CppParser parser;
31+ const auto ast = parser.parseStream (testSnippet.data (), testSnippet.size ());
32+ REQUIRE (ast != nullptr );
33+
34+ const auto members = GetAllOwnedEntities (*ast);
35+ REQUIRE (members.size () == 1 );
36+ cppast::CppConstVarEPtr var = members[0 ];
37+ REQUIRE (var);
38+ }
You can’t perform that action at this time.
0 commit comments