diff --git a/build/Makefile.in b/build/Makefile.in index 6b9ca362229..4964305c892 100644 --- a/build/Makefile.in +++ b/build/Makefile.in @@ -195,6 +195,7 @@ CORE_SOURCES = \ src/core/Regex.pm \ src/core/Junction.pm \ src/core/Grammar.pm \ + src/core/Substitution.pm \ src/core/system.pm \ src/cheats/match-bool.pm \ src/cheats/setup-io.pm \ diff --git a/src/Perl6/Actions.pm b/src/Perl6/Actions.pm index 3c05f69ad88..a96f3155a5e 100644 --- a/src/Perl6/Actions.pm +++ b/src/Perl6/Actions.pm @@ -2132,6 +2132,30 @@ method quote:sym($/) { make create_code_object($past, 'Regex', 0, ''); } +method quote:sym($/) { + # Build the regex. + my $regex_ast := Regex::P6Regex::Actions::buildsub($.ast); + my $regex := create_code_object($regex_ast, 'Regex', 0, ''); + + # Quote needs to be closure-i-fied. + my $closure_ast := PAST::Block.new( + PAST::Stmts.new(), + PAST::Stmts.new( + $.ast + ) + ); + my $closure := create_code_object($closure_ast, 'Block', 0, ''); + + # Make a Substitution. + $regex.named('matcher'); + $closure.named('replacer'); + make PAST::Op.new( + :pasttype('callmethod'), :name('new'), + PAST::Var.new( :name('Substitution'), :scope('package') ), + $regex, $closure + ); +} + method quote_escape:sym<$>($/) { #make $.ast; # my $a = 3; say "$a".WHAT # Gives Int, not Str with the above. Force diff --git a/src/Perl6/Grammar.pm b/src/Perl6/Grammar.pm index 2492e2476db..c1466b77b3e 100644 --- a/src/Perl6/Grammar.pm +++ b/src/Perl6/Grammar.pm @@ -989,7 +989,13 @@ token quote:sym { | '{''}' ] } - +token quote:sym { + >> + '/' + + + +} token quote_escape:sym<$> { } token quote_escape:sym<{ }> { } diff --git a/src/core/Substitution.pm b/src/core/Substitution.pm new file mode 100644 index 00000000000..935216ec754 --- /dev/null +++ b/src/core/Substitution.pm @@ -0,0 +1,8 @@ +class Substitution { + has $!matcher; + has $!replacer; + + method ACCEPTS($topic is rw) { + $topic = $topic.subst($!matcher, $!replacer); + } +} diff --git a/src/core/operators.pm b/src/core/operators.pm index 4ac2d3bfee3..51251a78cea 100644 --- a/src/core/operators.pm +++ b/src/core/operators.pm @@ -11,6 +11,12 @@ our multi infix:<~~>(Mu $topic, Regex $matcher) { }; } +class Substitution { ... } +our multi infix:<~~>(Mu $topic is rw, Substitution $matcher) { + $matcher.ACCEPTS($topic) +} + + our multi infix:(Mu $topic, Mu $matcher) { $matcher.REJECTS($topic) }