Hi Nikolay,

Your grammar allows a line to be completely empty
at the end of the input, so the end sequence is:

     Try to match Line against 'ccccc'
     Match
     Input is now ''
     Try to match Line against ''
     Match
     Parser detects no change in the input and terminates.

What you actually want is to parse lines that are *separated*
by newlines. RecDescent has a convenient way of doing that:

     Rulename(s /separator/)

So you could rewrite your grammar like so:

  my $grammar = q{
    Page:
        <skip:''>
        Line(s /\n/)     {print "Finished! \n"}

    Line:
        /[^\n]*/         {print "Line: '$item[1]'\n"}
  };

Try this version and you'll get what you expected.

Note also that I used the <skip:...> directive instead of setting
the global variable. The directive version is much safer.

Damian

Reply via email to