ichimunki has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use Parse::RecDescent; my $grammar = join( '', <DATA> ); my $parser = Parse::RecDescent->new( $grammar ) or die "Error: Bad grammar\n"; #while(<STDIN>){ $text .= $_; } my $text =<< "SUB_STDIN"; A nicely [[spaced]] link. A poorly[[spaced]]link. Another poorly..[[spaced]]..link. SUB_STDIN my $results = $parser->startrule( $text ) or die "Error: Bad text\n"; __DATA__ startrule: <skip:''> bit(s) bit: eol | word | space | token | punct eol: /\n[ \t]*/ {print "<newline>\n" } space: /[ \t]+/ {print "< >" } word: /[\w\']+/ {print "<word: $item[1]>" } punct: /[^\w\s]+/ {print "<punct: $item[1]>" } token: link link: /\[\[(.+?)\]\]/ {print "<link: $item[1]>" }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parse::RecDescent Grammar Fun
by hsmyers (Canon) on Jul 24, 2002 at 20:53 UTC | |
by ichimunki (Priest) on Jul 24, 2002 at 21:13 UTC | |
by hsmyers (Canon) on Jul 24, 2002 at 22:51 UTC | |
by ichimunki (Priest) on Jul 25, 2002 at 00:52 UTC | |
|
Re: Parse::RecDescent Grammar Fun
by Abigail-II (Bishop) on Jul 25, 2002 at 11:25 UTC | |
by ichimunki (Priest) on Jul 25, 2002 at 14:21 UTC |