Hi, You may be interested in the net.cgrand.parsley.functional-trees and net.cgrand.parsley.views namespaces.
you need to pass options :make-node fnode and :make-leaf :fleaf to your parser. Now the result of parse-tree is not a tree anymore but an opaque object (a function). . You can then compute views on the tree. The #'as-map view will return the usual parse-tree, and the #'length and #'offsets view should be close to what you are looking for. Views are managed in an iincremental manner. offsets are relative and not absolute because absolute offsets are too brittle towards incremetalism. Let me know if it helps you. Christophe On Thu, Aug 22, 2013 at 11:20 PM, Jörg Winter <jwin1...@gmail.com> wrote: > Hi, > > Is there any existing option/fn to get the offsets and lengths of parsed > content ? > > For example for this: > > (-> sexpr p/incremental-buffer (p/edit 0 0 "(") (p/edit 1 0 "x)") > p/parse-tree clojure.pprint/pprint) > > ...instead of: > > {:tag :root, > :content > [{:tag :list, :content ["(" {:tag :symbol, :content ["x"]} ")"]}]} > > ...getting something like this: > > {:tag :root, > :content > [{:tag :list, :offset 0, :length 3, :content ["(" {:tag :symbol, :offset > 1, :length 1, :content ["x"]} ")"]}]} > > ? > > I guess project "paredit.clj" also does this more or less.. I just don't > find the simplest fn to do this in its purest form. > > Best, > Joerg > > -- > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > -- On Clojure http://clj-me.cgrand.net/ Clojure Programming http://clojurebook.com Training, Consulting & Contracting http://lambdanext.eu/ -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.