spirit
Grammar Strategy
What constructs do we need to match, how well, and what can we ignore?
Fundamentally, we just need:
stuff
import module Blah;
export module Blah {
stuff
public:
stuff
private:
stuff
}
stuff
Where all the 'stuff' can be saved and manipulated in bulk.
The export keyword's used with templates as well, but that's it.
import's a new keyword.
so it really comes down to recognizing these constructs, and ignoring
everything else flat out, without screwing up the constructs we care about.
hmm...
import_stmt = ch_p(T_IMPORT) >> ch_p(T_MODULE) >> ch_p(T_IDENTIFIER);
export_block = ch_p(T_EXPORT) >> ch_p(T_MODULE) >> ch_p(T_IDENTIFIER)
Summary and Strategy
Requirements
My work this summer is implementing the 'modules' mentioned here:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1964.pdf
which are implemented using a syntax like:
// File_1.cpp:
export namespace Lib { // Module definition.
import namespace std;
public:
struct S {
S() { std::cout << “S()\n”; }
};
}
// File_2.cpp:
import namespace Lib;
int main() {
Lib::S s;
}
I'm using Boost.Spirit for this work. Spirit is a parsing framework in C++, using expression templates to define BNF-esque grammars inline. Its use requires that I do some C++ parsing, with no preexisting grammar to use as a starting point. I've committed to using Spirit to make a preprocessor that converts "Modular C++" to "C++", which will then be compilable with a stock compiler (I'm using G++).

