Boost logo

Boost Users :

From: Eric Niebler (eric_at_[hidden])
Date: 2008-05-29 17:05:04


Christoph Duelli wrote:
> [I am using Boost 1.35, on Linux, running gcc 4.1.2]
>
> I want to parse a string like the following
> ---
> ResA { opt1=>val1, opt2 => val2}, ResB
> ResC {opt3=> valllll }
>
> ResD
> ---
>
> I thought that maybe it is easier to to this using xpressive rather than
> Spirit (which I have used for more complicated stuff so far).
>
> I am happy to say, that with the very helpful docs I was able to create a
> sregex that parses the above. Also, I found it the solution is quite short,
> so I am basically happy with xpressive.
>
> As this was my first try, there is certainly (lots of) room for improvement:
>
> I have attached my program, and would welcome comments (and suggestions for
> enhancements.)

<snip code>

Wow, for a first try, I'd say this is pretty darn good. You'll be
pleased to know that in the next version of xpressive, there will be a
skip() modifier which will eliminate all those nasty *_s from your
patterns. For instance, you'll be able to simply say skip(_s)(rx_res >>
*(',' >> rx_res)).

To improve runtime performance, you might consider replacing *_s with
keep(*_s), which will turn off the kleene star's backtracking behavior.
(Google "regex independent subexpression" to read about it.) That's
really the only suggestion I can make. The rest looks very nice.

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

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net