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

Commit

Permalink
Browse files Browse the repository at this point in the history
Add cut-rule token.
  • Loading branch information
pmichaud committed Oct 13, 2009
1 parent bdc43da commit 1987a95
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/PAST/Compiler-Regex.pir
Expand Up @@ -485,6 +485,24 @@ Handle a concatenation of regexes.
.end


=item cut(PAST::Regex node)

Generate POST for the cut-group and cut-rule operators.

=cut

.sub 'cut' :method :multi(_, ['PAST';'Regex'])
.param pmc node

.local pmc cur, fail, ops
(cur, fail) = self.'!rxregs'('cur fail')
ops = self.'post_new'('Ops', 'node'=>node, 'result'=>cur)
ops.'push_pirop'('set_addr', '$I10', fail)
self.'!cursorop'(ops, '!mark_commit', 0, '$I10')
.return (ops)
.end


=item enumcharlist(PAST::Regex node)

Generate POST for matching a character from an enumerated
Expand Down
6 changes: 5 additions & 1 deletion src/Regex/P6Regex/Actions.pm
Expand Up @@ -42,7 +42,6 @@ method termish($/) {
$lastlit := $ast.pasttype eq 'literal' ?? $ast !! 0;
}
}
if +$past.list == 1 { $past := $past[0]; }
make $past;
}

Expand Down Expand Up @@ -150,6 +149,11 @@ method metachar:sym<$$>($/) {
make $past;
}

method metachar:sym<:::>($/) {
my $past := PAST::Regex.new( :pasttype('cut') );
make $past;
}

method metachar:sym<lwb>($/) {
my $past := PAST::Regex.new( :pasttype('anchor'), :subtype('lwb') );
make $past;
Expand Down
2 changes: 2 additions & 0 deletions src/Regex/P6Regex/Grammar.pm
Expand Up @@ -64,6 +64,8 @@ grammar Regex::P6Regex::Grammar is PCT::Grammar;
token metachar:sym<^^> { $<sym>=['^^'] {*} }
token metachar:sym<$> { $<sym>=['$'] {*} }
token metachar:sym<$$> { $<sym>=['$$'] {*} }
token metachar:sym<:::> { $<sym>=[':::'] {*} }
token metachar:sym<::> { $<sym>=['::'] {*} }
token metachar:sym<lwb> { $<sym>=['<<'|'«'] {*} }
token metachar:sym<rwb> { $<sym>=['>>'|'»'] {*} }
token metachar:sym<bs> { \\ <backslash> {*} }
Expand Down
2 changes: 1 addition & 1 deletion t/p6regex/01-regex.t
Expand Up @@ -74,7 +74,7 @@ Description of the test.
push test_files, 'rx_basic'
push test_files, 'rx_metachars'
push test_files, 'rx_quantifiers'
# push test_files, 'rx_backtrack'
push test_files, 'rx_backtrack'
push test_files, 'rx_charclass'
push test_files, 'rx_subrules'
# push test_files, 'rx_lookarounds'
Expand Down

0 comments on commit 1987a95

Please sign in to comment.