Skip to content

Commit

Permalink
Merge pull request #1541 from pragmaware/improve-namespace-parsing-2
Browse files Browse the repository at this point in the history
CXX: Improve namespace parsing
  • Loading branch information
pragmaware committed Aug 31, 2017
2 parents 075e56d + 695d5c2 commit afcba95
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*.od
*.pdf
*.ssexwsp
*.ssexwsp.user
*.TMP
*.tmp
*~
Expand Down
5 changes: 4 additions & 1 deletion Units/parser-cxx.r/namespace.cpp.d/expected.tags
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ d4 input.cpp /^ inline namespace d3::d4 {$/;" n namespace:d1::d2::d3 file: end:4
d1_d2_d3_d4_f input.cpp /^ void d1_d2_d3_d4_f() { }$/;" f namespace:d1::d2::d3::d4 typeref:typename:void end:44
e1 input.cpp /^namespace e1 = a1::a2::a3;$/;" A file: name:a1::a2::a3
e2 input.cpp /^namespace e2 = b1::b2 __attribute__((abi_tag("blah")));$/;" A file: name:b1::b2
z1 input.cpp /^namespace z1 { };$/;" n file: end:52
f1 input.cpp /^namespace f1 _SOME_MACRO(default)$/;" n file: end:54
f2 input.cpp /^namespace f2::f3 _SOME_MACRO("blah","foo")$/;" n file: end:58
f3 input.cpp /^namespace f2::f3 _SOME_MACRO("blah","foo")$/;" n namespace:f2 file: end:58
z1 input.cpp /^namespace z1 { };$/;" n file: end:60
9 changes: 8 additions & 1 deletion Units/parser-cxx.r/namespace.cpp.d/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ namespace e1 = a1::a2::a3;

namespace e2 = b1::b2 __attribute__((abi_tag("blah")));

namespace z1 { };
namespace f1 _SOME_MACRO(default)
{
}

namespace f2::f3 _SOME_MACRO("blah","foo")
{
}

namespace z1 { };


24 changes: 19 additions & 5 deletions parsers/cxx/cxx_parser_namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,9 @@ bool cxxParserParseNamespace(void)
if(!cxxTokenTypeIs(g_cxx.pToken,CXXTokenTypeOpeningBracket))
{
// tolerate syntax error
CXX_DEBUG_LEAVE_TEXT("Found semicolon just after namespace declaration");
CXX_DEBUG_LEAVE_TEXT("Found semicolon/EOF just after namespace declaration");
return true;
}

CXX_DEBUG_LEAVE_TEXT("Was expecting an opening bracket here");
// FIXME: Maybe we could attempt to recover here?
return true;
}
break;
case CXXTokenTypeOpeningBracket:
Expand All @@ -202,6 +198,24 @@ bool cxxParserParseNamespace(void)
CXX_DEBUG_LEAVE_TEXT("Found semicolon just after namespace declaration");
return true;
break;
case CXXTokenTypeIdentifier:
// Probably some kind of macro
if(!cxxParserParseUpToOneOf(
CXXTokenTypeOpeningBracket | CXXTokenTypeSemicolon | CXXTokenTypeEOF,
false
))
{
CXX_DEBUG_LEAVE_TEXT("Failed to parse up to an opening bracket");
return false;
}

if(!cxxTokenTypeIs(g_cxx.pToken,CXXTokenTypeOpeningBracket))
{
// tolerate syntax error
CXX_DEBUG_LEAVE_TEXT("Found semicolon/EOF just after namespace declaration");
return true;
}
break;
default:
CXX_DEBUG_LEAVE_TEXT("Some kind of syntax error here");
return cxxParserSkipToSemicolonOrEOF();
Expand Down

0 comments on commit afcba95

Please sign in to comment.