libparse-recdescent-perl/demo/demo_autoscoresep.pl

33 lines
594 B
Perl
Raw Permalink Normal View History

2022-09-23 10:00:36 +08:00
#! /usr/local/bin/perl -ws
use Parse::RecDescent;
$RD_WARN = undef;
$RD_TRACE=1;
my $parse = Parse::RecDescent->new(<<'EOGRAMMAR');
line: <autoscore: @{$item[1]}>
line: seplist[sep=>',']
| seplist[sep=>':']
| seplist[sep=>" "]
seplist: <skip:""> <leftop: /[^$arg{sep}]*/ "$arg{sep}" /[^$arg{sep}]*/>
EOGRAMMAR
while (<DATA>)
{
chomp;
my $res = $parse->line($_);
print '[', join('][', @$res), "]\n";
}
__DATA__
c,o,m,m,a,s,e,p,a,r,a,t,e,d
c:o:l:o:n:s:e:p:a:r:a:t:e:d
s p a c e s e p a r a t e d
m u:l t i,s:ep ar:a,ted
m u:l,t i,s:ep ar:a,ted
m:u:l,t i,s:ep ar:a,ted