-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enabled to overwrite sort method for the regexp. #6
base: master
Are you sure you want to change the base?
Conversation
I would not do that because it would affect everyone who upgraded to the new version, wouldn't it? I suggest you simply subclass Regexp::Assemble itself, add that code (or a new method) and use your own local copy of that code. Alternately, you could propose a new method which does what you want but has no effect on any other user. That is, users could call or ignore your new method. |
@ronsavage Simple subclassingI think that we can not resolve this problem by simple subclassing. package Regexp::Assemble::Custom {
use parent 'Regexp::Assemble';
sub _re_sort($$) {
my ($a, $b) = @_;
$a =~ m/[\*\+]/ <=> $b =~ m/[\*\+]/ || $a cmp $b;
}
}
my $ra = Regexp::Assemble::Custom->new->track(1);
$ra->add(qw(ab [a-z]+));
say $ra->match('ab'); # "[a-z]+" is returned. Regexp::Assemble::Custom::_re_sort is not called To overwrite
|
Hmmm. I can see you've been very thorough. I can't work on this right now, since I'm at $work, so I'll have to think about it. |
Thank you very much. I am not in a hurry. I'd appreciate it if you could answer at your convenience. |
Oh... very sorry.
The following code also worked at 0.37 without patch use Regexp::Assemble;
package Regexp::Assemble;
no warnings 'redefine';
sub _re_sort {
$a =~ m/[\*\+]/ <=> $b =~ m/[\*\+]/ || $a cmp $b;
};
package main;
my $ra = Regexp::Assemble->new->track(1);
$ra->add(qw(ab [a-z]+));
say $ra->match('ab'); # "ab" is returned. I think that 40608cb is useful, however even without it, I can do what I want to do. |
Hi Taku
Glad to hear you've kept working on this, and that you've done so well.
Nevertheless, I'll have a look at the code over the weekend.
…On 11/04/17 11:28, Taku AMANO wrote:
Oh... very sorry.
To overwrite |_re_sort| by redifine
The following code also worked at 0.37 without patch
<https://gist.github.com/usualoma/58a89fd5bc8c4cfe634259158f1f46d2>
use Regexp::Assemble;
package Regexp::Assemble;
no warnings 'redefine';
sub _re_sort {
$a =~ m/[\*\+]/ <=> $b =~ m/[\*\+]/ || $a cmp $b;
};
package main;
my $ra = Regexp::Assemble->new->track(1);
$ra->add(qw(ab [a-z]+));
say $ra->match('ab'); # "ab" is returned.
I think that 40608cb
<40608cb>
is useful, however even without it, I can do what I want to do.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABT-AKabVIVjq46uduxqQndqqNLEZJQks5rutdFgaJpZM4M4JAg>.
--
Ron Savage - savage.net.au
|
Motivation
I want to weight to some conditions explicitly.
Proposal
I think that we can specify matching order by specifying comparison function for regular expression.