diff --git a/lib/GGE/Exp.pm b/lib/GGE/Exp.pm index f059631..597843e 100644 --- a/lib/GGE/Exp.pm +++ b/lib/GGE/Exp.pm @@ -37,29 +37,32 @@ role GGE::ShowContents { } } -# RAKUDO: Could name this one GGE::Exp::CUT or something, if enums -# with '::' in them worked, which they don't. [perl #71460] -our sub CUT_GROUP { -1 } -our sub CUT_RULE { -2 } -our sub CUT_MATCH { -3 } -#enum CUT ( -# CUT_GROUP => -1, -# CUT_RULE => -2, -# CUT_MATCH => -3, -#); - -our sub GREEDY { 0 } -our sub EAGER { 1 } -our sub NONE { 2 } -#enum GGE_BACKTRACK < -# GREEDY -# EAGER -# NONE -#>; class GGE::Exp is GGE::Match { our $group; + # RAKUDO: Should be just 'CutType' [RT #75454] + package GGE::Exp::CutType { + our sub CUT_GROUP { -1 } + our sub CUT_RULE { -2 } + our sub CUT_MATCH { -3 } + } + # RAKUDO: Enums don't work enough yet. + # our enum GGE::Exp::CutType ( + # CUT_GROUP => -1, + # CUT_RULE => -2, + # CUT_MATCH => -3, + # ); + + # RAKUDO: Should be just 'Backtracking' [RT #75454] + package GGE::Exp::Backtracking { + our sub GREEDY { 0 } + our sub EAGER { 1 } + our sub NONE { 2 } + } + # RAKUDO: Enums don't work enough yet. + # our enum GGE::Exp::Backtracking ; + method structure($indent = 0) { # RAKUDO: The below was originally written as a map, but there's # a bug somewhere in &map and lexical pads. The workaround @@ -148,7 +151,7 @@ class GGE::Exp is GGE::Match { } when 'fail' { local-return(); - } ]], CUT_RULE); + } ]], GGE::Exp::CutType::CUT_RULE); my $explabel = 'R'; $GGE::Exp::group = self; my $exp = self.reduce; @@ -180,7 +183,8 @@ class GGE::Exp is GGE::Match { %hash = $quant; %hash = %hash == Inf ?? '### ' !! ''; # RAKUDO: Waiting for named enums for this one - # my $bt = ($quant // GREEDY).name.lc; + # my $bt = ($quant + # // GGE::Exp::Backtracking::GREEDY).name.lc; my $bt = 'no idea'; %hash = sprintf '%s..%s (%s)', %hash, %hash, $bt; } @@ -256,7 +260,7 @@ class GGE::Exp::Quant is GGE::Exp { method contents() { my ($min, $max, $bt) = map { self{$_} }, ; - $bt //= GREEDY; + $bt //= GGE::Exp::Backtracking::GREEDY; # RAKUDO: Named enums # "{$bt.name.lc} $min..$max" "no idea $min..$max" @@ -277,7 +281,7 @@ class GGE::Exp::Quant is GGE::Exp { %args = 0; %args = '### '; given self { - when EAGER() { + when GGE::Exp::Backtracking::EAGER() { $code.emit( q[[ when '%L' { # quant %Q eager push @gpad, 0; @@ -308,7 +312,7 @@ class GGE::Exp::Quant is GGE::Exp { goto('%1'); } ]], $replabel, $nextlabel, |%args); } - when NONE() { + when GGE::Exp::Backtracking::NONE() { # RAKUDO: Hash slices not implemented yet # %args = $code.unique(), ''; %args = $code.unique(); @@ -709,7 +713,7 @@ class GGE::Exp::CGroup is GGE::Exp::Group { class GGE::Exp::Cut is GGE::Exp { method reduce() { - if self > CUT_RULE() { + if self > GGE::Exp::CutType::CUT_RULE() { my $group = $GGE::Exp::group; if !$group { $group = CodeString.unique(); @@ -802,7 +806,8 @@ class GGE::Exp::Subrule is GGE::Exp does GGE::ShowContents { when '%L_cont' { %4 goto('fail'); - } ]], CUT_MATCH, $next, $captgen, $captsave, $captback, |%args); + } ]], GGE::Exp::CutType::CUT_MATCH, $next, + $captgen, $captsave, $captback, |%args); } } } diff --git a/lib/GGE/Perl6Regex.pm b/lib/GGE/Perl6Regex.pm index d8e7ce5..c487a2f 100644 --- a/lib/GGE/Perl6Regex.pm +++ b/lib/GGE/Perl6Regex.pm @@ -471,23 +471,23 @@ class GGE::Perl6Regex { $m.to = $mob.to; if $mod2 eq ':?' { - $m = EAGER; + $m = GGE::Exp::Backtracking::EAGER; $m.to += 2; } elsif $mod2 eq ':!' { - $m = GREEDY; + $m = GGE::Exp::Backtracking::GREEDY; $m.to += 2; } elsif $mod1 eq '?' { - $m = EAGER; + $m = GGE::Exp::Backtracking::EAGER; ++$m.to; } elsif $mod1 eq '!' { - $m = GREEDY; + $m = GGE::Exp::Backtracking::GREEDY; ++$m.to; } elsif $mod1 eq ':' || $key eq ':' { - $m = NONE; + $m = GGE::Exp::Backtracking::NONE; ++$m.to; } @@ -652,7 +652,9 @@ class GGE::Perl6Regex { $exp = perl6exp($sep, %pad); } %pad = $isarray; - $exp //= %pad ?? NONE() !! GREEDY; + $exp //= %pad + ?? GGE::Exp::Backtracking::NONE() + !! GGE::Exp::Backtracking::GREEDY; return $exp; } @@ -730,9 +732,9 @@ class GGE::Perl6Regex { multi sub perl6exp(GGE::Exp::Cut $exp is rw, %pad) { $exp = - $exp.ast eq '::' ?? CUT_GROUP() - !! $exp.ast eq ':::' ?? CUT_RULE() - !! CUT_MATCH; + $exp.ast eq '::' ?? GGE::Exp::CutType::CUT_GROUP() + !! $exp.ast eq ':::' ?? GGE::Exp::CutType::CUT_RULE() + !! GGE::Exp::CutType::CUT_MATCH; return $exp; }