public Map(MapType type, IDictionary map) { if (type == null || map == null) { Console.WriteLine(new StackTrace(true)); throw new NullErr().val; } this.m_type = type; this.m_map = map; }
public Map(MapType type) : this(type, new Hashtable()) { }
/// <summary> /// map := "[" mapPair ("," mapPair)* "]" /// mapPair := obj ":" + obj /// </summary> private object readMap(MapType mapType, object firstKey) { // setup accumulator Hashtable map = new Hashtable(); // finish first pair consume(Token.COLON, "Expected ':'"); map[firstKey] = readObj(null, null, false); // parse map pairs while (curt != Token.RBRACKET) { consume(Token.COMMA, "Expected ','"); if (curt == Token.RBRACKET) break; object key = readObj(null, null, false); consume(Token.COLON, "Expected ':'"); object val = readObj(null, null, false); map[key] = val; } consume(Token.RBRACKET, "Expected ']'"); // infer type if necessary if (mapType == null) { int size = map.Count; object[] keys = new object[map.Count]; object[] vals = new object[map.Count]; IDictionaryEnumerator en = map.GetEnumerator(); int i = 0; while (en.MoveNext()) { keys[i] = en.Key; vals[i] = en.Value; i++; } Type k = Type.common(keys, size); Type v = Type.common(vals, size); mapType = new MapType(k, v); } return new Map((MapType)mapType, map); }
private Type readType(bool lbracket) { Type t = readSimpleType(); if (curt == Token.QUESTION) { consume(); t = t.toNullable(); } if (curt == Token.COLON) { consume(); t = new MapType(t, readType()); } while (curt == Token.LRBRACKET) { consume(); t = t.toListOf(); } if (curt == Token.QUESTION) { consume(); t = t.toNullable(); } return t; }