Re: Help with a grammar problem

[email protected] (Matthew Braid) Fri, 4 Sep 2009 08:22:51 +1000
Newsgroups perl.recdescent
Message-ID <[email protected]>
Hi all,

Would there be some way of manipulating the skip re to do this?

Something along the lines of:

top: <skip: /NOT START DELIMETER/> chunk(s) eof
chunk: delimeter_start <skip: /NORMAL SKIP/> command(s) delimiter_end
eof: /\Z/

The problem there is defining a skip that won't skip a
delimeter_start. This probably won't allow delimeter_start to _not_
mean the start of a set of commands as well.

Not tested, but just a suggestion.

MB

2009/9/4 Mike Diehl <[email protected]>:
> On Thursday 03 September 2009 01:50:58 Damian Conway wrote:
>> Hi Mike,
>>
>> > What I've tried amounts to this:
>> >
>> > chunk: /.*?/ delimiter_start command(s) delimiter_end /.*?/
>>
>> Unfortunately that won't work, because every regex in a PRD grammar is
>> independent of the rest of the grammar, so even a minimal-matching .*?
>> eats everything.
>
> Ya, that's what I was suspecting. =A0In hind sight, I should have figured=
 that;
> that's how I'd write it...
>
>> Is there some reason you can't use something like:
>>
>> =A0 =A0 my $parser =3D Parse::RecDescent->new($grammar);
>>
>> =A0 =A0 $text =3D~ s{<DELIMITER> (.*?) </DELIMITER>}
>> =A0 =A0 =A0 =A0 =A0 =A0 { $parser->parse($1); q{} }gexs;
>
> That's what I was doing, but it seems I misinterpreted my profiling resul=
ts.
> I found from profiling that the function I use to create (once) and run t=
he
> parser accounted for 80% of runtime.
>
> I assumed that since I only create the parser once (if !defined), creatin=
g the
> parser wasn't where the cost was. =A0So I decided that it must be due to
> actually running the parser, which might run several times during program
> execution. =A0My conclusion was that I needed to rewrite the grammar so t=
hat
> the parser would only run once.
>
> It sounds like I may need to go back to the old algorithm and start tunin=
g the
> grammar.
>
> --
>
> Take care and have fun,
> Mike Diehl.
>