Skip to content

Commit

Permalink
Extend CompilableForm to Class, Boolean, Character. Clearer section o…
Browse files Browse the repository at this point in the history
…n var resolved constants.
  • Loading branch information
onionpancakes committed Apr 7, 2024
1 parent 0d268b1 commit 3e98fdc
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ Use `c/token-serializer` and `c/html-serializer` to access individual tokens and

### DOCTYPE

Use `c/doctype-html5`. It's just a RawString wrapping `<!DOCTYPE html>`. Because it's a RawString, it is safe to wrap in a vector to concatenate with the rest of the HTML document.
Use `c/doctype-html5`, a `RawString` wrapping `<!DOCTYPE html>`. Because it is a `RawString`, it is safe to wrap in a vector to concatenate with the rest of the HTML document.

```clojure
(c/html [c/doctype-html5 [:html "..."]])
Expand Down Expand Up @@ -762,7 +762,7 @@ Whether or not if this is a good idea is left to the user.

## Var Resolved Constants

Symbols referring to **constant** values are **var resolved** during compilation traversal, thereby allowing those constant values to participate in compilation. These include constant types such as `String` and any collection of constants, as well as `c/doctype-html5`, `c/nbsp`, and any `c/raw` string values. See `cc/constant?`.
Symbols referring to **vars** containing **constant values** are **resolved** to those values during compilation traversal, thereby allowing those constant values to participate in compilation. Constant types include `String`, `Long`, `IPersistentCollection` of constants, and `RawString` such as `c/doctype-html5` and `c/nbsp`. Use `cc/constant?` to check if values are constants.

```clojure
;; Fully compacted!
Expand Down
18 changes: 18 additions & 0 deletions src/dev/onionpancakes/chassis/compiler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,24 @@
(constant? [_] true)
(evaluated? [_] true)
(resolved [this] this)
Class
(attrs? [_] false)
(not-attrs? [_] true)
(constant? [_] true)
(evaluated? [_] true)
(resolved [this] this)
Boolean
(attrs? [_] false)
(not-attrs? [_] true)
(constant? [_] true)
(evaluated? [_] true)
(resolved [this] this)
Character
(attrs? [_] false)
(not-attrs? [_] true)
(constant? [_] true)
(evaluated? [_] true)
(resolved [this] this)
String
(attrs? [_] false)
(not-attrs? [_] true)
Expand Down
20 changes: 20 additions & 0 deletions test/dev/onionpancakes/chassis/tests/test_compiler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@
nil
0
0.0
\a
""
"foobar"
:foo
true
{}
#{}
'()
[]
#inst "2007-01-04"
#uuid "00000000-0000-0000-0000-000000000000"
java.lang.String

[:div]
[:div nil]
Expand Down Expand Up @@ -141,16 +145,24 @@
0.0
0.0M
3/2
\a
""
:foo
true
#uuid "00000000-0000-0000-0000-000000000000"
java.lang.String

[:div]
[:div#foo.bar "123"]
[:div {:foo "bar"} "123"]
[:div [:p "foo"] [:p "bar"]]
[:div [1 2 3 4]]
[:div #{1 2 3 4}]
[:div \a]
[:div :foo]
[:div true]
[:div #uuid "00000000-0000-0000-0000-000000000000"]
[:div java.lang.String]

;; Macros
(example-elem-macro "123")
Expand All @@ -172,8 +184,12 @@
0.0
0.0M
3/2
\a
""
:foo
true
#uuid "00000000-0000-0000-0000-000000000000"
java.lang.String

(short 0)
(int 0)
Expand All @@ -190,7 +206,11 @@
[:div [:p "foo"] [:p "bar"]]
[:div [1 2 3 4]]
[:div #{1 2 3 4}]
[:div \a]
[:div :foo]
[:div true]
[:div #uuid "00000000-0000-0000-0000-000000000000"]
[:div java.lang.String]

;; Alias
[::Foo]
Expand Down

0 comments on commit 3e98fdc

Please sign in to comment.