Skip to content
Browse files

First crack at <~~> in regexes. Note that <~~0> and <~~beer> are NYI,…

… and are probably compiled a bit differently.
  • Loading branch information...
1 parent 1e35759 commit 22c12b0cffa05d999fbf84b83eeb551922860ed5 @jnthn jnthn committed May 16, 2012
Showing with 33 additions and 0 deletions.
  1. +1 −0 docs/ChangeLog
  2. +23 −0 src/Perl6/Actions.pm
  3. +5 −0 src/Perl6/Grammar.pm
  4. +4 −0 src/core/Cursor.pm
View
1 docs/ChangeLog
@@ -35,6 +35,7 @@ New in 2012.05
+ fixed a bug in precompilation of modules that use roles from other modules
+ basic implementation of pack and unpack
+ implemented substr-rw, which provides an l-value (assignable) substring
++ implemented <~~> (recursive call into self) syntax in regexes
New in 2012.04.1
+ autvivification for arrays and hashes
View
23 src/Perl6/Actions.pm
@@ -2212,6 +2212,16 @@ class Perl6::Actions is HLL::Actions {
}
$past.name($name);
$past.blocktype("declaration");
+
+ # Install a $?REGEX (mostly for the benefit of <~~>).
+ $block[0].push(PAST::Op.new(
+ :pasttype('bind'),
+ PAST::Var.new(:name<$?REGEX>, :scope<lexical_6model>, :isdecl(1)),
+ PAST::Op.new(
+ :pirop('perl6_code_object_from_parrot_sub PP'),
+ PAST::Op.new( :pirop('set PQs'), PAST::Op.new( :pirop('getinterp P') ), 'sub')
+ )));
+ $block.symbol('$?REGEX', :scope<lexical_6model>);
# Do the various tasks to turn the block into a method code object.
my $inv_type := $*W.find_symbol([ # XXX Maybe Cursor below, not Mu...
@@ -5348,6 +5358,19 @@ class Perl6::RegexActions is QRegex::P6Regex::Actions {
make $qast;
}
+ method assertion:sym<~~>($/) {
+ if $<num> {
+ pir::die('Sorry, ~~ regex assertion with a capture is not yet implemented');
+ }
+ elsif $<desigilname> {
+ pir::die('Sorry, ~~ regex assertion with a capture is not yet implemented');
+ }
+ else {
+ make QAST::Regex.new( :rxtype<subrule>, :subtype<method>,
+ PAST::Node.new('RECURSE'), :node($/) );
+ }
+ }
+
method codeblock($/) {
my $blockref := $<block>.ast;
my $past :=
View
5 src/Perl6/Grammar.pm
@@ -2880,6 +2880,11 @@ grammar Perl6::RegexGrammar is QRegex::P6Regex::Grammar {
token assertion:sym<var> {
<?[$@&]> <var=.LANG('MAIN', 'variable')>
}
+
+ token assertion:sym<~~> {
+ <sym>
+ [ <?before '>'> | $<num>=[\d+] | <desigilname=.LANG('MAIN','desigilname')> ]
+ }
token codeblock {
<block=.LANG('MAIN','block')>
View
4 src/core/Cursor.pm
@@ -72,6 +72,10 @@ my class Cursor does NQPCursorRole {
$lang_cursor."$name"();
}
+ method RECURSE() {
+ pir::find_dynamic_lex__Ps('$?REGEX')(self)
+ }
+
method prior() {
nqp::isconcrete($last_match) ??
self."!LITERAL"(nqp::unbox_s(~$last_match)) !!

0 comments on commit 22c12b0

Please sign in to comment.
Something went wrong with that request. Please try again.