On Sun, Apr 19, 2015 at 06:31:30PM +0200, mt1957 wrote:
: L.s.,
: 
: I found a small problem when writing a piece of grammar. A
: simplified part of it is shown here;
: ...
: token tag-body   { <body-start> ~ <body-end> <body-text> }
: token body-start { '[' }
: token body-end  { ']' }
: token body-text  { .*? <?body-end> }
: ...
: 

A couple of things:

The ~ is intended primarily for literal delimiters, so you'd typically just
see something like:

    token tag-body   { '[' ~ ']' <body-text> }
    token body-text  { .*? <?before ']'> }

In this case there would be no body-end rule at all--which means you'd
hang the action routine somewhere else.  So you could just as easily
hang your action routine on tag-body or on body-text, depending on
whether you care about whether the match object includes the delimiters.
In either case, it doesn't have to attach to the final delimiter.

:  * Is there a possibility to give the method more information in the
:    form of boolean flags saying for example that there was a look ahead
:    match, all in all the parser knows about the way it must seek!

One could always set a dynamic variable inside the "not really" rule:

    token body-text {
        :my $*NOT-REALLY = 1;
        .*?
        <?body-end>
    }

but it's easier to just move the reduction action.

Larry

Reply via email to