Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[nrx] Resore lookahead assertions
  • Loading branch information
sorear committed Sep 6, 2010
1 parent 2eff169 commit cdc7790
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 50 deletions.
1 change: 1 addition & 0 deletions src/CodeGen.pm
Expand Up @@ -67,6 +67,7 @@ use 5.010;
OpenQuant => [m => 'Void'],
CloseQuant => [m => 'Int32'],
CommitGroup => [m => 'Void'],
CommitGroupZW => [m => 'Void'],
GetCursorList => [m => 'Variable'],
LTMPushAlts => [m => 'Void'],
PushCursorList => [m => 'Void'],
Expand Down
3 changes: 2 additions & 1 deletion src/Niecza/Actions.pm
Expand Up @@ -593,7 +593,8 @@ sub metachar__S_Double_Double { my ($cl, $M) = @_;

sub rxcapturize { my ($cl, $name, $rxop) = @_;
if (!$rxop->isa('RxOp::Subrule')) {
die '$<foo> = [bar] NYI';
# <before>, etc. Not yet really handled XXX
return $rxop;
}

my @extra = map { $_ => $rxop->$_ } qw/zyg arglist name/;
Expand Down
72 changes: 49 additions & 23 deletions src/RxOp.pm
Expand Up @@ -219,16 +219,25 @@ use CgOp;
use Moose;
extends 'RxOp';

sub op {
my ($self, $cn, $cont) = @_;
sub code {
my ($self, $body) = @_;

my $icn = Niecza::Actions->gensym;
$icn, Op::CallSub->new(
invocant => Op::Lexical->new(name => '&_rxbefore'),
positionals => [
Op::Lexical->new(name => $icn),
$self->_close_op($self->zyg->[0]),
$self->_close_k($cn, $cont)]);
my $fail = $self->label;
my $pass = $self->label;
my @code;
push @code, CgOp::rxpushb("CUTGRP", $pass);
push @code, CgOp::rxpushb("CUTGRP", $fail);
push @code, $self->zyg->[0]->code($body);
push @code, CgOp::rawcall(CgOp::rxframe, 'CommitGroup',
CgOp::clr_string("CUTGRP"), CgOp::clr_string("ENDCUTGRP"));
push @code, CgOp::rawccall(CgOp::rxframe, 'Backtrack');
push @code, CgOp::label($fail);
push @code, CgOp::rawcall(CgOp::rxframe, 'CommitGroup',
CgOp::clr_string("CUTGRP"), CgOp::clr_string("ENDCUTGRP"));
push @code, CgOp::rawccall(CgOp::rxframe, 'Backtrack');
push @code, CgOp::label($pass);

@code;
}

sub lad {
Expand All @@ -246,16 +255,19 @@ use CgOp;
use Moose;
extends 'RxOp';

sub op {
my ($self, $cn, $cont) = @_;
sub code {
my ($self, $body) = @_;

my $pass = $self->label;
my @code;
push @code, CgOp::rxpushb("CUTGRP", $pass);
push @code, $self->zyg->[0]->code($body);
push @code, CgOp::rawcall(CgOp::rxframe, 'CommitGroup',
CgOp::clr_string("CUTGRP"), CgOp::clr_string("ENDCUTGRP"));
push @code, CgOp::rawccall(CgOp::rxframe, 'Backtrack');
push @code, CgOp::label($pass);

my $icn = Niecza::Actions->gensym;
$icn, Op::CallSub->new(
invocant => Op::Lexical->new(name => '&_rxnotbefore'),
positionals => [
Op::Lexical->new(name => $icn),
$self->_close_op($self->zyg->[0]),
$self->_close_k($cn, $cont)]);
@code;
}

sub lad {
Expand All @@ -274,15 +286,29 @@ use CgOp;

has name => (isa => 'Str', is => 'ro', required => 1);
has captures => (isa => 'ArrayRef[Maybe[Str]]', is => 'ro', default => sub { [] });
has arglist => (isa => 'ArrayRef[Op]', is => 'ro');
has arglist => (isa => 'Maybe[ArrayRef[Op]]', is => 'ro');

sub true {
my ($self) = @_;
# all not quite right in the capturey case
if ($self->name eq 'sym') {
return RxOp::String->new(text => $::symtext);
}
if ($self->name eq 'before') {
return RxOp::Before->new(zyg => $self->zyg);
}
if ($self->name eq 'after') {
return RxOp::After->new(zyg => $self->zyg);
}
}

sub code {
my ($self, $body) = @_;
my $bt = $self->label;
my $sk = $self->label;

if ($self->name eq 'sym') {
return RxOp::String->new(text => $::symtext)->code($body);
if (my $true = $self->true) {
return $true->code($body);
}

my @code;
Expand All @@ -307,8 +333,8 @@ use CgOp;

sub lad {
my ($self) = @_;
if ($self->name eq 'sym') {
return CgOp::rawnew('LADStr', CgOp::clr_string($::symtext));
if (my $true = $self->true) {
return $true->lad;
}
CgOp::rawnew('LADMethod', CgOp::clr_string($self->name));
}
Expand Down
26 changes: 0 additions & 26 deletions test2.pl
Expand Up @@ -3,30 +3,4 @@

ok '{}' ~~ / \{ <.ws> \} /, 'ws matches between \W';

{
my grammar G7 {
proto token tok {*}
token tok:sym<+> { <sym> }
token tok:foo { <sym> }

rule TOP { <tok> }
}

ok G7.parse('+'), "can parse :sym<> symbols";
ok G7.parse('foo'), "can parse : symbols";
}

{
my $a;
ok 'xxy' ~~ /x { $a = $/.pos } /, "can match with \$/ stuff";
is $a, 1, '$/.pos is the right sort of thing';
'xxy' ~~ /x { $a = ($¢ ~~ Cursor) }/;
is $a, True, '$¢ isa Cursor';
}

#ok "axy" ~~ / a <before x> \w y / , "before is zero-width";
#ok "axy" ~~ / a <?before x> \w y / , "?before is zero-width";
#ok "azy" ~~ / a <!before x> \w y / , "!before is zero-width";
#ok !("azy" ~~ / a <?before x> \w y /) , "?before x needs x";
#ok !("axy" ~~ / a <!before x> \w y /) , "!before x needs !x";
done-testing;

0 comments on commit cdc7790

Please sign in to comment.