Boost logo

Boost :

From: David B. Held (dheld_at_[hidden])
Date: 2002-01-18 15:08:33

-----Original Message-----
From: rogeeff <rogeeff_at_[hidden]>
To: boost_at_[hidden] <boost_at_[hidden]>
Date: Friday, January 18, 2002 01:54 PM
Subject: [boost] Re: Any interest for a parser class?

>--- In boost_at_y..., "David B. Held" <dheld_at_c...> wrote:
>> >> rule<> option_name
>> >> = substrings_p(
>> >> "-roll",
>> >> "-help",
>> >> "-repeat_number"
>> >> )[ref(choice)];
>> >
>> >In many cases you have only ONE key per rule and won't be able
>> >combine them in one rule (i.e. each argument rule suold be added
>> >separetly)
>> I don't think you understand what this rule is saying. It's saying:
>> "Let's define all the option names, and then index them, putting
>> the current option index in the variable choice." This is
>> completely generic, and should work for any option style at
>> about the level of complexity you suggested.
>You may not have all the option names in one place and accordingly
>can't combine them in one rule. Given that futher implementation
>seems questionable.

What seems questionable is your reasoning. You are taking a
specific solution, and using it to argue against a general solution.
You specified a problem. I solved it. Joel refined it. Unless you
claim that your problem is representative of all CLA scenarios,
it is obviously unsound to use the *specific solution* to criticize
the general approach. And, of course, you could not claim that
anyway, since the objection you bring up isn't even relevant to
the problem you posed. Joel's solution is but one of many
possibilities using Spirit. He chose that one because it was
most parsimonious for the stated problem. Do not be deceived.
Spirit is more than capable of parsing options that become
known at runtime, at various places. To prove it, I'll illustrate
with a code snippet:

// options.def

// Code
ifstream config("options.def");
std::string my_option1;
config >> my_option1;
rule<> runtime_option1 = strlit(my_option1.c_str())[&my_action1];
config >> my_option2;
rule<> runtime_option2 = strlit(my_option2.c_str())[&my_action2];

rule<> cla = *(runtime_option1 | runtime_option2);

if (cla.parse(cmd_line.begin(), cmd_line.end())) {
    std::cout << "Success!";

Perhaps you'd like to demonstrate how this would be done
with a hand-rolled parser.


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