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::unary_expr<
     boost::xpressive::detail::keeper_tag
   , boost::proto::dereference<
         boost::proto::terminal<
             boost::xpressive::detail::posix_charset_placeholder
>::type
>::type
>::type const _ws = {{{{"w", false}}}};

-- 
Eric Niebler
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk