Boost logo

Boost Users :

From: HartmutKaiser_at_[hidden]
Date: 2003-09-02 02:13:47


Larry Knain wrote:

> I inserted the code change you suggested and it picks up the
> 2 but there is no indication of the "missing" list element.
> I'll do some more reading and see what I can come up with.
> (I have a number of CSV files created by various spreadsheets
> and DB programs that I need to read that have "missing" list
> items and was trying for a more elegant solution in Spirit. I
> have done this with the tokenizer by keeping the delimiter tokens.)

Honestly, I've already thought, that you'll bring up this issue :-)
It's simply a matter of operator precedence in C++. If you write:

    list_csv =
            list_p(
                !list_csv_item[append(vec_item)],
                ','
            )[append(vec_list)]
        ;

you make the whole item construct optional:
!(list_csv_item[append(vec_item)]), i.e. the attached semantic action is
optional too and will be executed only, if/when the parser matches.
But if you'd write:

    list_csv =
            list_p(
                (!list_csv_item)[append(vec_item)],
                ','
            )[append(vec_list)]
        ;

(please note the additional parenthesis pair), you'd make optional the
parser part only. The action is executed always (even if the parser does
not match).

HTH
Regards Hartmut


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