Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

implement Match.ast and &make

This involves caching Match objects in Cursor.MATCH, because otherwise
the $/ that is passed to an action method is not the same as the one
returned from a match, thus $.ast is lost
  • Loading branch information...
commit 7411261e90ba9f2f5c625ffd6e5d722e48fbfc1a 1 parent b007943
@moritz moritz authored
View
7 docs/announce/2011.09
@@ -52,11 +52,8 @@ release include:
* a new regex engine
We briefly regress on a few features since the previous release.
-Most notably, the following features are not yet implemented in the
-new regex engine, and thus not yet available to the user:
-
-* proto regexes
-* make() and $/.ast
+Most notably, new regex engine has not implemented proto regexes
+yet, and only integer-based enums are available.
For a more detailed list of changes, see "docs/ChangeLog".
View
7 src/core/Cursor.pm
@@ -1,6 +1,8 @@
-my class Cursor does NQPCursorRole {
+my class Cursor does NQPCursorRole {
method MATCH() {
- my $match := Match.new(
+ my $match := nqp::getattr(self, Cursor, '$!match');
+ return $match if pir::type_check__IPP($match, Match) && $match.defined;
+ $match := Match.new(
orig => nqp::getattr(self, Cursor, '$!orig'),
from => nqp::p6box_i(nqp::getattr_i(self, Cursor, '$!from')),
to => nqp::p6box_i(nqp::getattr_i(self, Cursor, '$!pos')),
@@ -24,6 +26,7 @@ my class Cursor does NQPCursorRole {
}
nqp::bindattr($match, Capture, '$!list', $list);
nqp::bindattr($match, Capture, '$!hash', $hash);
+ nqp::bindattr(self, Cursor, '$!match', $match);
$match;
}
View
11 src/core/Match.pm
@@ -3,6 +3,7 @@ my class Match is Capture {
has $.from;
has $.to;
has $.CURSOR;
+ has $.ast;
multi method gist(Match:D:) {
$!to > $!from ?? $!orig.substr($!from, $!to-$!from) !! ''
@@ -51,3 +52,13 @@ my class Match is Capture {
}
}
}
+
+sub make(Mu $ast) {
+ nqp::bindattr(
+ pir::perl6_decontainerize__PP(pir::find_caller_lex__Ps('$/')),
+ Match,
+ '$!ast',
+ $ast
+ );
+}
+
View
2  t/spectest.data
@@ -232,7 +232,7 @@ S05-capture/caps.t
S05-capture/match-object.t
# S05-capture/named.t # err: Method 'rxtype' not found for invocant of class 'PAST;Regex'
# S05-capture/subrule.t # err: Method 'rxtype' not found for invocant of class 'PAST;Regex'
-# S05-grammar/action-stubs.t # err: Null PMC access in set_pmc_keyed()
+S05-grammar/action-stubs.t
# S05-grammar/inheritance.t # err: Null PMC access in set_pmc_keyed()
S05-grammar/methods.t
# S05-grammar/namespace.t # err: Null PMC access in set_pmc_keyed()
Please sign in to comment.
Something went wrong with that request. Please try again.