Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
allow to run code in P5 regexes
  • Loading branch information
FROGGS committed Aug 19, 2013
1 parent 94b7b28 commit da63d08
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Perl6/Actions.nqp
Expand Up @@ -6396,6 +6396,40 @@ class Perl6::P5RegexActions is QRegex::P5Regex::Actions does STDActions {
$*W.create_signature(nqp::hash('parameters', [])))
}

method p5metachar:sym<(?{ })>($/) {
make QAST::Regex.new( $<codeblock>.ast,
:rxtype<qastnode>, :node($/) );
}

method p5metachar:sym<(??{ })>($/) {
make QAST::Regex.new(
QAST::Node.new(
QAST::SVal.new( :value('INTERPOLATE') ),
$<codeblock>.ast,
QAST::IVal.new( :value(%*RX<i> ?? 1 !! 0) ),
QAST::IVal.new( :value(1) ),
QAST::IVal.new( :value(1) ) ),
:rxtype<subrule>, :subtype<method>, :node($/));
}

method codeblock($/) {
my $blockref := $<block>.ast;
my $past :=
QAST::Stmts.new(
QAST::Op.new(
:op('p6store'),
QAST::Var.new( :name('$/'), :scope<lexical> ),
QAST::Op.new(
QAST::Var.new( :name(''), :scope<lexical> ),
:name('MATCH'),
:op('callmethod')
)
),
QAST::Op.new(:op<call>, $blockref)
);
make $past;
}

method store_regex_nfa($code_obj, $block, $nfa) {
$code_obj.SET_NFA($nfa.save);
}
Expand Down
12 changes: 12 additions & 0 deletions src/Perl6/Grammar.nqp
Expand Up @@ -4053,4 +4053,16 @@ grammar Perl6::RegexGrammar is QRegex::P6Regex::Grammar does STD {

grammar Perl6::P5RegexGrammar is QRegex::P5Regex::Grammar does STD {
token rxstopper { <stopper> }

token p5metachar:sym<(?{ })> {
'(?' <?[{]> <codeblock> ')'
}

token p5metachar:sym<(??{ })> {
'(??' <?[{]> <codeblock> ')'
}

token codeblock {
<block=.LANG('MAIN','block')>
}
}

0 comments on commit da63d08

Please sign in to comment.