static object matchSymbol(string token, string mask) { Match m = symbolPat.Match(mask); if (m.Success) { string maskNS = m.Groups[1].Value; string maskName = m.Groups[2].Value; if (maskNS != null && maskNS.EndsWith(":/") || maskName.EndsWith(":") || mask.IndexOf("::", 1) != -1) { return(null); } if (mask.StartsWith("::")) { return(null); } bool isKeyword = mask[0] == ':'; if (isKeyword) { Match m2 = symbolPat.Match(mask.Substring(1)); if (!m2.Success) { return(null); } string ns; string name; ExtractNamesUsingMask(token.Substring(1), m2.Groups[1].Value, m2.Groups[2].Value, out ns, out name); return(Keyword.intern(ns, name)); } else { string ns; string name; ExtractNamesUsingMask(token, maskNS, maskName, out ns, out name); return(Symbol.intern(ns, name)); } } return(null); }
static object matchSymbol(string s) { Match m = symbolPat.Match(s); if (m.Success) { int gc = m.Groups.Count; string ns = m.Groups[1].Value; string name = m.Groups[2].Value; if (ns != null && ns.EndsWith(":/") || name.EndsWith(":") || s.IndexOf("::", 1) != -1) { return(null); } // Maybe resolveSymbol should move here or into Namespace: resolveSymbol is not used in the compiler. if (s.StartsWith("::")) { Symbol ks = Symbol.intern(s.Substring(2)); Namespace kns; if (ks.Namespace != null) { kns = Compiler.NamespaceFor(ks); } else { kns = Compiler.CurrentNamespace; } //auto-resolving keyword return(Keyword.intern(kns.Name.Name, ks.Name)); } bool isKeyword = s[0] == ':'; Symbol sym = Symbol.intern(s.Substring(isKeyword ? 1 : 0)); if (isKeyword) { return(Keyword.intern(sym)); } return(sym); } return(null); }
public override object invoke(object reader, object colon, object opts) { PushbackTextReader r = reader as PushbackTextReader; // Read ns symbol object osym = read(r, true, null, false, opts); Symbol sym = osym as Symbol; if (sym == null || sym.Namespace != null) { throw new Exception("Namespaced map must specify a valid namespace: " + osym); } string ns = sym.Name; // Read map int nextChar = r.Read(); while (isWhitespace(nextChar)) { nextChar = r.Read(); } if ('{' != nextChar) { throw new Exception("Namespaced map must specify a map"); } List <object> kvs = ReadDelimitedList('}', r, true, opts); if ((kvs.Count & 1) == 1) { throw new Exception("Namespaced map literal must contain an even number of forms"); } // Construct output map object[] a = new object[kvs.Count]; // IPersistentMap m = RT.map(); using (var iterator = kvs.GetEnumerator()) { for (int i = 0; iterator.MoveNext(); i += 2) { var key = iterator.Current; iterator.MoveNext(); var val = iterator.Current; Keyword kw = key as Keyword; if (kw != null) { if (kw.Namespace == null) { key = Keyword.intern(ns, kw.Name); } else if (kw.Namespace.Equals("_")) { key = Keyword.intern(null, kw.Name); } } else { Symbol s = key as Symbol; if (s != null) { if (s.Namespace == null) { key = Symbol.intern(ns, s.Name); } else if (s.Namespace.Equals("_")) { key = Symbol.intern(null, s.Name); } } } a[i] = key; a[i + 1] = val; } } return(RT.map(a)); }
public object GetRealObject(StreamingContext context) { return(Keyword.intern(_sym)); }
static object matchSymbol(string token, int lastSlashIndex) { // no :: except at beginning if (token.IndexOf("::", 1) != -1) { return(null); } string nsStr; string nameStr; if (lastSlashIndex == -1) { nsStr = null; nameStr = token; } else { nsStr = token.Substring(0, lastSlashIndex); nameStr = token.Substring(lastSlashIndex + 1); } // Must begin with non-digit, or ':' + non-digit if there is a namespace Match nameMatch = nsStr != null?nameSymbolPat.Match(nameStr) : nsSymbolPat.Match(nameStr); if (!nameMatch.Success) { return(null); } // no trailing : if (nameStr.EndsWith(":")) { return(null); } if (nsStr != null) { // Must begin with non-digit or ':' + non-digit Match nsMatch = nsSymbolPat.Match(nsStr); if (!nsMatch.Success) { return(null); } // no trailing :/ on ns if (nsStr != null && nsStr.EndsWith(":/")) { return(null); } } if (token.StartsWith("::")) { return(null); } bool isKeyword = token[0] == ':'; Symbol sym = Symbol.intern(token.Substring(isKeyword ? 1 : 0)); if (isKeyword) { return(Keyword.intern(sym)); } return(sym); }