|
Boost Users : |
From: Eric Niebler (eric_at_[hidden])
Date: 2007-10-31 12:40:40
Jacques-Olivier Goussard wrote:
> *Eric Niebler* wrote:
>>'ll second the suggestion to look into xpressive. With xpressive, you
>>can refer to one regex from another. And with the latest version (in the
>>Boost Sandbox) you can put your list of cities into a symbol table and
>>get very fast look-up -- much better than just a bunch of alternates.
>
> Ok, I've taken a look and that doesn't seem to be what I need afteral.
> The regexp used must use the Perl semantic and are only known at
> runtime, so I would go for what you call dynamic expressions, however
> I'm not sure I see
> how I can use your symbol table neat trick with those, unless they are
> disconnected. I.e. I can easily translate
> "in (CITY) on westbrook"
> into
> sregex leftre = 'in';
> sregex rightre = 'on westbrook';
> sregex re = leftre >> (city_map) >> rightre;
>
> but what to do with
> "in (CITY|heaven) on westbrook" ?
You're right, you can't /directly/ use symbol tables in dynamic regexes,
but you can embed a static regex into a dynamic one. See the section on
Dynamic Regex Grammars here: http://tinyurl.com/2nacj7.
In particular, you can:
sregex_compiler comp;
// static regex, creates a symbol table from city_map:
comp["CITY"] = (a1 = city_map);
// dynamic regex calls static regex
sregex re = comp.compile("in ((?$CITY)|heaven) on westbrook");
HTH,
-- 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