<< Back to previous view

[TRDR-19] Some column numbers off when reading symbols with source-logging-push-back-reader Created: 24/Nov/14  Updated: 24/Nov/14

Status: Open
Project: tools.reader
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Andy Fingerhut Assignee: Nicola Mometto
Resolution: Unresolved Votes: 0
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


 Comments   
Comment by Andy Fingerhut [ 24/Nov/14 11:54 AM ]

I don't have a proposed fix, but perhaps this is related to how most reader types do nothing for (unread nil) calls, but 2 of them, including source-logging-push-back-reader, do modify their state on such a call.





[TRDR-18] A couple of typos in doc strings Created: 21/Nov/14  Updated: 22/Nov/14  Resolved: 22/Nov/14

Status: Closed
Project: tools.reader
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Trivial
Reporter: Andy Fingerhut Assignee: Nicola Mometto
Resolution: Completed Votes: 0
Labels: None


 Description   

Two occurrences of SourceLoggingReader should probably be replaced with SourceLoggingPushbackReader ?



 Comments   
Comment by Nicola Mometto [ 22/Nov/14 11:56 AM ]

Fixed thanks https://github.com/clojure/tools.reader/commit/ececc05cd8d505cc5f4ff9cee408e202b6cbf402





Generated at Fri Nov 28 10:08:47 CST 2014 using JIRA 4.4#649-r158309.