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

Commit

Permalink
Refactor subrule matching a bit.
Browse files Browse the repository at this point in the history
Correct Cursor-builtins to use new !cursor_pass method.
<alpha> matches underscore.
Update specialized dump_str method to check for new Match objects.
  • Loading branch information
pmichaud committed Oct 12, 2009
1 parent a8a7999 commit a0c9610
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 36 deletions.
25 changes: 8 additions & 17 deletions src/PAST/Compiler-Regex.pir
Expand Up @@ -793,28 +793,19 @@ Perform a subrule call.
negate = node.'negate'()
testop = self.'??!!'(negate, 'if', 'unless')

.local pmc zerowidth
zerowidth = node.'zerowidth'()

.local pmc bindpast, bindpost
bindpast = node.'bindnames'()
unless bindpast goto bindpost_done
bindpost = self.'as_post'(bindpast, 'rtype'=>'*')
bindpost_done:
.local pmc subtype
subtype = node.'subtype'()

ops.'push_pirop'('inline', name, negate, zerowidth, 'inline'=>" # rx subrule %0 negate=%1 zerowidth=%2")
ops.'push_pirop'('inline', name, subtype, negate, 'inline'=>" # rx subrule %0 subtype=%1 negate=%2")

self.'!cursorop'(ops, '!cursor_pos', 0, pos)
ops.'push_pirop'('callmethod', name, cur, 'result'=>'$P10')
ops.'push_pirop'(testop, '$P10', fail)
unless bindpast goto bindnames_done
ops.'push'(bindpost)
self.'!cursorop'(ops, '!cursor_names', 0, bindpost)
bindnames_done:
if zerowidth goto zerowidth_done
ops.'push_pirop'('callmethod', "'pos'", '$P10', 'result'=>pos)
zerowidth_done:

if subtype == 'zerowidth' goto done
ops.'push_pirop'('callmethod', '"pos"', '$P10', 'result'=>pos)
self.'!cursorop'(ops, '!mark_push', 0, 0, -1, 0, '$P10')
if subtype == 'method' goto done
ops.'push_pirop'('callmethod', '"!cursor_names"', '$P10', name)
done:
.return (ops)
.end
Expand Down
8 changes: 1 addition & 7 deletions src/PAST/Regex.pir
Expand Up @@ -20,20 +20,14 @@ for regular expressions.
p6meta.'new_class'('PAST::Regex', 'parent'=>'PAST::Node')
.end
.sub 'backtrack' :method
.param pmc value :optional
.param int has_value :opt_flag
.tailcall self.'attr'('backtrack', value, has_value)
.end
.sub 'bindnames' :method
.param pmc value :optional
.param int has_value :opt_flag
.tailcall self.'attr'('bindnames', value, has_value)
.end
.sub 'negate' :method
.param pmc value :optional
.param int has_value :opt_flag
Expand Down
16 changes: 14 additions & 2 deletions src/Regex/Cursor-builtins.pir
Expand Up @@ -21,13 +21,25 @@ Regex::Cursor-builtins - builtin regexes for Cursor objects
$I0 = is_cclass cclass, tgt, pos
unless $I0 goto fail
inc pos
cur.'!matchify'(name, 'pos'=>pos)
cur.'!cursor_pass'(pos, name)
fail:
.return (cur)
.end

.sub 'alpha' :method
.tailcall self.'!cclass'('alpha', .CCLASS_ALPHABETIC)
.local pmc cur
.local int pos
.local string tgt
(cur, pos, tgt) = self.'!cursor_start'()
$I0 = is_cclass .CCLASS_ALPHABETIC, tgt, pos
if $I0 goto pass
$S0 = substr tgt, pos, 1
if $S0 != '_' goto fail
pass:
inc pos
cur.'!cursor_pass'(pos, 'alpha')
fail:
.return (cur)
.end

.sub 'digit' :method
Expand Down
4 changes: 2 additions & 2 deletions src/Regex/Cursor.pir
Expand Up @@ -73,7 +73,7 @@ for the Cursor if one hasn't been created yet.
# If the subcursor isn't bound with a name, skip it
subnames = getattribute subcur, '$!names'
if null subnames goto cstack_loop
match = subcur.'MATCH'()
submatch = subcur.'MATCH'()
match[subnames] = submatch
goto cstack_loop
cstack_done:
Expand Down Expand Up @@ -229,7 +229,7 @@ Set the Cursor's name (for binding) to names.
=cut
=sub '!cursor_names' :method
.sub '!cursor_names' :method
.param pmc names
setattribute self, '$!names', names
.end
Expand Down
4 changes: 2 additions & 2 deletions src/Regex/Dumper.pir
Expand Up @@ -3,7 +3,7 @@

=head1 TITLE

Regex::Dumper - various methods for displaying PGE structures
Regex::Dumper - various methods for displaying Match structures

=head2 C<Regex::Match> Methods

Expand Down Expand Up @@ -159,7 +159,7 @@ An alternate dump output for a Match object and all of its subcaptures.
goto subrules_1

dumper:
$I0 = isa $P0, ['PGE';'Match']
$I0 = isa $P0, ['Regex';'Match']
unless $I0 goto dumper_0
$S0 = $P0.'dump_str'(prefix1, b1, b2)
out .= $S0
Expand Down
13 changes: 9 additions & 4 deletions src/Regex/P6Regex/Actions.pm
Expand Up @@ -201,20 +201,25 @@ method backslash:sym<misc>($/) {

method assertion:sym<?>($/) {
my $past := $<assertion>.ast;
$past.zerowidth(1);
$past.subtype('zerowidth');
make $past;
}

method assertion:sym<!>($/) {
my $past := $<assertion>.ast;
$past.negate( !$past.negate );
$past.zerowidth(1);
$past.subtype('zerowidth');
make $past;
}

method assertion:sym<method>($/) {
my $past := $<assertion>.ast;
$past.subtype('method');
make $past;
}

method assertion:sym<name>($/) {
my $past := PAST::Regex.new( :name(~$<longname>) , :pasttype('subrule'),
:bindnames(~$<longname>) );
my $past := PAST::Regex.new( :name(~$<longname>) , :pasttype('subrule') );
make $past;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Regex/P6Regex/Grammar.pm
Expand Up @@ -91,7 +91,7 @@ grammar Regex::P6Regex::Grammar is PCT::Grammar;
token assertion:sym<!> { '!' [ <?before '>' > | <assertion> ] {*} }

token assertion:sym<method> {
'.' <assertion>
'.' <assertion> {*}
}

token assertion:sym<name> {
Expand Down
2 changes: 1 addition & 1 deletion t/p6regex/01-regex.t
Expand Up @@ -76,7 +76,7 @@ Description of the test.
push test_files, 'rx_quantifiers'
# push test_files, 'rx_backtrack'
push test_files, 'rx_charclass'
# push test_files, 'rx_subrules'
push test_files, 'rx_subrules'
# push test_files, 'rx_lookarounds'
# push test_files, 'rx_captures'
# push test_files, 'rx_modifiers'
Expand Down

0 comments on commit a0c9610

Please sign in to comment.