Boost logo

Boost :

Subject: [boost] Parsing commands with Spirit
From: edouard_at_[hidden]
Date: 2010-02-02 08:30:58

On Tue, 2 Feb 2010 07:13:27 -0600, "Hartmut Kaiser"
<hartmut.kaiser_at_[hidden]> wrote:

>> lit("command1") >> +char_[ref(my_str) = _1] >> lit("separator") >>
>> +char_[ref(my_str2) = _1] |
>> lit("command2) >> +alnum_[ref(my_str) = _1]
> typedef iterator_range<char const*> range_type;
> typedef std::pair<range_type, range_type> result_type;
> rule<char const*, result_type()> r =
> "command1" >> raw[+(!lit("separator") >> char_)] >> "separator"
> "command2" >> raw[+alnum];
> Does exactly as the above except it returns two pairs of pointers to the
> arguments of your commands. Just call it as:
> char const* begin = ...;
> char const* end = ...;
> result_type rt;
> parse(begin, end, r, rt);
> allowing you to access your pairs of pointers from rt.
> Voila! No memory allocation at all!

Awesome! Well now I *have to* test this. ;) - in the long run having a
real parser will do us good.

Then I have an additional question, if you mind, as I said the second
problem we have is that my command parameter may contain the separator, we
get around this by parsing right to left. This is not something we can do
much about it, unless we encode all the commands parameters which is a
thing we cannot realistically do.

Let me give you an example:


We currently extract "aaa/bbb/ccc" and "ddd".

The way I want to do this in Spirit is extract "aaa/bbb/ccc/ddd" and
manually extract "ddd" from it. The other possibility is to extract "aaa",
"bbb", "ccc" and "ddd" and since I have a pair of pointers just merge the
pair "aaa" => "ccc".

What would be a more sensible approach to this?

Thanks a lot.


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