Boost logo

Boost :

From: Joel de Guzman (joel_at_[hidden])
Date: 2003-11-05 18:37:55

Brian McNamara <lorgon_at_[hidden]> wrote:

>> Parser-decorators, for example, can call that function anytime post-parse.
>> For instance, closures set the match's value post-parse:
>> template <typename ResultT, typename ParserT, typename ScannerT>
>> ResultT& post_parse(ResultT& hit, ParserT const&, ScannerT const&)
>> {
>> hit.value(frame[phoenix::tuple_index<0>()]);
>> return hit;
>> }
> Ah, I see. Makes sense.
> Will the prior value of "hit" necessarily have been a "successful match"?

Yes, when post-parse is called, we definitely have a successful match.

> Will the prior value of "hit" necessarily have a "valid attribute"?

No, not necessarily. For reference attributes however, I don't have
a case yet where a parser returns an invalid reference with a successful
match. I'm not sure if it's possible to fall into such a case.

>> The important thing to note that the validity of an attribute of a match
>> is not at all related to it's "success". While an unsuccessful match
>> definitely cannot have a valid attribute, a successful match *can* have
>> an invalid attribute. This flexibility allows composing parsers to set
>> attributes to an initially invalid match attribute. To clarify a bit

> One more quick question: for this use-case,
>>>> match<int> m; // unitialized
>>>> m.value(3); // initializes m
> when does this "happen" in practice? Maybe in a closure where the first
> iteration results in no value but the second iteration does? I'm still
> in the dark, here.

Consider this rule:

    r = epsilon_p[ r.val = 123 ];

a) r returns a match<int>, corresponding to it's closure member val.
b) epsilon_p returns a match<nil_t>
c) r invokes epsilon_p: hit = eps.parse(input);
    c.1) hit has type match<int>
    c.2) eps.parse(input) has return type match<nil_t>
    c.3) assigning a mismatch match yields an invalid attribute.
    c.4) hit's attribute is invalid
d) eps' semantic action stores 123 into r's closure member val.
e) r is about to return with an invalid attribute
f) the closure 'decorator's post-parse function is called.
g) closure member val (with a value of 123) is places in the match<int>
h) r returns the match<int> with a value of 123

I tried to avoid making it seem long and winding, but this is the best
I can do. I hope this doesn't cause more confusion?


Joel de Guzman

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