数据样本
[Wang, Zhiguo; Zhao, Zhiguo] Hangzhou Normal Univ, Ctr Cognit & Brain Disorders, Hangzhou, Zhejiang, Peoples R China; [Wang, Zhiguo; Theeuwes, Jan] Vrije Univ Amsterdam, Dept Cognit Psychol, Amsterdam, Netherlands
Grammar
grammar University {
token TOP { ^ <university> $ }
token university { [ <bracket> <info> ]+ % '; ' }
token bracket { '[' <studentname> '] ' }
token studentname { <stdname=.info>+ % '; ' }
token info { <field>+ % ', ' }
token field { <-[,\]\[;\n]>+ }
}
grammar MyUniversity is University {
token university { <info>+ % '; ' }
}
Action
class MyUniversityAction {
...
}
解析
my $parsed = University::Grammar.parse($string);
for @($parsed<university><info>) -> $u {
say $u<field>[0];
}