On Mon, 23 Jun 2003, [EMAIL PROTECTED] wrote: > 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.
Could I ask you to please condense your example grammar to the smallest unit that exhibits a bug? I think your definition of zoekVraag doesn't work: > zoekVraag: > basisZoekVraag (operator basisZoekVraag)(s) Parse::RecDescent grammars work better with two-part recursive definitions; see below for how your grammar could work (I shortened it for the example, but it should be clear how to do your whole grammar). The $return actions make debugging easier. You could also do <autotree>. I'm not sure why your Criteria rule has the /\D/ match, it works fine without it on your example text and with it you'll miss some data. \D will match just one non-digit character (also non-space unless you override your skip); is that what you really want? There is no need to quote ' characters in a regular expression (the zoekString rule). HTH Ted #!/usr/bin/perl -w use strict; use Parse::RecDescent; use Data::Dumper; #$::RD_TRACE=100; my $grammar = q{ # Criteria:zoekVraag /\D/ Criteria: zoekVraag(s) zoekVraag: basisZoekVraag | compoundZV | <error> compoundZV: operator zoekVraag { $return = { operator => $item{operator}, zv => $item{zoekVraag} }; 1; } basisZoekVraag: mediumZoekVraag | onderwerpZoekVraag | <error> onderwerpZoekVraag: 'topic=' zoekString { $return = { topic => $item{zoekString} }; 1; } mediumZoekVraag: 'medium=' zoekString { $return = { medium => $item{zoekString} }; 1; } operator: /or|and/ | <error> zoekString: /'[a-zA-Z:\. ]+'/ }; my $parser = new Parse::RecDescent($grammar); undef $/; my $text = "medium='d' or medium='f' and topic='t'"; my $result = $parser->Criteria($text); print Dumper($result);