Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2007-11-24 14:21:27

(Currently I'm on vacation. Sorry for the delay.)

Jorge Lodos Vigil wrote:
> Hi
> We are using xpressive with a grammar to match certain patterns. In some cases, we have the need to ignore white spaces.
> Using dynamic regexes, this can be achieved with the ignore_white_space constant.
> Is there a way to ignore white spaces using a grammar in xpressive other than modifying the grammar itself?
> We know spirit is an option, but we need to evaluate parsing speed with as many methods as possible.
> Thanks in advance.

I see that Dave has offered a couple of creative solutions, but that
they interact badly with backtracking. What we really need is a
whitespace skipping directive. Neither dynamic nor static xpressive has
one. (The ignore_white_space option is like perl's /x option, and
certainly doesn't do what you want.)

The only thing I can think of off the top of my head is to do something
like the following:

BOOST_PROTO_AUTO( _ws, keep(*_w) );

... and then use _ws in your grammar wherever you want to ignore
whitespace, like:

   sregex rx = "some stuff" >> _ws >> "other stuff";

_ws will efficiently eat up the whitespace. Not ideal, but it works. If
you don't want to use BOOST_PROTO_AUTO, the following is equivalent:

   , boost::proto::dereference<
>::type const _ws = {{{{"w", false}}}};

Eric Niebler
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at