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 plist = MSymbol.Of ("plist");
21 public static MSymbol integer = MSymbol.Of ("integer");
23 private MSymbol (string name)
28 public static MSymbol Of (string name)
34 if (! pool.TryGetValue (name, out sym))
36 sym = new MSymbol (name);
43 public static MSymbol PropertyKey (string name)
45 MSymbol sym = MSymbol.Of (name);
47 if (sym.flags == null)
48 sym.flags = MProperty.Flags.None;;
52 public static MSymbol PropertyKey (string name, MProperty.Flags flags)
54 MSymbol sym = MSymbol.Of (name);
56 if ((flags & MProperty.Flags.BothSticky) != MProperty.Flags.None
57 && (flags & MProperty.Flags.Sensitive) != MProperty.Flags.None)
58 throw new Exception ("Sensitive property can't be sticky");
59 if (sym.flags == null)
61 else if (sym.flags != flags)
62 throw new Exception ("Flags of PropertyKey mismatch");
66 public override string ToString ()
70 foreach (char c in Name)
72 if (c == '\\' || c == ' ' || c == '\'' || c == '\"'
73 || c == '(' || c == ')')
80 public MPlist Find (MSymbol key)
82 return (Plist == null ? null : Plist.Find (key));
85 public object Get (MSymbol key)
87 return (Plist == null ? null : Plist.Get (key));
90 public object Put (MSymbol key, object val)
93 Plist = new MPlist ();
94 return Plist.Put (key, val);