2 using System.Collections.Generic;
7 public sealed class MSymbol
9 private static Dictionary<string, MSymbol> pool
10 = new Dictionary<string, MSymbol> ();
12 public readonly string Name;
14 internal MProperty.Flags? flags;
16 public static MSymbol nil = MSymbol.Of ("nil");
17 public static MSymbol t = MSymbol.Of ("t");
18 public static MSymbol symbol = MSymbol.Of ("symbol");
19 public static MSymbol mtext = MSymbol.Of ("mtext");
20 public static MSymbol mstring = MSymbol.Of ("string");
21 public static MSymbol plist = MSymbol.Of ("plist");
22 public static MSymbol integer = MSymbol.Of ("integer");
24 private MSymbol (string name)
29 public static MSymbol Of (string name)
35 if (! pool.TryGetValue (name, out sym))
37 sym = new MSymbol (name);
44 public static MSymbol PropertyKey (string name)
46 MSymbol sym = MSymbol.Of (name);
48 if (sym.flags == null)
49 sym.flags = MProperty.Flags.None;;
53 public static MSymbol PropertyKey (string name, MProperty.Flags flags)
55 MSymbol sym = MSymbol.Of (name);
57 if ((flags & MProperty.Flags.BothSticky) != MProperty.Flags.None
58 && (flags & MProperty.Flags.Sensitive) != MProperty.Flags.None)
59 throw new Exception ("A property can't be both sticky and sensitve");
60 if (sym.flags == null)
62 else if (sym.flags != flags)
63 throw new Exception ("Flags of PropertyKey mismatch");
67 public override string ToString ()
71 foreach (char c in Name)
73 if (c == '\\' || c == ' ' || c == '\'' || c == '\"'
74 || c == '(' || c == ')')
81 public MPlist Find (MSymbol key)
83 return (Plist == null ? null : Plist.Find (key));
86 public object Get (MSymbol key)
88 return (Plist == null ? null : Plist.Get (key));
91 public object Put (MSymbol key, object val)
94 Plist = new MPlist ();
95 return Plist.Put (key, val);