Boost logo

Boost :

From: Hartmut Kaiser (hartmut.kaiser_at_[hidden])
Date: 2006-01-23 11:21:14


 
John Ky wrote:

> Is it possible to define a rule:
>
> rule<> mystringrule = confix_p('"', *c_escape_ch_p, '"')
>
> differently such that I can use
>
> std::string value;
>
> bool result = parse("\"hello world\"",
> mystringrule[assign_a(value)]).full;
>
> and get the text = "hello world" assigned to value?
>
> Currently, I get text = "\"hello world\"" instead. ie with
> double quotes at either end.

I'ld suggest to use closures for that (not tested):

    struct strlit_closure
    : public boost::spirit::closure<strlit_closure, std::string>
    {
        member1 val;
    };

    typedef rule<strlit_closure> rule_type;

    rule_type mystringrule
        = confix_p('"', *c_escape_ch_p[assign_a(mystringrule.val)], '"');

    bool result = parse("\"hello world\"",
        mystringrule[assign_a(value)]).full;

This is based on the fact, that the first closure member of a rule is used
as the rule's value.

HTH
Regards Hartmut


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