Forwarded on behalf of Ron D. Smith ------- Forwarded message follows ------- To: "Peter van der Kamp" <[EMAIL PROTECTED]> Subject: Re: Matching subrules Date sent: Mon, 23 Jun 2003 10:02:32 -0700 From: "Ron D. Smith" <[EMAIL PROTECTED]>
I'm not sure why you are confused, particularly with tracing on. You are asking for a 'Criteria' which is a 'zoekVraag /\D/' You then give it your string which CORRECTLY parses: "medium='d' or medium='f' a" This is obviously a zoekVraag followed by a non- digit. Your grammar clearly does not preclude extra stuff at the end of the string and you do not specify that the string must be completely consumed. I don't know what you want but there are at least two ways to get your grammar to fail. The first is the non-digit regx, which does not specify that you have nothing after the non-digit. Criteria:zoekVraag /\D\b/ will force the non-digit to be a single character. This does not necessarily generate the nice error messages you might like but does return undef. You also might make the following modification: Criteria:zoekVraag /\D/ /^\Z/ This will also fail. The two suggestions are, of course, not mutually exclusive. What was important about the trace was not what it *parsed*, but WHAT IT LEFT OVER. What you seem to be objecting to was that it did not try and consume the entire input, but you never told it that it had to. On Monday, Jun 23, 2003 "Peter van der Kamp" said: > I'm wondering why my grammar (see hereafter) accepts > the following input: > medium='d' or medium='f' ant topic='t' > > while it should raise an error on 'ant'. > With tracing enabled you can see that it really does > something with 'ant', except raising an error. > > Peter van der Kamp > > > use Parse::RecDescent; > #$::RD_TRACE=100; > > my $grammar = q{ > Criteria:zoekVraag /\D/ > > zoekVraag: > basisZoekVraag (operator basisZoekVraag)(s) > | > <error> > > basisZoekVraag: > mediumZoekVraag > | > onderwerpZoekVraag > | > titelZoekVraag > | > auteurZoekVraag > | > periodZoekVraag > | > <error> > > mediumZoekVraag: > 'medium=' zoekString > > onderwerpZoekVraag: > 'topic=' zoekString > > titelZoekVraag: > 'title=' zoekString > > auteurZoekVraag: > 'author=' zoekString > > periodZoekVraag: > rangePeriodZoekVraag > | > singlePeriodZoekVraag > > singlePeriodZoekVraag: > 'p=' cijfers > > rangePeriodZoekVraag: > 'p=' cijfers '-' cijfers > | > 'p=' '-' cijfers > | > 'p=' cijfers '-' > > operator: > /or|and/ > | > <error> > > zoekString: /\'[a-zA-Z:\. ]+\'/ > cijfers: /[0-9]{4}/ > }; > > my $parser = new Parse::RecDescent($grammar); > undef $/; > my $text = <STDIN>; > #print Data::Dumper->Dump([$parser- > >Criteria($text)]); > $result = $parser->Criteria($text); > > -- Intel, Corp. 5000 W. Chandler Blvd. Chandler, AZ 85226 -- Intel, Corp. 5000 W. Chandler Blvd. Chandler, AZ 85226 ------- End of forwarded message -------