Re: option: /<option/i /\w+/ optarg(?) '>'
[email protected] ("Ted Zlatanov") 20 May 2004 08:38:53 -0400
| Newsgroups | perl.recdescent |
|---|---|
| Organization | =?koi8-r?q?=F4=C5=CF=C4= CF=D2=20=FA=CC=C1=D4=C1=CE=CF=D7? = @ Cienfuegos |
| Message-ID | <[email protected]> |
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