Skip to content

Commit

Permalink
more consistent underscore usage when this isn't used; more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
onionpancakes committed Feb 25, 2024
1 parent ee1186a commit 81183e5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
36 changes: 18 additions & 18 deletions src/dev/onionpancakes/chassis/compiler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
clojure.lang.Compiler$NilExpr
(attrs-compiler-expr? [_] true)
clojure.lang.Compiler$MapExpr
(attrs-compiler-expr? [this] true)
(attrs-compiler-expr? [_] true)
clojure.lang.Compiler$EmptyExpr
(attrs-compiler-expr? [this]
(attrs-type? (.getJavaClass this)))
Expand All @@ -176,33 +176,33 @@

(extend-protocol CompilableForm
dev.onionpancakes.chassis.core.OpeningTag
(attrs? [this] false)
(not-attrs? [this] true)
(attrs? [_] false)
(not-attrs? [_] true)
(constant? [this]
;; Attrs is evaluated, but may not constant.
(constant? (.-attrs this)))
(evaluated? [this] true)
(evaluated? [_] true)
(resolved [this]
(c/->OpeningTag (.-metadata this)
(.-tag this)
(.-head-id this)
(.-head-class this)
(resolved (.-attrs this))))
dev.onionpancakes.chassis.core.ClosingTag
(attrs? [this] false)
(not-attrs? [this] true)
(attrs? [_] false)
(not-attrs? [_] true)
(constant? [_] true)
(evaluated? [_] true)
(resolved [this] this)
dev.onionpancakes.chassis.core.RawString
(attrs? [this] false)
(not-attrs? [this] true)
(attrs? [_] false)
(not-attrs? [_] true)
(constant? [_] true)
(evaluated? [_] true)
(resolved [this] this)
clojure.lang.MapEntry
(attrs? [this] false)
(not-attrs? [this] true)
(attrs? [_] false)
(not-attrs? [_] true)
(constant? [this]
(and (constant? (key this))
(constant? (val this))))
Expand All @@ -224,8 +224,8 @@
(resolved [this]
(into (empty this) (map resolved) this))
clojure.lang.Keyword
(attrs? [this] false)
(not-attrs? [this] true)
(attrs? [_] false)
(not-attrs? [_] true)
(constant? [_] true)
(evaluated? [_] true)
(resolved [this] this)
Expand All @@ -235,7 +235,7 @@
(and (not *evaluated*)
(or (attrs-type-hinted? this)
(attrs-invocation? this))))
(not-attrs? [this]
(not-attrs? [_]
(boolean *evaluated*))
;; Lists are compilation barriers.
;; Not constants, not evaluated.
Expand All @@ -258,7 +258,7 @@
(or (attrs-type-hinted? (key entry))
(attrs-compiler-binding? (val entry)))
false))))
(not-attrs? [this]
(not-attrs? [_]
(boolean *evaluated*))
(constant? [_]
(boolean *evaluated*))
Expand All @@ -276,8 +276,8 @@
;; Constable catches Strings, constant Numbers
;; (not mutable accumulator Numbers), and a bit more.
java.lang.constant.Constable
(attrs? [this] false)
(not-attrs? [this] true)
(attrs? [_] false)
(not-attrs? [_] true)
(constant? [_] true)
(evaluated? [_] true)
(resolved [this] this)
Expand All @@ -292,8 +292,8 @@
(evaluated? [_] true)
(resolved [this] this)
nil
(attrs? [this] true)
(not-attrs? [this] false)
(attrs? [_] true)
(not-attrs? [_] false)
(constant? [_] true)
(evaluated? [_] true)
(resolved [_] nil))
Expand Down
32 changes: 19 additions & 13 deletions src/dev/onionpancakes/chassis/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@
(replace "'" "'")))

(defn escape-attribute-value
"Escapes an attribute value string. Escapes &, <, >, \", and '."
"Escape as an attribute value string. Escapes &, <, >, \", and '."
{:tag String}
([] "")
([x]
Expand Down Expand Up @@ -300,8 +300,8 @@
(extend-protocol AttributeValueFragment
clojure.lang.Keyword
(attribute-value-fragment [this]
(if-let [ns (namespace this)]
(let [ns-frag (escape-attribute-value-fragment ns)
(if-let [ns-str (namespace this)]
(let [ns-frag (escape-attribute-value-fragment ns-str)
name-frag (escape-attribute-value-fragment (.getName this))
sb (doto (StringBuilder.)
(.append ns-frag)
Expand Down Expand Up @@ -353,7 +353,7 @@
;; and false has a fragment value of nil.
(if this "" nil))
nil
(attribute-value-fragment [this] nil))
(attribute-value-fragment [_] nil))

;; Opening Tag

Expand Down Expand Up @@ -727,6 +727,9 @@
(defn make-opening-tag
{:tag OpeningTag}
[metadata ^clojure.lang.Keyword head attrs]
;; The index of the first '#' is the anchor.
;; The index of the first '.' is tested whether it's before or after the anchor.
;; If before, check for another '.' after the anchor.
(let [head-ns (namespace head)
head-name (.getName head)
pound-idx (.indexOf head-name 35 #_(int \#))
Expand Down Expand Up @@ -815,8 +818,11 @@
([value & more]
(RawString. (apply str value more))))

(def raw
"Alias for raw-string."
(def ^{:arglists (:arglists (meta #'raw-string))}
raw
"Wraps value as an unescaped string.
Alias for raw-string."
raw-string)

;; Token impl
Expand All @@ -831,7 +837,7 @@
(replace ">" "&gt;")))

(defn escape-text
"Escapes a text string. Escapes &, <, and >."
"Escape as a text string. Escapes &, <, and >."
{:tag String}
([] "")
([x]
Expand Down Expand Up @@ -1377,26 +1383,26 @@

(extend-protocol Node
clojure.lang.ISeq
(branch? [this] true)
(branch? [_] true)
(children [this] this)
clojure.core.Eduction
(branch? [this] true)
(branch? [_] true)
(children [this] this)
clojure.lang.IDeref
(branch? [this] true)
(branch? [_] true)
(children [this]
;; Note: adds an additional depth to the search stack.
[(.deref this)])
clojure.lang.Fn
(branch? [this] true)
(branch? [_] true)
(children [this]
;; Note: adds an additional depth to the search stack.
[(this)])
Object
(branch? [this] false)
(branch? [_] false)
(children [_] nil)
nil
(branch? [this] false)
(branch? [_] false)
(children [_] nil))

;; Raw consts
Expand Down

0 comments on commit 81183e5

Please sign in to comment.