<< Back to previous view

[TRDR-13] Better documentation wrt interaction between reader-types and java readers Created: 11/Apr/14  Updated: 11/Apr/14

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

Type: Task Priority: Major
Reporter: Nicola Mometto Assignee: Nicola Mometto
Resolution: Unresolved Votes: 0
Labels: None





[TRDR-14] Feature Expressions Created: 15/May/14  Updated: 05/Aug/14

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

Type: Enhancement Priority: Major
Reporter: Ghadi Shayban Assignee: Nicola Mometto
Resolution: Unresolved Votes: 0
Labels: None

Attachments: File tools.reader-feature-expressions-2.diff     File tools.reader-feature-expressions-3.diff     File tools.reader-feature-expressions.diff    
Patch: Code and Test

 Description   

Feature expressions based directly on Common Lisp.

Implementation based on Roman's patch for CLJS-27. #+ #- and or not are supported. Unreadable tagged literals are suppressed through *suppress-read*.

For example, reading the following with features set to #{:clj} returns :baz

#+bad/platform #foo bar :baz

Initial feature names for each platform will be clj, cljs, and cljr.

CLJ-1424 is the accompanying patch for Clojure.

Patch: tools.reader-feature-expressions-3.diff



 Comments   
Comment by Nicola Mometto [ 19/May/14 6:56 PM ]

I looked over the patch and it mostly looks good, a few comments:

  • does *suppress-read* need to be exposed?
  • can you add a docstring for *features*?
  • should *suppress-read* affect read-eval?

That said, has it been decided that this is how feature expressions will be implemented in 1.7?
If not, I'm going to wait to merge this in until a decision is taken, this is a major design point and I don't want to diverge from the official clojure take on this even for a single release: people might start using it, especially since t.r is now the default reader for cljs.

Comment by Ghadi Shayban [ 19/May/14 7:23 PM ]

Yes thank you for not merging. This is WIP and just one approach for feature expressions. There seem to be at least two couple diverging approaches emerging from the various discussion (Brandon Bloom's idea of read-time splicing being the other.) I would definitely not merge until the community and Rich weighs in.

In any case having all Clojure platforms be ready for the change is probably essential. Also backwards compatibility of feature expr code to Clojure 1.6 and below is also not trivial.

1) *suppress-read* probably doesn't need to be exposed
2) *suppress-read* should probably imply *read-eval* false. You wouldn't want read-ctor to load any classes or call any code or constructors

Comment by Alex Miller [ 04/Aug/14 12:56 PM ]

Updated patch to reflect clj and cljs as initial feature names.





[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.





Generated at Fri Nov 28 05:07:23 CST 2014 using JIRA 4.4#649-r158309.