I am still new to Boost spirit.
I am trying to parse a string with possible lead and trailing whitespace and intermediate whitespace. I want to do the following with the string
- Remove any trailing and leading whitespace
- Limit the in-between word spaces to one whitespace
For example
"( my test1 ) (my test2)"
gets parsed as two terms -
"my test1"
"my test2"
I have used the following logic
using boost::spirit::qi;
struct Parser : grammar<Iterator, attribType(), space_type>
{
public:
Parser() : Parser::base_type(term)
{
group %= '(' >> (group | names) >> ')';
names %= no_skip[alnum][_val=_1];
}
private:
typedef boost::spirit::qi::rule<Iterator, attribType(), space_type> Rule;
Rule group;
Rule names
}
While it allows preserving the spaces in between. Unfortunately, it also keeps heading and trailing whitespace and multiple intermediate whitespace. I want to find a better logic for that.
I did see references to using a custom skipper with boost::spirit::qi::skip online, but I haven't come across a useful example for spaces. Does anyone else have experience with it?