UNPKG

jsedn

Version:

js implementation of edn

55 lines (49 loc) 1.48 kB
// Generated by CoffeeScript 1.6.1 (function() { var Map, Pair, Symbol, kw, sym, type, _ref, _ref1; type = require("./type"); _ref = require("./collections"), Map = _ref.Map, Pair = _ref.Pair; _ref1 = require("./atoms"), Symbol = _ref1.Symbol, kw = _ref1.kw, sym = _ref1.sym; module.exports = function(parse) { return function(data, values, tokenStart) { var unifyToken, valExists; if (tokenStart == null) { tokenStart = "?"; } if (type(data) === "string") { data = parse(data); } if (type(values) === "string") { values = parse(values); } valExists = function(v) { if (values instanceof Map) { if (values.exists(v)) { return values.at(v); } else if (values.exists(sym(v))) { return values.at(sym(v)); } else if (values.exists(kw(":" + v))) { return values.at(kw(":" + v)); } } else { return values[v]; } }; unifyToken = function(t) { var val; if (t instanceof Symbol && ("" + t)[0] === tokenStart && ((val = valExists(("" + t).slice(1))) != null)) { return val; } else { return t; } }; return data.walk(function(v, k) { if (k != null) { return new Pair(unifyToken(k), unifyToken(v)); } else { return unifyToken(v); } }); }; }; }).call(this);