From 3e98fdc5ac25da7b863c4413cfebbe7ad326d787 Mon Sep 17 00:00:00 2001 From: onionpancakes <639985+onionpancakes@users.noreply.github.com> Date: Sun, 7 Apr 2024 00:33:07 -0700 Subject: [PATCH] Extend CompilableForm to Class, Boolean, Character. Clearer section on var resolved constants. --- README.md | 4 ++-- src/dev/onionpancakes/chassis/compiler.clj | 18 +++++++++++++++++ .../chassis/tests/test_compiler.clj | 20 +++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 42140d5..907aa6e 100644 --- a/README.md +++ b/README.md @@ -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 ``. 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 ``. 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 "..."]]) @@ -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! diff --git a/src/dev/onionpancakes/chassis/compiler.clj b/src/dev/onionpancakes/chassis/compiler.clj index a91518d..7cff24f 100644 --- a/src/dev/onionpancakes/chassis/compiler.clj +++ b/src/dev/onionpancakes/chassis/compiler.clj @@ -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) diff --git a/test/dev/onionpancakes/chassis/tests/test_compiler.clj b/test/dev/onionpancakes/chassis/tests/test_compiler.clj index f298538..bf122b9 100644 --- a/test/dev/onionpancakes/chassis/tests/test_compiler.clj +++ b/test/dev/onionpancakes/chassis/tests/test_compiler.clj @@ -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] @@ -141,8 +145,12 @@ 0.0 0.0M 3/2 + \a "" + :foo + true #uuid "00000000-0000-0000-0000-000000000000" + java.lang.String [:div] [:div#foo.bar "123"] @@ -150,7 +158,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] ;; Macros (example-elem-macro "123") @@ -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) @@ -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]