(Object reader, Object colon, Object opts)
| 487 | |
| 488 | public static class NamespaceMapReader extends AFn{ |
| 489 | public Object invoke(Object reader, Object colon, Object opts) { |
| 490 | PushbackReader r = (PushbackReader) reader; |
| 491 | |
| 492 | // Read ns symbol |
| 493 | Object sym = read(r, true, null, false, opts); |
| 494 | if (!(sym instanceof Symbol) || ((Symbol)sym).getNamespace() != null) |
| 495 | throw new RuntimeException("Namespaced map must specify a valid namespace: " + sym); |
| 496 | String ns = ((Symbol)sym).getName(); |
| 497 | |
| 498 | // Read map |
| 499 | int nextChar = read1(r); |
| 500 | while(isWhitespace(nextChar)) |
| 501 | nextChar = read1(r); |
| 502 | if('{' != nextChar) |
| 503 | throw new RuntimeException("Namespaced map must specify a map"); |
| 504 | List kvs = readDelimitedList('}', r, true, opts); |
| 505 | if((kvs.size() & 1) == 1) |
| 506 | throw Util.runtimeException("Namespaced map literal must contain an even number of forms"); |
| 507 | |
| 508 | // Construct output map |
| 509 | Object[] a = new Object[kvs.size()]; |
| 510 | Iterator iter = kvs.iterator(); |
| 511 | for(int i = 0; iter.hasNext(); i += 2) { |
| 512 | Object key = iter.next(); |
| 513 | Object val = iter.next(); |
| 514 | |
| 515 | if(key instanceof Keyword) { |
| 516 | Keyword kw = (Keyword) key; |
| 517 | if (kw.getNamespace() == null) { |
| 518 | key = Keyword.intern(ns, kw.getName()); |
| 519 | } else if (kw.getNamespace().equals("_")) { |
| 520 | key = Keyword.intern(null, kw.getName()); |
| 521 | } |
| 522 | } else if(key instanceof Symbol) { |
| 523 | Symbol s = (Symbol) key; |
| 524 | if (s.getNamespace() == null) { |
| 525 | key = Symbol.intern(ns, s.getName()); |
| 526 | } else if (s.getNamespace().equals("_")) { |
| 527 | key = Symbol.intern(null, s.getName()); |
| 528 | } |
| 529 | } |
| 530 | a[i] = key; |
| 531 | a[i+1] = val; |
| 532 | } |
| 533 | return RT.map(a); |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | public static class DispatchReader extends AFn{ |
nothing calls this directly
no test coverage detected