我正在尝试解析 BibTeX 作者字段,并将其拆分为单独的作者。这将帮助我重写每个作者的姓名首字母。这是一个最小的例子:
use v6;
my $str = '{Rockhold, Mark L and Yarwood, RR and Selker, John S}';
grammar BibTexAuthor {
token TOP {
<all-text>
}
token all-text {
'{' <authors> '}'
}
token authors {
[<author> [' and ' || <?before '}'>]]+
}
token author {
[<-[\s}]> || [' ' <!before 'and '>]]+
}
}
class BibTexAuthor-actions {
method TOP($/) {
say $/;
print "First author = ";
say $<author>.made[0];
make $/.Str;
}
method all-text($/) {
make $/.Str;
}
method authors($/) {
make $/.Str;
}
method author($/) {
make $/.Str;
}
}
my $res = BibTexAuthor.parse( $str, actions => BibTexAuthor-actions.new).made;
Output:
「{Rockhold, Mark L and Yarwood, RR and Selker, John S}」
all-text => 「{Rockhold, Mark L and Yarwood, RR and Selker, John S}」
authors => 「Rockhold, Mark L and Yarwood, RR and Selker, John S」
author => 「Rockhold, Mark L」
author => 「Yarwood, RR」
author => 「Selker, John S」
First author = Nil
为什么我无法提取第一作者TOP
method?