splitted source (decl, def) gives compile errors byy use for test suite

Olaf Peter <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
Hello,

I run into a compiler error :

test/grammar_api.cpp: In function 'const string_literal_type& 
string_literal()':
test/grammar_api.cpp:1291:9: error: 'string_literal' is not a member of 
'parser'
   return parser::string_literal;
          ^~~~~~

using spirit x3 with these project organization:

* include/my/grammar.hpp:
----8<----
namespace parser {
         // Parser Rule IDs
         struct string_literal_class;
         ...
         // Parser Rule Types
         typedef x3::rule<string_literal_class> string_literal_type;
}
----8<----

* include/my/grammar_def.hpp:
----8<----
#include "my/grammar.hpp"
namespace parser {
         // Parser Declarations
         string_literal_type const string_literal { "string_literal" };
         // Parser Definition
         auto const string_literal_def =
         '"' > *graph > '"'
             ;
         // Definition
         BOOST_SPIRIT_DEFINE(string_literal)
}
----8<----

* include/my/config.hpp:
----8<----
namespace parser {
         typedef std::string::const_iterator iterator_type;
         typedef x3::unused_type context_type;
}
----8<----

* src/grammar.cpp:
----8<----
#include <eda/vhdl93/grammar_def.hpp>
#include <eda/vhdl93/parser_config.hpp>
namespace parser {
         BOOST_SPIRIT_INSTANTIATE(string_literal, iterator_type, 
context_type);
}
----8<----

* test/grammar_api.h:
----8<----
#include "my/grammar.hpp"
// Grammar Test Bench API Definition
namespace parser {
         BOOST_SPIRIT_DECLARE(string_literal_type);
}
parser::string_literal_type const& string_literal();
----8<----

* test/grammar_api.cpp
----8<----
// Grammar Test Bench API Definition
#include "grammar_api.hpp"
parser::string_literal_type const& string_literal() {
     return parser::string_literal;
}
----8<----

* test/main.cpp
----8<----
// using the string_literal() parser, not yet here
----8<----


The idea is not to expose all parsers into the client code, but make 
them exposed to the tests; inspired by test driven development.

How to organize it correct and avoid multiple instances? The grammar.hpp 
self is missing the top/entry rule, e.g. program, since I start with 
smaller production rules (bottom up design)

To fix the compiler error I have to include test/grammar_api.h in 
grammar_def.hpp. I guess these increases compile time later on and 
obviously shall be avoided.


Thanks,

Olaf



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.