File tree Expand file tree Collapse file tree 3 files changed +51
-2
lines changed Expand file tree Collapse file tree 3 files changed +51
-2
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,7 @@ set(TEST_SNIPPET_EMBEDDED_TESTS
125125 ${CMAKE_CURRENT_LIST_DIR} /test /unit/expr -tests.cpp
126126 ${CMAKE_CURRENT_LIST_DIR} /test /unit/attribute-specifier-sequence.cpp
127127 ${CMAKE_CURRENT_LIST_DIR} /test /unit/error-handler-test .cpp
128+ ${CMAKE_CURRENT_LIST_DIR} /test /unit/namespace-test .cpp
128129)
129130
130131add_executable (cppparserunittest
Original file line number Diff line number Diff line change @@ -282,7 +282,7 @@ extern int yylex();
282282
283283%type <str> strlit
284284%type <str> optapidecor apidecor apidecortokensq
285- %type <str> identifier numbertype typeidentifier varidentifier optname id name operfuncname funcname
285+ %type <str> identifier optidentifier numbertype typeidentifier varidentifier optname id name operfuncname funcname
286286%type <str> templidentifier templqualifiedid
287287%type <str> doccommentstr
288288%type <str> rshift
@@ -727,6 +727,9 @@ id : tknID [ZZLOG; $$ = $1; ] {}
727727
728728optname : [ZZLOG ;] { $$ = makeCppToken(nullptr, nullptr); }
729729 | name [ZZLOG;] { $$ = $1; }
730+
731+ optidentifier : [ZZLOG ;] { $$ = makeCppToken(nullptr, nullptr); }
732+ | identifier [ZZLOG;] { $$ = $1; }
730733 ;
731734
732735enumitem : name [ZZLOG ;] { $$ = new CppEnumItem($1); }
@@ -1652,7 +1655,7 @@ classdefn : classspecifier optapidecor optattribspecifiers identifier op
16521655 }
16531656 ;
16541657
1655- namespacedefn : tknNamespace optname ' {'
1658+ namespacedefn : tknNamespace optidentifier ' {'
16561659 [
16571660 ZZVALID ;
16581661 gCompoundStack.push(classNameFromIdentifier($2));
Original file line number Diff line number Diff line change 1+ #include < catch/catch.hpp>
2+
3+ #include " cppparser.h"
4+
5+ #include " embedded-snippet-test-base.h"
6+
7+ class NamespaceTest : public EmbeddedSnippetTestBase
8+ {
9+ protected:
10+ NamespaceTest ()
11+ : EmbeddedSnippetTestBase(__FILE__)
12+ {
13+ }
14+ };
15+
16+ #if TEST_CASE_SNIPPET_STARTS_FROM_NEXT_LINE
17+ # if __cplusplus > 201703L
18+ namespace my ::ns1 {
19+ auto p = new char *[5 ];
20+ }
21+ # endif
22+ #endif
23+
24+ TEST_CASE_METHOD (NamespaceTest, " C++17 style nested namespace" )
25+ {
26+ auto testSnippet = getTestSnippetParseStream (__LINE__ - 5 );
27+
28+ CppParser parser;
29+ const auto ast = parser.parseStream (testSnippet.data (), testSnippet.size ());
30+ REQUIRE (ast != nullptr );
31+
32+ const auto & members = ast->members ();
33+ REQUIRE (members.size () == 3 );
34+
35+ CppCompoundEPtr ns = members[1 ];
36+ REQUIRE (ns);
37+ CHECK (ns->name () == " my::ns1" );
38+ const auto & nsMembers = ns->members ();
39+ REQUIRE (nsMembers.size () == 1 );
40+
41+ CppVarEPtr var = nsMembers[0 ];
42+ REQUIRE (var);
43+
44+ CHECK (var->assignValue () != nullptr );
45+ }
You can’t perform that action at this time.
0 commit comments