Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge remote branch 'origin/mob_pm'
  • Loading branch information
moritz committed May 29, 2010
2 parents 5940b25 + 250adbb commit 3ac2d94
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 3 deletions.
2 changes: 2 additions & 0 deletions build/Makefile.in
Expand Up @@ -136,6 +136,7 @@ BUILTINS_PIR = \
src/builtins/assign.pir \
src/builtins/metaops.pir \
src/builtins/control.pir \
src/builtins/Cursor.pir \

# Make sure parrot cheats are last in this list.
# First parrot cheat must be attriter.pir (to get .HLL),
Expand Down Expand Up @@ -216,6 +217,7 @@ CORE_SOURCES = \
src/core/Date.pm \
src/core/Temporal.pm \
src/core/YOU_ARE_HERE.pm \
src/core/Match.pm \

# SETTING = \
# src/setting/traits.pm \
Expand Down
35 changes: 35 additions & 0 deletions src/builtins/Cursor.pir
@@ -0,0 +1,35 @@
## $Id$

=head1 TITLE

Cursor - Perl 6 cursor objects

=head2 Methods

=over 4

=cut

.namespace [ 'Cursor' ]

.sub 'onload' :anon :init :load
.local pmc p6meta, cursorproto
p6meta = get_hll_global ['Mu'], '$!P6META'
cursorproto = p6meta.'new_class'('Cursor', 'parent'=>'parrot;Regex::Cursor Any')
.end


.sub 'new_match' :method
$P0 = new ['Match']
.return ($P0)
.end

=back

=cut

# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir:
4 changes: 2 additions & 2 deletions src/core/Cool-str.pm
Expand Up @@ -216,7 +216,7 @@ augment class Cool {

my $taken = 0;
my $i = 1;
my @r = gather while my $m = Regex::Cursor.parse(self, :rule($pat), |%opts) {
my @r = gather while my $m = Cursor.parse(self, :rule($pat), |%opts) {
my $m-copy = $m;
if !$nth.defined || $i == $next-index {
take $m-copy;
Expand Down Expand Up @@ -249,7 +249,7 @@ augment class Cool {
}
return |@r;
} else {
Regex::Cursor.parse(self, :rule($pat), |%opts);
Cursor.parse(self, :rule($pat), |%opts);
}
}
multi method match($pat, *%options) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/Grammar.pm
@@ -1,4 +1,4 @@
class Grammar is Regex::Cursor {
class Grammar is Cursor {
method parsefile($file, *%options) {
my $fh = open($file, :r)
|| die "$file: $!";
Expand Down
35 changes: 35 additions & 0 deletions src/core/Match.pm
@@ -0,0 +1,35 @@
class Match is Regex::Match is Cool does Associative {
multi method postcircumfix:<{ }>($key) {
Q:PIR {
$P0 = find_lex 'self'
$P1 = find_lex '$key'
%r = $P0[$P1]
unless null %r goto done
%r = new ['Proxy']
setattribute %r, '$!base', $P0
setattribute %r, '$!key', $P1
done:
}
}

# We shouldn't need to provide this -- we should be able to
# simply write "does Positional" in the class declaration
# and it would provide us the postcircumfix:<[ ]> methods
# for free. But there seems to be a bug or problem in the
# role composer that prevents us from having both "does Positional"
# and "does Associative" in the class declaration, so we'll
# provide the simple .[] for now.
multi method postcircumfix:<[ ]>(Int $key) {
Q:PIR {
$P0 = find_lex 'self'
$P1 = find_lex '$key'
$I1 = $P1
%r = $P0[$I1]
unless null %r goto done
%r = new ['Proxy']
setattribute %r, '$!base', $P0
setattribute %r, '$!key', $P1
done:
}
}
}

0 comments on commit 3ac2d94

Please sign in to comment.