Permalink
Browse files

Implement <( and )>.

  • Loading branch information...
1 parent cc71885 commit 04b180961addd24b636e86cb3a8a0d34353d6a4b @jnthn jnthn committed May 12, 2012
Showing with 37 additions and 0 deletions.
  1. +10 −0 src/Perl6/Actions.pm
  2. +3 −0 src/Perl6/Grammar.pm
  3. +24 −0 src/core/Cursor.pm
View
@@ -5212,6 +5212,16 @@ class Perl6::RegexActions is QRegex::P6Regex::Actions {
}
make $qast;
}
+
+ method metachar:sym<from>($/) {
+ make QAST::Regex.new( :rxtype<subrule>, :subtype<method>,
+ PAST::Node.new('MARK_FROM'), :node($/) );
+ }
+
+ method metachar:sym<to>($/) {
+ make QAST::Regex.new( :rxtype<subrule>, :subtype<method>,
+ PAST::Node.new('MARK_TO'), :node($/) );
+ }
method metachar:sym<rakvar>($/) {
make QAST::Regex.new( PAST::Node.new('INTERPOLATE', $<var>.ast,
View
@@ -2863,6 +2863,9 @@ grammar Perl6::RegexGrammar is QRegex::P6Regex::Grammar {
<quote_EXPR: ':q', ':w'>
}
+ token metachar:sym<from> { '<(' }
+ token metachar:sym<to> { ')>' }
+
token assertion:sym<{ }> {
<?[{]> <codeblock>
}
View
@@ -5,6 +5,24 @@ my class Cursor does NQPCursorRole {
trusts Regex;
my $last_match;
method !set_last_match($m) { $last_match = $m }
+
+ # For <( and )>
+ has $!explicit_from;
+ has $!explicit_to;
+ method MARK_FROM() {
+ my int $pos = nqp::getattr_i(self, Cursor, '$!pos');
+ $!explicit_from = $pos;
+ my $cur := self.'!cursor_start'();
+ $cur.'!cursor_pass'($pos);
+ $cur
+ }
+ method MARK_TO() {
+ my int $pos = nqp::getattr_i(self, Cursor, '$!pos');
+ $!explicit_to = $pos;
+ my $cur := self.'!cursor_start'();
+ $cur.'!cursor_pass'($pos);
+ $cur
+ }
method MATCH() {
my $match := nqp::getattr(self, Cursor, '$!match');
@@ -30,6 +48,12 @@ my class Cursor does NQPCursorRole {
?? nqp::bindpos($list, $key, $value)
!! nqp::bindkey($hash, $key, $value);
}
+ if $!explicit_from.DEFINITE {
+ nqp::bindattr($match, Match, '$!from', $!explicit_from);
+ }
+ if $!explicit_to.DEFINITE {
+ nqp::bindattr($match, Match, '$!to', $!explicit_to);
+ }
}
nqp::bindattr($match, Capture, '$!list', $list);
nqp::bindattr($match, Capture, '$!hash', $hash);

0 comments on commit 04b1809

Please sign in to comment.