(defn
lines->segs
"Take a nested sorted map encoding line and column information\n for a file and return a vector of vectors of encoded segments.\n Each vector represents a line, and the internal vectors are segments\n representing the contents of the line."
[lines]
(let
[relseg (atom [0 0 0 0 0])]
(reduce
(fn
[segs cols]
(swap!
relseg
(fn [[_ source line col name]] [0 source line col name]))
(conj
segs
(reduce
(fn
[cols [gcol sidx line col name :as seg]]
(let
[offset (map - seg @relseg)]
(swap!
relseg
(fn [[_ _ _ _ lname]] [gcol sidx line col (or name lname)]))
(conj cols (base64-vlq/encode offset))))
[]
cols)))
[]
lines)))