[Boost][spirit] Confused about spaces!
Hello. I'm trying to implement a very basic parser but I'm stuck at
the beginning of it.
The parser will be fed with input from a very basic minilanguage to
execute tests.
I want that the first line begins literally like this:
begin TestActions
But with my current implementation I can't:
template <class FwdIterator>
struct TestFileParser : qi::grammar
On 6/4/2011 12:32 AM, Germán Diago wrote:
Hello. I'm trying to implement a very basic parser but I'm stuck at the beginning of it.
The parser will be fed with input from a very basic minilanguage to execute tests.
I want that the first line begins literally like this:
begin TestActions
But with my current implementation I can't:
template <class FwdIterator> struct TestFileParser : qi::grammar
{ TestFileParser() : TestFileParser::base_type(start_) { using namespace boost::spirit::qi;
start_ = lit("begin") >> lit("TestActions");
}
qi::rule
start_; }; Because this implementation matches "beginTestActions" as well. And I want them to be different words. If I put a space between them, my rule complains because its attribute must be a Test(). And if I put in the middel a ' ' it doesn't work anymore. What's wrong with spaces? I'm using phrase_parse with qi::ascii::space skipper. Thanks in advance.
Use a lexeme and a predicate. Here's an example: lexeme[lit("begin") >> !alnum] // make sure we have whole words >> lit("TestActions"); The expression: >> !alnum makes sure that begin is not immediately followed by alnum. Being a predicate (using !), its attribute is ignored by the attribute mechanism. HTH. Regards, -- Joel de Guzman http://www.boostpro.com http://boost-spirit.com
participants (2)
-
Germán Diago
-
Joel de Guzman