Skip to content

Commit

Permalink
Make Match.raku a bit more readable
Browse files Browse the repository at this point in the history
As in, making sure the attributes are always in the same order,
and attributes are only shown if they actually add information.
  • Loading branch information
lizmat committed Jan 24, 2020
1 parent b291fc7 commit 56d2b23
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/core.c/Match.pm6
Expand Up @@ -891,18 +891,17 @@ my class Match is Capture is Cool does NQPMatchRole {
}
}
multi method raku(Match:D:) {
my %attrs;
%attrs.ASSIGN-KEY("orig", (self.orig // '' ).raku);
%attrs.ASSIGN-KEY("from", (self.from // 0 ).raku);
%attrs.ASSIGN-KEY("pos", (self.pos // 0 ).raku);
%attrs.ASSIGN-KEY("made", (self.made // Any).raku);
%attrs.ASSIGN-KEY("list", (self.Capture::list // [] ).raku);
%attrs.ASSIGN-KEY("hash", (self.Capture::hash // {} ).raku);
'Match.new('
~ %attrs.fmt('%s => %s', ', ')
~ ')'
multi method raku(Match:D: --> Str:D) {
my $attrs := nqp::list_s;
nqp::push_s($attrs,(orig => self.orig // '').raku);
nqp::push_s($attrs,(from => self.from // 0).raku);
nqp::push_s($attrs,(pos => self.pos // 0).raku);
nqp::push_s($attrs,(list => $_).raku) with self.Capture::list;
nqp::push_s($attrs,(hash => $_).raku) with self.Capture::hash;
nqp::push_s($attrs,(made => $_).raku) with self.made;
nqp::concat('Match.new(',nqp::concat(nqp::join(', ',$attrs),')'))
}
multi method gist (Match:D: $d = 0) {
return "#<failed match>" unless self;
Expand Down

0 comments on commit 56d2b23

Please sign in to comment.