diff options
author | scgilardi <scgilardi@gmail.com> | 2008-12-02 19:57:29 +0000 |
---|---|---|
committer | scgilardi <scgilardi@gmail.com> | 2008-12-02 19:57:29 +0000 |
commit | 4763b89ae48263299ffba1df115e635d1192c332 (patch) | |
tree | 4100c5c59fb709625fc4421cf4427d51dc9d99f8 /src/clojure | |
parent | 433ce4a25db5baccde14cacadc90434984d8904e (diff) |
repl-ln.clj: improve ; comment behavior
Diffstat (limited to 'src/clojure')
-rw-r--r-- | src/clojure/contrib/repl_ln.clj | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/clojure/contrib/repl_ln.clj b/src/clojure/contrib/repl_ln.clj index 8ec493a4..cee7882b 100644 --- a/src/clojure/contrib/repl_ln.clj +++ b/src/clojure/contrib/repl_ln.clj @@ -76,21 +76,40 @@ namespace (ns-name *ns*)] (format prompt-fmt-internal serial thread depth line namespace))) +(defn- whitespace? + "Returns logical true if c is whitespace in Clojure" + [c] + (or (Character/isWhitespace c) (= c (int \,)))) + +(defn- eol? + "Returns logical true if c is an eol character" + [c] + (#{\return \newline} (char c))) + +(defn- skip-to-eol + "Reads and skips everything until an eol character" + [s] + (loop [c (.read s)] + (when-not (eol? c) + (recur (.read s))))) + (defn- skip-whitespace "Reads and skips whitespace characters from stream s. Returns :eos on end - of stream, :eol on end of line, or false on non-whitespace." + of stream, :eol on end of line, :eol after skipping rest of line on + semicolon, or false otherwise." [s] (loop [c (.read s)] (cond (= c -1) :eos - (#{\return \newline} (char c)) :eol - (or (Character/isWhitespace c) (= c \,)) (recur (.read s)) + (eol? c) :eol + (= c (int \;)) (do (skip-to-eol s) :eol) + (whitespace? c) (recur (.read s)) :else (do (.unread s c) false)))) (defn- read-hook "Read hook that keeps the compiler's line number in sync with that of our input stream, prompts only when there is nothing remaining to read on the previous input line, and calls the Clojure reader only when there's - something to read on the current line." + something interesting to read on the current line." [eof] (loop [c (skip-whitespace *in*)] (cond (= c :eos) eof |