I am trying to parse a BibTeX author field, and split it into its separate authors. This will help me rewriting the initials of each author. Here is a minimal example:
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
Why am I not able to extract the first author in the TOP
method?
method authors($/) { make @<author>.map(*.made) }
– Quintonquintuplemethod authors
with your suggestion, I still getNil
output for first author. – Tartan