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

Commit

Permalink
Determine regex name to be used for action methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 15, 2009
1 parent 468b4eb commit 0c574ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
23 changes: 18 additions & 5 deletions src/PAST/Compiler-Regex.pir
Expand Up @@ -39,6 +39,13 @@ Return the POST representation of the regex AST rooted by C<node>.
reghash = new ['Hash']
.lex '$*REG', reghash

.local pmc regexname
$P0 = get_global '@?BLOCK'
$P1 = $P0[0]
$S0 = $P1.'name'()
regexname = box $S0
.lex '$*REGEXNAME', regexname

.local string prefix, rname, rtype
prefix = self.'unique'('rx')
concat prefix, '_'
Expand Down Expand Up @@ -627,8 +634,13 @@ second child of this node.
.local pmc cur, pos, ops
(cur, pos) = self.'!rxregs'('cur pos')
ops = self.'post_new'('Ops', 'node'=>node, 'result'=>cur)

.local string regexname
$P0 = find_dynamic_lex '$*REGEXNAME'
regexname = self.'escape'($P0)

ops.'push_pirop'('inline', 'inline'=>' # rx pass')
self.'!cursorop'(ops, '!cursor_pass', 0, pos, '""')
self.'!cursorop'(ops, '!cursor_pass', 0, pos, regexname)
ops.'push_pirop'('return', cur)
.return (ops)
.end
Expand All @@ -648,14 +660,15 @@ second child of this node.
.local pmc cpost, posargs, namedargs
(cpost, posargs, namedargs) = self.'post_children'(node, 'signature'=>'v:')

.local string name, key
name = '""'
.local string regexname, key
$P0 = find_dynamic_lex '$*REGEXNAME'
regexname = self.'escape'($P0)
key = posargs[0]

ops.'push_pirop'('inline', name, key, 'inline'=>' # rx reduce name=%0 key=%1')
ops.'push_pirop'('inline', regexname, key, 'inline'=>' # rx reduce name=%0 key=%1')
ops.'push'(cpost)
self.'!cursorop'(ops, '!cursor_pos', 0, pos)
self.'!cursorop'(ops, '!reduce', 0, name, posargs :flat, namedargs :flat)
self.'!cursorop'(ops, '!reduce', 0, regexname, posargs :flat, namedargs :flat)
.return (ops)
.end

Expand Down
3 changes: 2 additions & 1 deletion src/Regex/P6Regex/Actions.pm
Expand Up @@ -8,7 +8,8 @@ our @MODIFIERS := Q:PIR {
};
method TOP($/) {
make buildsub( $<nibbler>.ast );
my $past := buildsub( $<nibbler>.ast );
make $past;
}

method nibbler($/, $key?) {
Expand Down

0 comments on commit 0c574ea

Please sign in to comment.