
Felipe Magno de Almeida wrote:
Hello,
When I have a grammar like this:
struct create_table_grammar : boost::proto::shift_left < boost::proto::shift_left < boost::proto::terminal<tags::create> , boost::proto::terminal<tags::table> > , boost::proto::terminal<const char*>
{};
And this expression:
create << table << "lala"; Where create and table are terminals with the respective tags.
I have this compile error: examples/test1.cpp: In function ‘int main()’: examples/test1.cpp:12: error: no match for ‘operator<<’ in ‘sql::keywords::create << sql::keywords::table’
Right, because the expression "create << table" doesn't match the grammar you've defined above.
If I don't inner expressions, then (create << table) works. But I can't define a more restricted grammar this way. I want create << table to work only when preceded with another specific expression. I wanted create << table to be enabled, but to disable everything else except (create << table) << "";
Is this possible?
Not directly. You will have to allow "create << table" in your grammar (possibly by not specifying any grammar when defining your domain, or else by specifying a loose one), and then define a /separate/ grammar that validates fully formed expressions for correctness. Presumably somewhere in your code there is a place where these expressions get evaluated. That's the place to ensure that "create << table" is always followed by a string literal. For that, you would use BOOST_MPL_ASSERT and proto::matches. HTH, -- Eric Niebler BoostPro Computing http://www.boostpro.com