Skip to content

Commit

Permalink
implement serialization for SubInfo, LAD, LexInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Oct 11, 2011
1 parent c6ea422 commit b1088dc
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 22 deletions.
65 changes: 63 additions & 2 deletions lib/Cursor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Niecza;
using Niecza.Serialization;
using System;
using System.Collections.Generic;
using System.Text;
Expand Down Expand Up @@ -533,7 +534,7 @@ public class Cursor : P6any {
public CapInfo captures;
public STable save_klass;

public override void Freeze(Niecza.Serialization.FreezeBuffer fb) { throw new NotImplementedException(); }
public override void Freeze(FreezeBuffer fb) { throw new NotImplementedException(); }
public string GetBacking() { return global.orig_s; }

public Cursor(P6any proto, string text, P6any actions)
Expand Down Expand Up @@ -935,9 +936,10 @@ public Dictionary<LexerState,LexerState> dfashare
}

// ltm automaton descriptors
public abstract class LAD {
public abstract class LAD : IFreeze {
public abstract void ToNFA(NFA pad, int from, int to);
public abstract void Dump(int indent);
public abstract void Freeze(FreezeBuffer fb);
public virtual void QueryLiteral(NFA pad, out int len, out bool cont) {
len = 0; cont = false;
}
Expand Down Expand Up @@ -970,6 +972,10 @@ public override void ToNFA(NFA pad, int from, int to) {
public override void Dump(int indent) {
Console.WriteLine(new string(' ', indent) + "str: " + text);
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte) SerializationCode.LADStr);
fb.String(text);
}
}

public class LADStrNoCase : LAD {
Expand Down Expand Up @@ -997,6 +1003,10 @@ public override void ToNFA(NFA pad, int from, int to) {
public override void Dump(int indent) {
Console.WriteLine(new string(' ', indent) + "strnocase: " + text);
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte) SerializationCode.LADStrNoCase);
fb.String(text);
}
}

public class LADCC : LAD {
Expand All @@ -1011,6 +1021,10 @@ public override void ToNFA(NFA pad, int from, int to) {
public override void Dump(int indent) {
Console.WriteLine(new string(' ', indent) + "cc: " + cc.ToString());
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte) SerializationCode.LADCC);
fb.Ints(cc.vec);
}
}

public class LADImp : LAD {
Expand All @@ -1024,6 +1038,9 @@ public override void ToNFA(NFA pad, int from, int to) {
public override void Dump(int indent) {
Console.WriteLine(new string(' ', indent) + "imp");
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte) SerializationCode.LADImp);
}
}

public class LADNull : LAD {
Expand All @@ -1039,6 +1056,9 @@ public override void Dump(int indent) {
public override void QueryLiteral(NFA pad, out int len, out bool cont) {
len = 0; cont = true;
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte) SerializationCode.LADNull);
}
}

public class LADNone : LAD {
Expand All @@ -1049,6 +1069,9 @@ public override void ToNFA(NFA pad, int from, int to) {
public override void Dump(int indent) {
Console.WriteLine(new string(' ', indent) + "none");
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte) SerializationCode.LADNone);
}
}

public class LADDot : LAD {
Expand All @@ -1060,6 +1083,9 @@ public override void ToNFA(NFA pad, int from, int to) {
public override void Dump(int indent) {
Console.WriteLine(new string(' ', indent) + "dot");
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte) SerializationCode.LADDot);
}
}

public class LADStar : LAD {
Expand All @@ -1078,6 +1104,10 @@ public override void Dump(int indent) {
Console.WriteLine(new string(' ', indent) + "star:");
child.Dump(indent + 4);
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte) SerializationCode.LADStar);
fb.ObjRef(child);
}
}

public class LADOpt : LAD {
Expand All @@ -1094,6 +1124,10 @@ public override void Dump(int indent) {
Console.WriteLine(new string(' ', indent) + "opt:");
child.Dump(indent + 4);
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte) SerializationCode.LADOpt);
fb.ObjRef(child);
}
}

public class LADPlus : LAD {
Expand All @@ -1118,6 +1152,10 @@ public override void Dump(int indent) {
Console.WriteLine(new string(' ', indent) + "plus:");
child.Dump(indent + 4);
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte) SerializationCode.LADPlus);
fb.ObjRef(child);
}
}

public class LADSequence : LAD {
Expand Down Expand Up @@ -1155,6 +1193,12 @@ public override void Dump(int indent) {
foreach (LAD l in args)
l.Dump(indent + 4);
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte) SerializationCode.LADSequence);
fb.Int(args.Length);
foreach (LAD l in args)
fb.ObjRef(l);
}
}

public class LADAny : LAD {
Expand All @@ -1177,6 +1221,12 @@ public override void Dump(int indent) {
foreach (LAD k in zyg)
k.Dump(indent + 4);
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte) SerializationCode.LADAny);
fb.Int(zyg.Length);
foreach (LAD l in zyg)
fb.ObjRef(l);
}
}

public class LADParam : LAD {
Expand Down Expand Up @@ -1240,6 +1290,10 @@ public override void QueryLiteral(NFA pad, out int len, out bool cont) {
public override void Dump(int indent) {
Console.WriteLine(new string(' ', indent) + "param: " + name);
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte) SerializationCode.LADParam);
fb.String(name);
}
}

public class LADMethod : LAD {
Expand Down Expand Up @@ -1291,6 +1345,10 @@ public override LAD Reify(NFA pad) {
public override void Dump(int indent) {
Console.WriteLine(new string(' ', indent) + "methodcall " + name);
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte) SerializationCode.LADMethod);
fb.String(name);
}
}

// Only really makes sense if used in the static scope of a proto
Expand Down Expand Up @@ -1332,6 +1390,9 @@ public override LAD Reify(NFA pad) {
public override void Dump(int indent) {
Console.WriteLine(new string(' ', indent) + "dispatcher");
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte) SerializationCode.LADDispatcher);
}
}

// These objects get put in hash tables, so don't change nstates[] after
Expand Down
Loading

0 comments on commit b1088dc

Please sign in to comment.