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.
--
જલધર
In reply to Dynamic expansion of tokens with Parse::RecDescent by jaldhar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |