Skip to content

Commit

Permalink
Merge branch 'master' into qbootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed May 21, 2012
2 parents 7a76f20 + 31fdcee commit 4bac8c3
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 4 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2012.04.1
2012.05
3 changes: 1 addition & 2 deletions src/QAST/Compiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,7 @@ class QAST::Compiler is HLL::Compiler {
$ops.push(self.regex_post($node[0]));
self.regex_peek($ops, $faillabel, '$I11');
$ops.push($name);
$ops.push_pirop('repr_bind_attr_int', %*REG<cur>, %*REG<curclass>, '"$!pos"', '$I11');
$ops.push_pirop('callmethod', '"!cursor_start"', %*REG<cur>, :result<$P11>);
$ops.push_pirop('callmethod', '"!cursor_start_subcapture"', %*REG<cur>, '$I11', :result<$P11>);
$ops.push_pirop('callmethod', '"!cursor_pass"', '$P11', %*REG<pos>);
$ops.push_pirop('callmethod', '"!cursor_capture"', %*REG<cur>,
'$P11', $name, :result(%*REG<cstack>));
Expand Down
11 changes: 10 additions & 1 deletion src/QRegex/Cursor.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ role NQPCursorRole {

method CAPHASH() {
my $caps := nqp::hash();
my %caplist := $!regexsub.nqpattr('caps');
my %caplist := $!regexsub ?? $!regexsub.nqpattr('caps') !! nqp::hash();
for %caplist {
$caps{~$_} := nqp::list() if %caplist{~$_} >= 2;
}
Expand Down Expand Up @@ -81,6 +81,15 @@ role NQPCursorRole {
)
}

method !cursor_start_subcapture($from) {
my $new := nqp::create(self);
nqp::bindattr($new, $?CLASS, '$!orig', $!orig);
nqp::bindattr_s($new, $?CLASS, '$!target', $!target);
nqp::bindattr_i($new, $?CLASS, '$!from', $from);
nqp::bindattr_i($new, $?CLASS, '$!pos', -3);
$new;
}

method !cursor_capture($capture, $name) {
$!match := nqp::null();
$!cstack := [] unless pir::defined($!cstack);
Expand Down
16 changes: 16 additions & 0 deletions src/QRegex/P6Regex/Actions.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,22 @@ class QRegex::P6Regex::Actions is HLL::Actions {
make $qast;
}

method assertion:sym<|>($/) {
my $qast;
my $name := ~$<identifier>;
if $name eq 'c' {
# codepoint boundaries alway match in
# our current Unicode abstraction level
$qast := 0;
}
elsif $name eq 'w' {
$qast := QAST::Regex.new(:rxtype<subrule>, :subtype<method>,
:node($/), PAST::Node.new('wb'),
:name('') );
}
make $qast;
}

method assertion:sym<method>($/) {
my $qast := $<assertion>.ast;
$qast.subtype('method');
Expand Down
1 change: 1 addition & 0 deletions src/QRegex/P6Regex/Grammar.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {

token assertion:sym<?> { '?' [ <?before '>' > | <assertion> ] }
token assertion:sym<!> { '!' [ <?before '>' > | <assertion> ] }
token assertion:sym<|> { '|' <identifier> }

token assertion:sym<method> {
'.' <assertion>
Expand Down
20 changes: 20 additions & 0 deletions src/Regex/P6Regex/Actions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,26 @@ class Regex::P6Regex::Actions is HLL::Actions {
make $past;
}

method assertion:sym<|>($/) {
my $past;
my $name := ~$<identifier>;
if $name eq 'c' {
# codepoint boundary is always true at our
# current Unicode abstraction level
$past := 0;
}
elsif $name eq 'w' {
$past := PAST::Regex.new(
'wb', :name('wb'),
:pasttype('subrule'), :node($/)
);
}
else {
self.panic("Don't know how to handle zero-width asertion <|$name>");
}
make $past;
}

method assertion:sym<method>($/) {
my $past := $<assertion>.ast;
$past.subtype('method');
Expand Down
1 change: 1 addition & 0 deletions src/Regex/P6Regex/Grammar.pm
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ grammar Regex::P6Regex::Grammar is HLL::Grammar {

token assertion:sym<?> { '?' [ <?before '>' > | <assertion> ] }
token assertion:sym<!> { '!' [ <?before '>' > | <assertion> ] }
token assertion:sym<|> { '|' <identifier> }

token assertion:sym<method> {
'.' <assertion>
Expand Down
2 changes: 2 additions & 0 deletions t/qregex/rx_subrules
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,7 @@ a<!wb> abc\ndef\n-==\nghi y \w\w nonword boundary
<+alpha-[Jj]>+ abc y character class with no j
<+ alpha - [ Jj ]> abc y character class with no j with ws
^<+alpha-[Jj]>+$ aJc n character class with no j fail
^a<|w> a/ y <|w> matches
^a<|w> ab n <|w> without match

## vim: noexpandtab tabstop=4 shiftwidth=4

0 comments on commit 4bac8c3

Please sign in to comment.