Boost logo

Boost :

From: David A. Greene (greened_at_[hidden])
Date: 2002-01-17 15:19:14


Douglas Gregor wrote:

> On Thursday 17 January 2002 02:00 pm, you wrote:
>>one of them should expose a (possibly limited) Spirit interface.
>
> I disagree strongly with this. Exposing Spirit in the interface forces the
> underlying implementation to use Spirit. Instead, I would strongly suggest
> defining a Parser concept that can facilitate any type of parser, so that
> Spirit and the CLA parser interfaces are decoupled. Perhaps the CLA interface
> would allow a custom parser to be added as such:
>
> template<typename Parser>
> void add_custom_parser(const Parser& parser);

You're right, I overstated things too much. What I was getting
at is the ability to customize the parser. The issue I see
with add_custom_parser is that we'd also want a way to allow
the custom parser to use bits of the standard parser to parse
the already-defined option syntax. Spirit allows a easy way
to take an existing parser and apply a "diff" to it to morph
it in various ways. That's why I mentioned Spirit above.

> The Parser concept could be (loosly) defined by one valid expression:
>
> parser(i, j): [i, j) is an input iterator sequence that is to be parsed by
> the parser. The return value could include the position at which parsing
> should resume to parse other arguments, and perhaps some value that describes
> the argument/value parsed in a manner that is common within the CLA parser.

If I understand you correctly, this model forces the programmer into
writing code like this:

// Pseudo-code
while ((arg = parser(i, j)) != PARSE_END) {
    // Do something with this argument
}

Other bits of discussion have focused on speparating syntax

analysis and semantic action. This model doesn't allow that
unless "Do something with this argument" builds an AST or
parse tree, which a parser should already do.

Perhaps there is room for both models. The first may be
more appropriate for simple utilities.

> It is very easy to add a Spirit rule as an argument parser:
>
> rule<> my_arg_parser;
> cla.add_custom_parser(
> boost::bind<R>(&rule<>::parse, &my_arg_parser, _1, _2));
>
> This does not prevent nor force the use of Spirit to implement the CLA parser.

Seems reasonable to me.

                            -Dave

-- 
"Some little people have music in them, but Fats, he was all music,
  and you know how big he was."  --  James P. Johnson

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