(defMacroVar fuzzyJsons (new StringMap)) (defMacroFunction _loadFuzzyJson [key file] (unless (fuzzyJsons.exists key) (dictSet fuzzyJsons key (new StringMap))) (let [map (dictGet fuzzyJsons key) json (Json.parse (File.getContent file))] (doFor key (Reflect.fields json) (if (map.exists key) // mark the key to throw an error if accessed, // because it is a duplicate (dictSet map key null) (dictSet map key (Reflect.field json key)))))) (defMacro loadFuzzyJson [key file] (_loadFuzzyJson (eval key) (eval file)) `{}) (defMacroFunction _getFuzzyJson [whichJson key take] (let [json (dictGet fuzzyJsons whichJson) bm (FuzzyMapTools.bestMatch json key) val (dictGet json bm)] (when take (json.remove bm)) val)) (defMacro getFuzzyJson [whichJson key &opt take &builder b] (let [value (_getFuzzyJson (eval whichJson) (eval key) take)] (if !(= null value) `(haxe.Json.parse ,(Json.stringify value)) (throw (+ (eval key) " has a duplicate definition between multiple files of fuzzy json " (eval whichJson)))))) (defMacro takeFuzzyJson [whichJson key] `(getFuzzyJson ,whichJson ,key true))