| 1 | use strict; use warnings; | ||
| 2 | package Lingy::Regex; | ||
| 3 | |||
| 4 | use Lingy::Common; | ||
| 5 | |||
| 6 | # need these things: | ||
| 7 | # * if-some | ||
| 8 | # * "sequence destructuring bindings" | ||
| 9 | |||
| 10 | sub new { | ||
| 11 | my ($class, $scalar) = @_; | ||
| 12 | bless qr/$scalar/, $class; | ||
| 13 | } | ||
| 14 | |||
| 15 | sub find { | ||
| 16 | return nil unless $_[1] =~ $_[0]; | ||
| 17 | return string($&) unless defined $1; | ||
| 18 | my ($i, @capture) = (1, string($&)); | ||
| 19 | { | ||
| 20 | no strict 'refs'; | ||
| 21 | while (defined (my $value = ${"$i"})) { | ||
| 22 | push @capture, string($value); | ||
| 23 | $i++; | ||
| 24 | } | ||
| 25 | } | ||
| 26 | VECTOR->new([@capture]); | ||
| 27 | } | ||
| 28 | |||
| 29 | sub matches { | ||
| 30 | find REGEX->new("\\A$_[0]\\z"), $_[1]; | ||
| 31 | } | ||
| 32 | |||
| 33 | sub pattern { | ||
| 34 | __PACKAGE__->new(@_); | ||
| 35 | } | ||
| 36 | |||
| 37 | 1; |