diff --git a/lib/Cursor.cs b/lib/Cursor.cs index 1f68a464..7a2d48ad 100644 --- a/lib/Cursor.cs +++ b/lib/Cursor.cs @@ -62,6 +62,7 @@ public struct State { end = orig.Length; bt = new PSN(default(State), null); bt.obj.klasses = new PSN(csr.klass, null); + bt.obj.xact = new XAct("MATCH", null); bt.obj.pos = c.pos; } @@ -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); diff --git a/t/RxUnitTest.cs b/t/RxUnitTest.cs index 4914736d..853584ad 100644 --- a/t/RxUnitTest.cs +++ b/t/RxUnitTest.cs @@ -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; } @@ -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") })); } }