-
-
Save FROGGS/d2c01ff6ada9efe61e07 to your computer and use it in GitHub Desktop.
Note: we're still in QRegex::P6Regex instead and :i is hard-coded for testing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/core/Cursor.pm b/src/core/Cursor.pm | |
index ddf0cd1..3bee4b0 100644 | |
--- a/src/core/Cursor.pm | |
+++ b/src/core/Cursor.pm | |
@@ -56,17 +56,18 @@ my class Cursor does NQPCursorRole { | |
if nqp::isconcrete($var) { | |
# Call it if it is a routine. This will capture if requested. | |
return $var(self) if $var ~~ Callable; | |
- my $maxlen := -1; | |
- my $cur := self.'!cursor_start_cur'(); | |
- my $pos := nqp::getattr_i($cur, $?CLASS, '$!from'); | |
- my $tgt := $cur.target; | |
- my $eos := nqp::chars($tgt); | |
- my Mu $nfa := QRegex::NFA.new; | |
- my $fate := 0; | |
- my $count := 0; | |
- my $start := 1; | |
- my Mu $alts := nqp::list(); | |
+ my $maxlen := -1; | |
+ my $cur := self.'!cursor_start_cur'(); | |
+ my $pos := nqp::getattr_i($cur, $?CLASS, '$!from'); | |
+ my $tgt := $cur.target; | |
+ my $eos := nqp::chars($tgt); | |
+ my Mu $nfa := QRegex::NFA.new; | |
+ my $fate := 0; | |
+ my $count := 0; | |
+ my $start := 1; | |
+ my Mu $alts := nqp::list(); | |
my Mu $order := nqp::list(); | |
+ my $a_run := $a; | |
if nqp::istype($var, Positional) || nqp::istype($var, Capture) { | |
if $s { | |
@@ -76,19 +77,30 @@ my class Cursor does NQPCursorRole { | |
else { | |
# prepare to run the NFA if $var is array-ish. | |
for $var.list -> $topic { | |
- nqp::push($alts, $topic); | |
if $a { | |
# We are in a regex assertion, the strings we get will be treated as | |
# regex rules. | |
- my $rx := eval( $i ?? "my \$x = anon regex \{:i ^$topic \}" | |
- !! "my \$x = anon regex \{ ^$topic \}" ); | |
- my Mu $nfas := nqp::findmethod($rx, 'NFA')($rx); | |
- $nfa.mergesubstates($start, 0, $fate, $nfas, Mu); | |
+ my Mu $rxcompiler := nqp::getcomp('QRegex::P6Regex'); | |
+ my Mu $thing := $rxcompiler.compile(":i $topic"); | |
+ my Mu $cursor := $thing(self); | |
+ my Mu $match; | |
+ if $cursor.pos > $cursor.from { | |
+ $match := nqp::substr($tgt, $cursor.from, $cursor.pos); | |
+ my Mu $lit := QAST::Regex.new( :rxtype<literal>, $match, | |
+ :subtype( $i ?? 'ignorecase' !! '') ); | |
+ my Mu $nfa2 := QRegex::NFA.new; | |
+ my Mu $node := nqp::findmethod($nfa2, 'addnode')($nfa2, $lit); | |
+ my Mu $save := nqp::findmethod($node, 'save')($node, :non_empty(1)); | |
+ $nfa.mergesubstates($start, 0, $fate, $save, Mu); | |
+ } | |
+ nqp::push($alts, $match); | |
+ $a_run := 0; | |
} | |
elsif $topic ~~ Regex { | |
# A Regex already. | |
my Mu $nfas := nqp::findmethod($topic, 'NFA')($topic); | |
$nfa.mergesubstates($start, 0, $fate, $nfas, Mu); | |
+ nqp::push($alts, $topic); | |
} | |
else { | |
# The pattern is a string. | |
@@ -98,6 +110,7 @@ my class Cursor does NQPCursorRole { | |
my Mu $node := nqp::findmethod($nfa2, 'addnode')($nfa2, $lit); | |
my Mu $save := nqp::findmethod($node, 'save')($node, :non_empty(1)); | |
$nfa.mergesubstates($start, 0, $fate, $save, Mu); | |
+ nqp::push($alts, $topic); | |
} | |
$fate := $fate + 1; | |
} | |
@@ -119,16 +132,19 @@ my class Cursor does NQPCursorRole { | |
} | |
for $order -> $topic { | |
- my $match; | |
- my $len; | |
+ my $match := ''; | |
+ my $len := 0; | |
- if $a { | |
+ if $a_run { | |
# We are in a regex assertion, the strings we get will be treated as | |
# regex rules. | |
- my $rx := eval( $i ?? "my \$x = anon regex \{:i ^$topic \}" | |
- !! "my \$x = anon regex \{ ^$topic \}" ); | |
- $match := (nqp::substr($tgt, $pos, $eos - $pos) ~~ $rx).Str; | |
- $len := nqp::chars( $match ); | |
+ my Mu $rxcompiler := nqp::getcomp('QRegex::P6Regex'); #QRegex::P6Regex | |
+ my Mu $thing := $rxcompiler.compile(":i $topic"); | |
+ my Mu $cursor := $thing(self); | |
+ if $cursor.pos > $cursor.from { | |
+ $match := nqp::substr($tgt, $cursor.from, $cursor.pos); | |
+ $len := nqp::chars( $match ); | |
+ } | |
} | |
elsif $topic ~~ Regex { | |
# A Regex already. | |
@@ -178,21 +194,5 @@ my class Cursor does NQPCursorRole { | |
} | |
} | |
-sub MAKE_REGEX($arg) { | |
- my role CachedCompiledRegex { | |
- has $.regex; | |
- } | |
- if $arg ~~ Regex { | |
- $arg | |
- } | |
- elsif nqp::istype($arg, CachedCompiledRegex) { | |
- $arg.regex | |
- } | |
- else { | |
- my $rx := eval("my \$x = anon regex \{ $arg \}"); | |
- $arg does CachedCompiledRegex($rx); | |
- $rx | |
- } | |
-} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment