Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
[nqp]: Add code assertions to nqp.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 29, 2009
1 parent 7c48517 commit 88ab936
Show file tree
Hide file tree
Showing 6 changed files with 10,511 additions and 9,453 deletions.
27 changes: 27 additions & 0 deletions src/NQP/Actions.pm
Expand Up @@ -369,6 +369,8 @@ method regex_declarator($/, $key?) {
$P0 = find_lex '$name'
set_hll_global ['Regex';'P6Regex';'Actions'], '$REGEXNAME', $P0
};
@BLOCK[0].symbol('$¢', :scope('lexical'));
@BLOCK[0].symbol('$/', :scope('lexical'));
return 0;
}
elsif $<proto> {
Expand Down Expand Up @@ -557,4 +559,29 @@ class NQP::RegexActions is Regex::P6Regex::Actions {
make PAST::Regex.new( $past, :pasttype('pastnode') );
}

method metachar:sym<{ }>($/) { make $<codeblock>.ast; }

method assertion:sym<{ }>($/) { make $<codeblock>.ast; }

method codeblock($/) {
my $block := $<block>.ast;
$block.blocktype('immediate');
my $past :=
PAST::Regex.new(
PAST::Stmts.new(
PAST::Op.new(
PAST::Var.new( :name('$/') ),
PAST::Op.new(
PAST::Var.new( :name('') ),
:name('MATCH'),
:pasttype('callmethod')
),
:pasttype('bind')
),
$block
),
:pasttype('pastnode')
);
make $past;
}
}
12 changes: 12 additions & 0 deletions src/NQP/Grammar.pm
Expand Up @@ -371,4 +371,16 @@ grammar NQP::Regex is Regex::P6Regex::Grammar {
token metachar:sym<:my> {
':' <?before 'my'> <statement=LANG('MAIN', 'statement')> <.ws> ';'
}

token metachar:sym<{ }> {
<?[{]> <codeblock>
}

token assertion:sym<{ }> {
<?[{]> <codeblock>
}

token codeblock {
<block=LANG('MAIN','pblock')>
}
}
23 changes: 21 additions & 2 deletions src/PAST/Compiler-Regex.pir
Expand Up @@ -127,6 +127,8 @@ Return the POST representation of the regex AST rooted by C<node>.
caparray_skip:

ops.'push_pirop'('.lex', 'unicode:"$\x{a2}"', cur)
ops.'push_pirop'('.local pmc', 'match')
ops.'push_pirop'('.lex', '"$/"', 'match')
ops.'push_pirop'('length', eos, tgt, 'result'=>eos)

# On Parrot, indexing into variable-width encoded strings
Expand Down Expand Up @@ -735,8 +737,25 @@ second child of this node.

.sub 'pastnode' :method :multi(_, ['PAST';'Regex'])
.param pmc node
$P0 = node[0]
.tailcall self.'as_post'($P0)
.local pmc cur, pos, fail, ops
(cur, pos, fail) = self.'!rxregs'('cur pos fail')
ops = self.'post_new'('Ops', 'node'=>node, 'result'=>cur)

.local pmc cpast, cpost
cpast = node[0]
cpost = self.'as_post'(cpast, 'rtype'=>'P')

self.'!cursorop'(ops, '!cursor_pos', 0, pos)
ops.'push'(cpost)

.local pmc subtype, negate, testop
subtype = node.'subtype'()
if subtype != 'zerowidth' goto done
negate = node.'negate'()
testop = self.'??!!'(negate, 'if', 'unless')
ops.'push_pirop'(testop, cpost, fail)
done:
.return (ops)
.end


Expand Down

0 comments on commit 88ab936

Please sign in to comment.