Merge pull request #52 from dm3/master
Marginalia fails on clojure files containing strings or other literals outside of forms (top level).
This commit is contained in:
commit
77af441e3d
4 changed files with 26 additions and 6 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,3 +7,4 @@ lib
|
|||
classes
|
||||
out
|
||||
webgen.cache
|
||||
.lein-failures
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
:dev-dependencies
|
||||
[[lein-clojars "0.6.0"]
|
||||
[jline "0.9.94"]
|
||||
;; lein vimclojure& #starts the nailgun server
|
||||
[org.clojars.autre/lein-vimclojure "1.0.0"]
|
||||
[swank-clojure "1.2.1"]]
|
||||
;;Needed for testing Latex equation formatting. You must download
|
||||
;;and install MathJax in you doc directory.
|
||||
|
|
|
@ -86,7 +86,8 @@
|
|||
;; HACK: to handle types
|
||||
(catch Exception _)))
|
||||
|
||||
(defmulti dispatch-form (fn [form _ _] (first form)))
|
||||
(defmulti dispatch-form (fn [form _ _]
|
||||
(if (seq? form) (first form) form)))
|
||||
|
||||
(defn- extract-common-docstring
|
||||
[form raw nspace-sym]
|
||||
|
@ -109,7 +110,7 @@
|
|||
[fn-body]
|
||||
(filter string? (rest fn-body)))
|
||||
|
||||
(defn- extract-internal-docstrings
|
||||
(defn- extract-internal-docstrings
|
||||
[body]
|
||||
(mapcat #(extract-impl-docstring %)
|
||||
body))
|
||||
|
@ -167,11 +168,19 @@
|
|||
form)
|
||||
nspace-sym))
|
||||
|
||||
(defn- dispatch-literal
|
||||
[form raw nspace-sym]
|
||||
[nil raw])
|
||||
|
||||
(defmethod dispatch-form :default
|
||||
[form raw nspace-sym]
|
||||
(if (re-find #"^def" (-> form first name))
|
||||
(extract-common-docstring form raw nspace-sym)
|
||||
(dispatch-inner-form form raw nspace-sym)))
|
||||
;; Strings which are inlined into clojure files outside of forms are parsed
|
||||
;; as `String` instances, while numbers - as `Number` subclasses.
|
||||
(cond (or (string? form) (number? form))
|
||||
(dispatch-literal form raw nspace-sym)
|
||||
(re-find #"^def" (-> form first name))
|
||||
(extract-common-docstring form raw nspace-sym)
|
||||
:else (dispatch-inner-form form raw nspace-sym)))
|
||||
|
||||
(defn extract-docstring [m raw nspace-sym]
|
||||
(let [raw (join "\n" (subvec raw (-> m :start dec) (:end m)))
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
(ns parse-test
|
||||
"This module does stuff"
|
||||
(:require [clojure.string :as str]))
|
||||
(:require [clojure.string :as str])
|
||||
(:use clojure.test)
|
||||
(:require marginalia.parser))
|
||||
|
||||
|
||||
;; It seems that, in Clojure, block
|
||||
|
@ -13,3 +15,9 @@
|
|||
Does some other cool stuff too."
|
||||
(println (str "Hello World, " name "!")))
|
||||
|
||||
(deftest test-inline-literals
|
||||
(is (= (count (marginalia.parser/parse "(ns test)")) 1))
|
||||
;(is (= (count (marginalia.parser/parse "(ns test)\n123")) 1)) still failing
|
||||
(is (= (count (marginalia.parser/parse "(ns test)\n123\n")) 1))
|
||||
(is (= (count (marginalia.parser/parse "(ns test)\n\"string\"")) 1))
|
||||
(is (= (count (marginalia.parser/parse "(ns test)\n\"some string\"")) 1)))
|
||||
|
|
Loading…
Reference in a new issue