in reply to Re: Parse::RecDescent trouble
in thread Parse::RecDescent trouble

I absolutely don't mind. Actually I am extremely happy I got an answer like this. Thank you a ton, it is full of very helpful advices. Particularly I had no idea I can add a closure to the grammar and use it as part of a virtual main package (I did not find it nowhere in the docs).
I have an additional question if you do not mind. Can you decipher this:
line : '' # Skip blank lines. <skip:'[ \t]*'> # Don't treat newlines as whitespace +. key_value /\n/ <skip: $item[2]> { $item[3] }
for me please? I particularly do not understand the '' construct (it will always match right?) neither do I understand how can you have several tokens in one rule without the | mark (you have '' then a skip pragma then key_value then /\n/ and then another skip pragma)
Once again thanks a lot for the insights!

Replies are listed 'Best First'.
Re^3: Parse::RecDescent trouble
by ikegami (Patriarch) on Jan 12, 2007 at 22:26 UTC

    Particularly I had no idea I can add a closure to the grammar and use it as part of a virtual main package

    It's not really a closure. The block is inlined at the start of the generated parser code. You should check out Grammar.pm after executing:

    use Parse::RecDescent my $grammar = ...; Parse::RecDescent->Precompile($grammar, "Grammar");

    That block is documented as Start-up Actions.

    I particularly do not understand the '' construct. it will always match right?

    Yes, but remember that P::RD removes /$skip/ from the input before every terminal in the grammar. The current value of skip is '\\s*', so '' removes all leading whitespace.

    That whole thing allows blank lines between key_value, but not within key_value.