Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support preserving location metadata of numbers, strings, etc. #52

Closed
borkdude opened this issue Aug 2, 2020 · 0 comments
Closed

Support preserving location metadata of numbers, strings, etc. #52

borkdude opened this issue Aug 2, 2020 · 0 comments

Comments

@borkdude
Copy link
Owner

borkdude commented Aug 2, 2020

This is implemented as follows (excerpt from the README):

Postprocess read values:

(defrecord Wrapper [obj loc])

(defn iobj? [x]
  #?(:clj (instance? clojure.lang.IObj x)
     :cljs (satisfies? IWithMeta x)))

(parse-string "[1]" {:postprocess
                       (fn [{:keys [:obj :loc]}]
                         (if (iobj? obj)
                           (vary-meta obj merge loc)
                           (->Wrapper obj loc)))})

[#user.Wrapper{:obj 1, :loc {:row 1, :col 2, :end-row 1, :end-col 3}}]

This allows you to preserve metadata for objects that do not support carrying
metadata. When you use a :postprocess function, it is your responsibility to
attach location metadata.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant