def fnReader(rdr, lparen): from py.clojure.lang.persistenthashmap import EMPTY from py.clojure.lang.var import popThreadBindings, pushThreadBindings if ARG_ENV.deref() is not None: raise IllegalStateException("Nested #()s are not allowed") #try: pushThreadBindings(RT.map(ARG_ENV, EMPTY)) rdr.back() form = read(rdr, True, None, True) drefed = ARG_ENV.deref() sargs = sorted(list(filter(lambda x: x != -1, drefed))) args = [] if len(sargs): for x in range(int(str(sargs[-1]))): if x in drefed: args.append(drefed[x]) else: args.append(garg(x)) retsym = drefed[-1] if retsym is not None: args.append(_AMP_) args.append(retsym) vargs = RT.vector(args) popThreadBindings() return RT.list(_FN_, vargs, form)
def metaReader(rdr, caret): from py.clojure.lang.symbol import Symbol from py.clojure.lang.cljkeyword import Keyword, TAG_KEY, T from py.clojure.lang.ipersistentmap import IPersistentMap line = rdr.lineCol()[0] meta = read(rdr, True, None, True) if isinstance(meta, Symbol) or isinstance(meta, str): meta = RT.map(TAG_KEY, meta) elif isinstance(meta, Keyword): meta = RT.map(meta, T) elif not isinstance(meta, IPersistentMap): raise ReaderException("Metadata must be Symbol,Keyword,String or Map") o = read(rdr, True, None, True) if not hasattr(o, "withMeta"): raise ReaderException("Cannot attach meta to a object without .withMeta") return o.withMeta(meta)
def __call__(self, r, backquote): pushThreadBindings(RT.map(GENSYM_ENV, EMPTY_MAP)) try: self.rdr = r form = read(r, True, None, True) return self.syntaxQuote(form) finally: popThreadBindings()
def varQuoteReader(rdr, singlequote): line = rdr.lineCol()[0] form = read(rdr, True, None, True) return RT.list(_VAR_, form).withMeta(RT.map(LINE_KEY, line))
def listReader(rdr, leftparen): startline = rdr.lineCol()[0] lst = readDelimitedList(')', rdr, True) lst = apply(RT.list, lst) return lst.withMeta(RT.map(LINE_KEY, startline))