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 implicit operator MSymbol (string name)
34 public static explicit operator string (MSymbol sym)
39 public static MSymbol Of (string name)
45 if (! pool.TryGetValue (name, out sym))
47 sym = new MSymbol (name);
54 public static MSymbol PropertyKey (string name)
56 MSymbol sym = MSymbol.Of (name);
58 if (sym.flags == null)
59 sym.flags = MProperty.Flags.None;;
63 public static MSymbol PropertyKey (string name, MProperty.Flags flags)
65 MSymbol sym = MSymbol.Of (name);
67 if ((flags & MProperty.Flags.BothSticky) != MProperty.Flags.None
68 && (flags & MProperty.Flags.Sensitive) != MProperty.Flags.None)
69 throw new Exception ("A property can't be both sticky and sensitve");
70 if (sym.flags == null)
72 else if (sym.flags != flags)
73 throw new Exception ("Flags of PropertyKey mismatch");
77 public override string ToString ()
81 foreach (char c in Name)
83 if (c == '\\' || c == ' ' || c == '\'' || c == '\"'
84 || c == '(' || c == ')')
91 public MPlist Find (MSymbol key)
93 return (Plist == null ? null : Plist.Find (key));
96 public object Get (MSymbol key)
98 return (Plist == null ? null : Plist.Get (key));
101 public object Put (MSymbol key, object val)
104 Plist = new MPlist ();
105 return Plist.Put (key, val);