On Thu, 20 May 2004, [EMAIL PROTECTED] wrote: > why doesn't the question mark in the optarg(?) > below work as I expect? In the trace I see that > optarg consumes the ">" character and then the > option rule fails, since the final ">" is missing. > > Isn't P:RD supposed to backtrack and say > "ok, the optarg(?) didn't match anything here"? > > Of course the script below works when I change > the optarg from /\S+/ to /\w+/, but I'm curious, > why doesn't optarg(?) mean "ZERO or one" here?
Your basic problem is this: > optarg: /\S+/ Because P::RD relies on the Perl 5 regex engine, it can't backtrack regular expressions on its own. It just asks Perl 5 to match an optarg and that's used subsequently. Maybe the Perl 6 grammars will do this (I think they can), but for now you have to be careful with the regular expressions you specify. This example, in particular, should exclude '>' from the possible things optarg will match - so \w+ is a solution, but you are being unnecessarily strict on the optarg rule. You may like /[^>]+/ better. But then, depending on how SGML-like your language is, you may have embedded '>' characters in your option arguments. In your case, it seems like what I suggest would be OK. Ted