jaldhar has asked for the wisdom of the Perl Monks concerning the following question:
assume I had a Parse::RecDescent grammar that looked in part like this:
order: quantity color item quantity: /\d+/ color: # what should this be? item: 'pen' | 'pencil'
now assume in one script that uses this grammar, there was:
my @colors = ('red', 'green', 'blue');
while in another script there was:
my @colors = ('cyan', 'magenta', 'burnt umber');
How would I write the definition for color in the grammer so it would match only valid @colors? There may be many other scripts with different color combinations, and as the second example shows, they can be arbitrary strings with embedded spaces.
I suspect the answer involves having a function in each script like this:
sub is_valid_color { my ($color) = @_; foreach (@colors) { return 1 if $color eq $_; } return undef; }
but for some reason I just can't make the connection.
--
જલધર
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Dynamic expansion of tokens with Parse::RecDescent
by amw1 (Friar) on Aug 18, 2004 at 21:13 UTC | |
by ikegami (Patriarch) on Aug 18, 2004 at 22:04 UTC | |
by amw1 (Friar) on Aug 18, 2004 at 22:46 UTC | |
|
Re: Dynamic expansion of tokens with Parse::RecDescent
by ikegami (Patriarch) on Aug 18, 2004 at 21:39 UTC | |
|
Re: Dynamic expansion of tokens with Parse::RecDescent
by revdiablo (Prior) on Aug 18, 2004 at 20:54 UTC | |
|
Re: Dynamic expansion of tokens with Parse::RecDescent
by Solo (Deacon) on Aug 18, 2004 at 21:04 UTC | |
|
Re: Dynamic expansion of tokens with Parse::RecDescent
by jaldhar (Vicar) on Aug 19, 2004 at 20:17 UTC |