Boost logo

Boost Users :

From: HartmutKaiser_at_[hidden]
Date: 2003-08-30 07:08:32


Larry Knain wrote:

> I should have said that this was a first attempt at using
> Spirit and I was just experimenting
> with some simple examples.
>
> There are three examples in the code. The adjustment was
> made to the second example which is for CSV. The string to
> be parsed was originally:
>
> char const *plist_csv = "\"string\",\"string with an embedded \\\"\","
> "12345,0.12345e4";
> Changed to:
>
> char const *plist_csv = "\"string\",\"string with an embedded \\\"\","
> "12345,0.12345e4,,2";
> These are at line 104.

If you look at the parser definition, you'll notice, that this
particular list parser is designed to parse escaped C-strings, integers
or reals separated by commas. I.e. no empty elements. If you would like
to make your list_p to match even empty elements, you'd have to make the
list_csv_item optional:

    list_csv =
            list_p(
                !list_csv_item[append(vec_item)],
    // ---------^ note this exclamation sign!
                ','
            )[append(vec_list)]
        ;

> The original parser line was:
>
> list_csv_item =
> confix_p('\"', *c_escape_ch_p, '\"')
> | longest_d[real_p | int_p]
> ;
> Again, I expected the null item to be omitted from my
> experience with the tokenizer code but
> I didn't expect the 2 to be omitted. After the initial
> failure I changed the line to:
>
> list_csv_item =
> confix_p('\"', *c_escape_ch_p, '\"')
> | longest_d[real_p | int_p|~anychar_p]
> ;
>
> It made no difference. Inserting \"\" between the two commas
> preceding the 2 did make it
> get the "null" token and the 2.

Adding the ~anything_p to the list_item parser isn't the correct thing.
This actually won't match any input at all.

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