Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement :: and :::
  • Loading branch information
sorear committed Sep 6, 2010
1 parent cdc7790 commit 83c3bc3
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
13 changes: 12 additions & 1 deletion lib/Cursor.cs
Expand Up @@ -125,7 +125,9 @@ public struct State {
}

public void CommitGroup(string open, string close) {
XAct x = bt.next.obj.xact;
XAct x = bt.obj.xact;
if (Cursor.Trace)
x.Dump("committing " + open + "," + close);
int level = 1;
while (x != null) {
x.committed = true;
Expand Down Expand Up @@ -232,6 +234,15 @@ public sealed class XAct {
public readonly XAct next;

public XAct(string tag, XAct next) { this.tag = tag; this.next = next; }

public void Dump(string st) {
string ac = st;
for (XAct x = this; x != null; x = x.next) {
ac += x.committed ? " + " : " - ";
ac += x.tag;
}
Console.WriteLine(ac);
}
}

// This is used to carry match states in and out of subrules. Within subrules,
Expand Down
4 changes: 3 additions & 1 deletion src/CodeGen.pm
Expand Up @@ -67,7 +67,9 @@ use 5.010;
OpenQuant => [m => 'Void'],
CloseQuant => [m => 'Int32'],
CommitGroup => [m => 'Void'],
CommitGroupZW => [m => 'Void'],
CommitRule => [m => 'Void'],
CommitAll => [m => 'Void'],
CommitSpecificRule => [m => 'Void'],
GetCursorList => [m => 'Variable'],
LTMPushAlts => [m => 'Void'],
PushCursorList => [m => 'Void'],
Expand Down
42 changes: 41 additions & 1 deletion src/RxOp.pm
Expand Up @@ -362,6 +362,45 @@ use CgOp;
no Moose;
}

{
package RxOp::CutLTM;
use Moose;
extends 'RxOp';

sub code {
my ($self, $body) = @_;
CgOp::rawcall(CgOp::rxframe, 'CommitGroup',
CgOp::clr_string("LTM"), CgOp::clr_string("ENDLTM"));
}

sub lad {
my ($self) = @_;
CgOp::rawnew('LADImp'); #special case
}

__PACKAGE__->meta->make_immutable;
no Moose;
}

{
package RxOp::CutRule;
use Moose;
extends 'RxOp';

sub code {
my ($self, $body) = @_;
CgOp::rawcall(CgOp::rxframe, 'CommitRule');
}

sub lad {
my ($self) = @_;
CgOp::rawnew('LADNull');
}

__PACKAGE__->meta->make_immutable;
no Moose;
}

{
package RxOp::Alt;
use Moose;
Expand Down Expand Up @@ -448,7 +487,8 @@ use CgOp;
CgOp::letn(
"ks", CgOp::methodcall(CgOp::methodcall(
CgOp::subcall(CgOp::getindex(CgOp::letvar("i"),
CgOp::letvar("fns")), CgOp::scopedlex('')),
CgOp::letvar("fns")), CgOp::newscalar(
CgOp::rawcall(CgOp::rxframe, 'MakeCursor'))),
'list'), 'clone'),
CgOp::letvar("i", CgOp::arith('+',
CgOp::letvar("i"), CgOp::int(1))),
Expand Down
18 changes: 18 additions & 0 deletions test2.pl
Expand Up @@ -3,4 +3,22 @@

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

{
rxtest /z .* y [ a :: x | . ]/, "z.*y[a::x|.]",
("zyax", "zyb", "zyaxya"), ("zya",);
# no ::> until STD gets here...
rxtest /z .* y [ a ::: x || . ]/, "z.*y[a:::x||.]",
("zyax", "zyb"), ("zya", "zyaxya");

my grammar G7 {
proto regex TOP {*}
regex TOP:foo { a :: x }
regex TOP:bar { . }
}

ok G7.parse("ax"), ":: does not block forward";
ok G7.parse("b"), ":: does not affect other paths";
ok !G7.parse("a"), "cannot backtrack past :: in proto ltm";
}

done-testing;

0 comments on commit 83c3bc3

Please sign in to comment.