Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2003-11-17 23:34:16

Darren Cook wrote:

>> Since ET's are native code, they can refer to other ET's (and
>> themselves!) in a natural way, so you can build recursive parsers out
>> of them.
> Can you show an example of how this would work? How is this different
> from using Spirit?

I imagine the usage will be very much like Spirit wrt defining recursive

// define a regex that matches balanced, nested parens
regex parens;
parens = '(' >> *( keep( +!chars["()"] ) | parens ) >> ')';

I just made that syntax up -- little of that is implemented yet. Here,
!chars["()"] is the equivalent of [^()] in perl, and keep(...) is the
same as (?>...).

The above also illustrates how xpressive will be different than Spirit.
By default, xpressive will do exhaustive backtracking, but it will
provide modifiers like keep() so you can control to what extent
backtracking happens. In this case, keep() turns off backtracking for a

Also, xpressive will allow dynamically- and statically-bound regexen to
play nice. Consider a text editor with a find/replace dialog and a
"whole word" option. You could mix and match static and dynamic as:

parser p;
regex rx;

rx = p.parse( get_string() ); // read regex from user
if( whole_word() ) // does the user want a whole word match?
    // build a new regex that is wrapped by
    // begin- and end-word assertions
    rx = word_begin >> as_xpr( rx ) >> word_end;

Something like as_xpr() would be needed to prevent this from defining a
recursive regex. That's not what we want here.

The other difference is that xpressive will use syntax and constructs
that are familiar to regex users. You will use Spirit when you need the
full expressive power of EBNF, or if you simply prefer EBNF.

I have high hopes that Joel and I will find a way to make xpressive and
Spirit play well together.

Eric Niebler
Boost Consulting

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