antlr4: Tool package directive can't generate multi-level namespaces for C++

In C++, multi-level namespaces look like:

namespace foo {
namespace bar {
// code for namespace foo::bar goes here
}
}

Currently, Files.stg for C++ only supports a single level namespace:

https://github.com/antlr/antlr4/blob/master/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Files.stg#L50

Probably the right thing to do is to explicitly make file.genPackage an array and have the string templates iterate over each element to open / close the namespaces as appropriate for the language.

One question then is, what is the delimiter? Should we always require foo.bar.baz à la Java, or support foo::bar::baz as well?

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Comments: 15 (10 by maintainers)

Most upvoted comments

Hmm, no need for an array I think. The template can split and iterate also over a simple string (at least that’s what I remember). For the delimiter we can allow both, trying double colon first and then dot. (I wish C++ would allow for namespace foo::bar { ... }).