Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
adaptations to the new Rakudo master
- Named enums are not in place yet; swapped them out for simple subroutines.

- As a consequence, needed to put parens in some places where subs would
  otherwise gobble up things as arguments.

- The quote qq[<$prefix\[$list\]>] is now interpreted as an indexing into
  $prefix, what with the new correct-er interpolator and all. (jnthn++) But
  that wasn't at all what was intended -- the inner brackets are escaped in
  a misguided attempt to have them not be interpolated. Split the string up
  into smaller ones for clarity.

- Changed one 'class ... is also' into a stub class and a real declaration,
  and another one into a class declaration and an 'augment class'. Had to
  add 'use MONKEY_TYPING;' for the latter.

- Changed a large number of subs in a class (which were already a workaround
  for constants) into 'our sub' declarations.

- Became a bit more honest with a hash parameter %opts, which was detected to
  be changing inside the method even though it was readonly. We got away with
  this earlier, because assignment to elements of a hash wasn't checked.

- Removed an 'undef'. Since the method body is empty, it should now return
  Nil instead, which should work just as well.

- Removed a no-longer-necessary workaround with '// undef' on hash lookups
  which might return a miss. Such return values used to be nuclear, but that
  problem has since been fixed.

- Workedaround the lack of '<->' signatures. The code didn't become *that*
  much more repetitious.

- Switched the engine over from 'alpha' to 'perl6'.
  • Loading branch information
Carl Masak committed Apr 10, 2010
1 parent c4fb5b3 commit 839bd22
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 42 deletions.
36 changes: 21 additions & 15 deletions lib/GGE/Exp.pm
Expand Up @@ -32,17 +32,23 @@ 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]
enum CUT (
CUT_GROUP => -1,
CUT_RULE => -2,
CUT_MATCH => -3,
);

enum GGE_BACKTRACK <
GREEDY
EAGER
NONE
>;
sub CUT_GROUP { -1 }
sub CUT_RULE { -2 }
sub CUT_MATCH { -3 }
#enum CUT (
# CUT_GROUP => -1,
# CUT_RULE => -2,
# CUT_MATCH => -3,
#);

sub GREEDY { 0 }
sub EAGER { 1 }
sub NONE { 2 }
#enum GGE_BACKTRACK <
# GREEDY
# EAGER
# NONE
#>;

class GGE::Exp is GGE::Match {
my $group;
Expand Down Expand Up @@ -252,7 +258,7 @@ class GGE::Exp::Quant is GGE::Exp {
}
%args<c C> = 0, '### ';
given self.hash-access('backtrack') {
when EAGER {
when EAGER() {
$code.emit( q[[
when '%L' { # quant %Q eager
push @gpad, 0;
Expand Down Expand Up @@ -283,7 +289,7 @@ class GGE::Exp::Quant is GGE::Exp {
goto('%1');
} ]], $replabel, $nextlabel, |%args);
}
when NONE {
when NONE() {
%args<c C> = $code.unique(), '';
if self.hash-access('min') != 0
|| self.hash-access('max') != Inf {
Expand Down Expand Up @@ -516,7 +522,7 @@ class GGE::Exp::EnumCharList is GGE::Exp does GGE::ShowContents {
}
}
my $list = self.ast;
qq[<$prefix\[$list\]>]
"<$prefix" ~ '[' ~ "$list]>";
}

method p6($code, $label, $next) {
Expand Down Expand Up @@ -677,7 +683,7 @@ class GGE::Exp::CGroup is GGE::Exp::Group {

class GGE::Exp::Cut is GGE::Exp {
method reduce() {
if self.hash-access('cutmark') > CUT_RULE {
if self.hash-access('cutmark') > CUT_RULE() {
my $group = $GGE::Exp::group;
if !$group.hash-access('cutmark') {
$group.hash-access('cutmark') = CodeString.unique();
Expand Down
3 changes: 1 addition & 2 deletions lib/GGE/Match.pm
@@ -1,7 +1,6 @@
use v6;

# XXX: See the file lib/GGE/Perl6Regex.pm for an explanation.
class GGE::Perl6Regex {}
class GGE::Perl6Regex { ... }

# This is a workaround. See the postcircumfix:<{ }> comments below.
class Store {
Expand Down
20 changes: 10 additions & 10 deletions lib/GGE/OPTable.pm
Expand Up @@ -15,16 +15,16 @@ class GGE::OPTable {
##constant GGE_OPTABLE_INFIX = 0x60;
##constant GGE_OPTABLE_POSTCIRCUMFIX = 0x80;
##constant GGE_OPTABLE_CIRCUMFIX = 0x90;
sub GGE_OPTABLE_EXPECT_TERM { 0x01 }
sub GGE_OPTABLE_EXPECT_OPER { 0x02 }
our sub GGE_OPTABLE_EXPECT_TERM { 0x01 }
our sub GGE_OPTABLE_EXPECT_OPER { 0x02 }

sub GGE_OPTABLE_TERM { 0x10 }
sub GGE_OPTABLE_POSTFIX { 0x20 }
sub GGE_OPTABLE_CLOSE { 0x30 }
sub GGE_OPTABLE_PREFIX { 0x40 }
sub GGE_OPTABLE_INFIX { 0x60 }
sub GGE_OPTABLE_POSTCIRCUMFIX { 0x80 }
sub GGE_OPTABLE_CIRCUMFIX { 0x90 }
our sub GGE_OPTABLE_TERM { 0x10 }
our sub GGE_OPTABLE_POSTFIX { 0x20 }
our sub GGE_OPTABLE_CLOSE { 0x30 }
our sub GGE_OPTABLE_PREFIX { 0x40 }
our sub GGE_OPTABLE_INFIX { 0x60 }
our sub GGE_OPTABLE_POSTCIRCUMFIX { 0x80 }
our sub GGE_OPTABLE_CIRCUMFIX { 0x90 }

has %!tokens;
has %!keys;
Expand All @@ -47,7 +47,7 @@ class GGE::OPTable {
expect => 0x0101, arity => 1 },
;

method newtok($name, *%opts) {
method newtok($name, *%opts is copy) {
my $category = $name.substr(0, $name.index(':') + 1);
if %!sctable{$category} -> %defaults {
%opts{$_} //= %defaults{$_} for %defaults.keys;
Expand Down
27 changes: 13 additions & 14 deletions lib/GGE/Perl6Regex.pm
Expand Up @@ -3,16 +3,18 @@ use GGE::Match;
use GGE::Exp;
use GGE::OPTable;

use MONKEY_TYPING;

class GGE::Exp::WS is GGE::Exp::Subrule {
method contents() { undef }
method contents() {}
}

# XXX: why 'is also'? Because we'd really like to do something like
# &::<GGE::Perl6Regex::parse_regex> in GGE::Match::before (and after), but
# that syntax isn't implemented yet. Thus, we do the next best thing and
# declare the GGE::Perl6Regex class in the GGE::Match module, and re-open it
# here.
class GGE::Perl6Regex is also {
class GGE::Perl6Regex {
has GGE::Exp $!exp;
has Callable $!binary;

Expand Down Expand Up @@ -613,10 +615,7 @@ class GGE::Perl6Regex is also {
if $key eq 's' {
$key = 'sigspace';
}
# RAKUDO: Looks odd with the '// undef', doesn't it? Well, without
# it, things blow up badly if we try to inspect the value
# of a hash miss.
my $temp = %pad{$key} // undef;
my $temp = %pad{$key};
%pad{$key} = $exp.ast;
$exp[0] = perl6exp($exp[0], %pad);
%pad{$key} = $temp;
Expand All @@ -640,14 +639,14 @@ class GGE::Perl6Regex is also {
}

multi sub perl6exp(GGE::Exp::Quant $exp is rw, %pad) {
my $isarray = %pad<isarray> // undef;
my $isarray = %pad<isarray>;
%pad<isarray> = True;
$exp[0] = perl6exp($exp[0], %pad);
if $exp.hash-access('sep') <-> $sep {
$sep = perl6exp($sep, %pad);
if $exp.hash-access('sep') -> $sep {
$exp.hash-access('sep') = perl6exp($sep, %pad);
}
%pad<isarray> = $isarray;
$exp.hash-access('backtrack') //= %pad<ratchet> ?? NONE !! GREEDY;
$exp.hash-access('backtrack') //= %pad<ratchet> ?? NONE() !! GREEDY;
return $exp;
}

Expand Down Expand Up @@ -713,7 +712,7 @@ class GGE::Perl6Regex is also {

multi sub perl6exp(GGE::Exp::Subrule $exp is rw, %pad) {
my $cname = $exp.hash-access('cname');
my $isarray = %pad<isarray> // undef;
my $isarray = %pad<isarray>;
if %pad<lexscope>.exists($cname) {
%pad<lexscope>{$cname}.hash-access('isarray') = True;
$isarray = True;
Expand All @@ -725,8 +724,8 @@ class GGE::Perl6Regex is also {

multi sub perl6exp(GGE::Exp::Cut $exp is rw, %pad) {
$exp.hash-access('cutmark') =
$exp.ast eq '::' ?? CUT_GROUP
!! $exp.ast eq ':::' ?? CUT_RULE
$exp.ast eq '::' ?? CUT_GROUP()
!! $exp.ast eq ':::' ?? CUT_RULE()
!! CUT_MATCH;
return $exp;
}
Expand Down Expand Up @@ -772,7 +771,7 @@ class GGE::Perl6Regex is also {
}
}

class GGE::Match is also {
augment class GGE::Match {
multi method before() {
return GGE::Match.new(self); # a failure
}
Expand Down
2 changes: 1 addition & 1 deletion test-regex
@@ -1,4 +1,4 @@
#!/usr/bin/alpha
#!/usr/local/bin/perl6
use v6;
use GGE;

Expand Down

0 comments on commit 839bd22

Please sign in to comment.