Skip to content

Commit

Permalink
[nrx] Implement CommitAll, CommitTo(name), CommitRule
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Aug 31, 2010
1 parent 8f9cfd5 commit 33f66ad
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/Cursor.cs
Expand Up @@ -62,6 +62,7 @@ public struct State {
end = orig.Length;
bt = new PSN<State>(default(State), null);
bt.obj.klasses = new PSN<DynMetaObject>(csr.klass, null);
bt.obj.xact = new XAct("MATCH", null);
bt.obj.pos = c.pos;
}

Expand All @@ -83,6 +84,35 @@ public struct State {
bt.obj.xact = new XAct(name, bt.obj.xact);
}

public void CommitAll() {
XAct x = bt.next.obj.xact;
while (x != null) {
x.committed = true;
x = x.next;
}
}

public void CommitSpecificRule(string name) {
XAct x = bt.next.obj.xact;
name = "RULE " + name;
while (x != null) {
x.committed = true;
x = x.next;
if (x.tag.Equals(name))
break;
}
}

public void CommitRule() {
XAct x = bt.next.obj.xact;
while (x != null) {
x.committed = true;
x = x.next;
if (x.tag.StartsWith("RULE "))
break;
}
}

public Frame Exact(Frame th, string st) {
if (bt.obj.pos + st.Length > end)
return Backtrack(th);
Expand Down
13 changes: 13 additions & 0 deletions t/RxUnitTest.cs
Expand Up @@ -25,6 +25,18 @@ class RxExact: RxOp {
}
}

class RxMeta: RxOp {
public delegate void MD(RxFrame rx);
MD md;
public RxMeta(MD md) { this.md = md; }
public override void Compile(CodeBuf cb) {
cb.ops.Add(delegate(Frame th) {
md(th.rx);
return th;
});
}
}

class RxStar: RxOp {
RxOp inner;
public RxStar(RxOp inner) { this.inner = inner; }
Expand Down Expand Up @@ -94,5 +106,6 @@ public class RxUnitTest {

public static void Main() {
RunTest(0, true, "aaaaab", new RxSeq(new RxOp[] { new RxStar( new RxExact("a") ), new RxExact("ab") }));
RunTest(1, false, "aaaaab", new RxSeq(new RxOp[] { new RxStar( new RxExact("a") ), new RxMeta(delegate(RxFrame rx) { rx.CommitAll(); }), new RxExact("ab") }));
}
}

0 comments on commit 33f66ad

Please sign in to comment.