Skip to content

Commit

Permalink
Capture and Match shouldn't provide method new
Browse files Browse the repository at this point in the history
(Especially when BUILD will work just fine.)  Otherwise we force
new grammars that have their own attributes to declare their own
new, which should be unnecessary.
  • Loading branch information
TimToady committed Apr 13, 2017
1 parent 331c51f commit 5069294
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/core/Capture.pm
Expand Up @@ -3,8 +3,6 @@ my class Capture { # declared in BOOTSTRAP
# has @!list; # positional parameters
# has %!hash; # named parameters

method new(:@list,:%hash) { self.bless(:@list,:%hash) }

method from-args(|c) { c }

submethod BUILD(:@list, :%hash --> Nil) {
Expand Down
20 changes: 16 additions & 4 deletions src/core/Match.pm
Expand Up @@ -444,10 +444,22 @@ my class Match is Capture is Cool does NQPMatchRole {
}
}

submethod new(:$orig,:$from = 0,:$pos,:$made) {
my $new := self.'!cursor_init'($orig, :p($pos));
nqp::bindattr_i($new, Match, '$!from', $from); # cannot assign to int in sig
$new
submethod BUILD(
:$orig = '',
:$from = 0,
:to(:$pos),
:ast(:$made),
:$shared,
:$braid,
:$list,
:$hash)
{
# :build tells !cursor_init that it's too late to do a CREATE
self.'!cursor_init'($orig, :build, :p($pos), :$shared, :$braid);
nqp::bindattr_i(self, Match, '$!from', $from);
nqp::bindattr( self, Match, '$!made', $made) if $made.defined;
nqp::bindattr( self, Capture, '@!list', $list) if $list.defined;
nqp::bindattr( self, Capture, '%!hash', $hash) if $hash.defined;
}

method clone() {
Expand Down

0 comments on commit 5069294

Please sign in to comment.