Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[v6] Add enum support
  • Loading branch information
sorear committed Nov 16, 2010
1 parent 6ca0209 commit 78407bb
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions v6/tryfile
Expand Up @@ -6,10 +6,38 @@ use Stash;
use NAME;
use JSYNC;

sub first(\$x) { for $x -> $elt { return $elt }; Any }
sub infix:<max>($a,$b) { $a < $b ?? $b !! $a }
sub infix:<min>($a,$b) { $a > $b ?? $b !! $a }

augment class List {
method shift() { self!fill(1) ?? self!shift-item !! Any }
}

augment class Mu {
method typename() { # should be ^name
Q:CgOp { (box Str (obj_typename (@ {self}))) }
}
}
augment class Cool {
method comb($rx) {
my $str = self.Str;
my $C = Cursor.new($str);
my $i = 0;
my @out;
while $i < $str.chars {
my $M = first($rx($C.cursor($i++)));
if $M {
$i max= $M.to;
push @out, $M.Str;
} else {
}
}
@out
}
}
augment class Any {
method list() { @( self, ) }
}
Expand All @@ -22,7 +50,6 @@ augment class NAME {
}
augment class Regex {
sub first(\$x) { for $x -> $elt { return $elt }; Any }
method ACCEPTS($st) {
my $i = 0;
my $str = $st.Str;
Expand Down Expand Up @@ -211,8 +238,6 @@ augment class STD::P6 {
}
}
sub infix:<min>($a,$b) { $a > $b ?? $b !! $a }

augment class Cursor {
my %term = (:dba('term') , :prec<z=>);
my %methodcall = (:dba('methodcall') , :prec<y=>, :assoc<unary>, :uassoc<left>, :fiddly, :!pure);
Expand Down Expand Up @@ -296,6 +321,20 @@ my %terminator = (:dba('terminator') , :prec<a=>, :assoc<list>);
self.cursor_fresh(%*LANG<MAIN>);
}
method add_enum($type,$expr) {
return unless $type;
return unless $expr;
my $typename = $type.Str;
my $*IN_DECL ::= 'constant';
# XXX complete kludge, really need to eval EXPR
# $expr =~ s/:(\w+)<\S+>/$1/g; # handle :name<string>
for $expr.comb(/ <[ a..z A..Z _ ]> \w* /) -> $n {
self.add_name($typename ~ "::$n");
self.add_name($n);
}
self
}
method canonicalize_name($n) {
my $M;
my $name = $n;
Expand Down

0 comments on commit 78407bb

Please sign in to comment.