BrentDax has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing a program called babyperl, which compiles a tiny subset of Perl 6 into bytecode. I've built the basic Parse::RecDescent grammar, but I can't figure out how to get it to insert a semicolon (or at least pretend there's one there) after the pattern BLOCK:    '{' statements '}'. There doesn't seem to be any lookbehind capability in Parse::RecDescent. I'd like to do something like statements:    statement (';'|lookbehind(BLOCK)) statements(?). Am I missing something, or does the functionality to do this simply not exist?

=cut
--Brent Dax
There is no sig.

Replies are listed 'Best First'.
Re: Parse::RecDescent--pretending there's a semicolon after a BLOCK
by TheDamian (Vicar) on Oct 06, 2001 at 09:53 UTC
    There's no look-behind functionality of the type you want.

    But what's wrong with:

    BLOCK: '{' statements '}' StatementBlock: BLOCK /(\s*;)*/ { $item[1] }
    ???
      That wasn't really what I needed, but the idea of the wrapper rule was. I wanted if(foo) {bar} to be treated as if(foo) {bar};, but I didn't want to lose the autotree behavior. So here's what I came up with:
      block: BLOCK { $text=';'.$text; $return=$item{BLOCK} } BLOCK: '{' statements '}' | <error>
      Simple and sensible.

      PS: I didn't know you had an account here. Apparently I'm in even better company than I thought. :^)

      =cut
      --Brent Dax
      There is no sig.

Re: Parse::RecDescent--pretending there's a semicolon after a BLOCK
by Anonymous Monk on Oct 07, 2001 at 08:30 UTC
    Hey i was wondering what this is all about someone has introdued this to me and it is cool!!!!