Uploaded image for project: 'tools.reader'
  1. TRDR-19

Some column numbers off when reading symbols with source-logging-push-back-reader

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Completed
    • Labels:
      None

      Description

      I have not checked other variants of readers in tools.reader yet, but here are some steps to reproduce what I have found. Not big deals, just nice if the source code locations were not off by 1 in some cases. Search for "TBD" in the sample REPL session below to see the things that appear off to me.

      (use '[clojure.tools.reader :only [read]])
      (use 'clojure.pprint)
      (require '[clojure.tools.reader.reader-types :as reader-types])
      
      (defn slurp-already-opened [r]
        (let [sb (StringBuilder.)]
          (loop [c (reader-types/read-char r)]
            (if (nil? c)
              (str sb)
              (do
                (.append sb c)
                (recur (reader-types/read-char r)))))))
      
      (defn read-with-locs [string]
        (let [reader (reader-types/source-logging-push-back-reader string)
              first-form (read reader)
              line (reader-types/get-line-number reader)
              column (reader-types/get-column-number reader)
              unread (slurp-already-opened reader)]
          {:form first-form
           :form-meta (meta first-form)
           :get-line line
           :get-column column
           :unread unread
           :read-length (- (count string) (count unread))}))
      
      user=> (pprint (read-with-locs "foo"))
      {:form foo,
       :form-meta
       {:line 1, :column 1, :end-line 1, :end-column 4, :source "foo"},
       :get-line 1,
       :get-column 3,  ; TBD: Expect 4 here
       :unread "",
       :read-length 3}
      nil
      user=> (pprint (read-with-locs "foo "))
      {:form foo,
       :form-meta
       {:line 1, :column 1, :end-line 1, :end-column 5, :source "foo"},  ; TBD: Expect :end-column 4 here
       :get-line 1,
       :get-column 4,
       :unread " ",
       :read-length 3}
      nil
      

        Attachments

          Activity

            People

            • Assignee:
              bronsa Nicola Mometto
              Reporter:
              jafingerhut Andy Fingerhut
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: