> oh fine, the next time I will look first in the source!

No. Read the docs first. Its there... :-)

>From the synopsis:
         # Change the universal token prefix pattern
         # (the default is: '\s*'):
       $Parse::RecDescent::skip = '[ \t]+';

> but not proper matching, it's already stopping at the first 
> line comment
> and therefore you get this ERROR messages as you get.

Er, I dont understand you. That pattern will skip all line comments and
whitespace. (Well, actually P::RD will match that regex repeated times as is
necessary.) 

BTW, it skipped all line comments and whitspace in the sample code I posted.

> 
> But anyway, your regex looks much better than my first try 
> and I changed
> my regex now to qr{(\s+|#.*)+} (the old one was running but 
> awful to maintain)

Im not really sure what the difference is, but whatever makes you
comfortable. I think that P::RD will automatically stick a \G or ^ or \A at
the beginning anyway so it probably doesnt matter.... :-)
 
> or  gr{
>         (       # capture group 1
>            \s+    # one or more whitespace
>           |       # or
>             \#.*  # or anything starting with # before next \n
>          )+       # close capture group 1, one ore more repetitions
>        }x
> 
> your whitspace should not start with ^\s because then you get not
> rid of the \n after #.*$.

Ah, can you post me output to explain what you mean? It seemed to skip
everything in the test code.

> Anyway Ives, working with your hint about Parse::RecDescent::skip
> the result looks a little bit better:

Its Yves actually... :-) 

> > #!/usr/bin/perl
> > use Parse::RecDescent;
> > $Parse::RecDescent::skip = qr{(\s+|#.*)+};
> > $RD_TRACE = 1;
> > my $grammar =<<'EOGRAMMAR';
> >         file            : int(s) /\z/
> >                         | <error>
> >                          
> >         int             : /[+-]?\d+/
> >                         | <error>
> > EOGRAMMAR
> > 
> > my $parser = Parse::RecDescent->new($grammar);
> > 
> > my $text = <<'EOTEXT';
> >         # comment
> >         .123
> > EOTEXT

And what does it do with the sample text I posted?

my $text = <<'EOTEXT';
        # comment
        123 #comment
        # comment
        .123 #Comment
EOTEXT

> > my $result = $parser->file($text);
> 
> 
>        ERROR (line 2): Invalid int: Was expecting /[+-]?\\d+/
> 
>        ERROR (line 1): Invalid file: Was expecting int
> 
> but still complaining about ERROR in line 1, what is not
> correct. Looking in the trace:

This error is correct. 

It did not match an integer (you have ".123" not 123), therefore int failed,
therefore file failed. 

Dont forget that it backtracks up the stack, realises it still has unmatched
text and no further rules apply and then terminates with an error.

Quickly here is your grammar translated into english...

match any number of ints followed by end of text. 

It tries to match an int. Fails and so stops trying to match int(s) and
tries to match /\z/ which means end of text. Since there is still text it
cannot match /\z/ and thus it fails with an error.  All of this is expected.

:-)

> it gets again stuffed back but the <error> directive spends a 
> different message. Has something to do how and when Damian
> is using skip.

If you can show us what you think should happen then maybe we can help you
make it happen, but what _is_ happening is what should be happening.

> Regards and again thanks for your time

Yeah, no prob. Im just a repressed TA at heart.

Yves

Reply via email to