feat: proper char type ({:jolt/type :jolt/char :ch N}) — reader literals, char?/char/int/str, =, seq/first/rest/nth of strings yield chars, char printing; fix REPL multi-line input accumulation

This commit is contained in:
Yogthos 2026-06-04 15:40:59 -04:00
parent e1556fd102
commit 0d841ef83d
7 changed files with 104 additions and 24 deletions

View file

@ -226,6 +226,23 @@
### ==== printing ====
["pr-str vec" "\"[1 2 3]\"" "(pr-str [1 2 3])"]
["prn-str" "\"1\\n\"" "(prn-str 1)"]
### ==== characters ====
["char?" "true" "(char? \\a)"]
["char not string" "false" "(= \\a \"a\")"]
["char eq" "true" "(= \\a \\a)"]
["int of char" "97" "(int \\a)"]
["char of int" "true" "(= \\A (char 65))"]
["str of chars" "\"abc\"" "(str \\a \\b \\c)"]
["seq of string" "(quote (\\a \\b))" "(seq \"ab\")"]
["first of string" "\\h" "(first \"hello\")"]
["nth of string" "\\e" "(nth \"hello\" 1)"]
["char newline" "10" "(int \\newline)"]
["char space" "32" "(int \\space)"]
["char unicode" "65" "(int \\u0041)"]
["pr-str char" "\"\\\\a\"" "(pr-str \\a)"]
["chars in vec" "[\\a \\b]" "[\\a \\b]"]
["apply str chars" "\"hi\"" "(apply str [\\h \\i])"]
])
(var pass 0)

View file

@ -128,13 +128,13 @@
(assert (deep= @[(sym "+") 1 3] (parse-string "(+ 1 #?(:clj 3 :cljs 4))"))
"#? inside list picks :clj")
# Characters
# Characters — the reader now produces char values {:jolt/type :jolt/char :ch N}
(let [form (parse-string "\\newline")]
(assert (struct? form) "char is struct")
(assert (= :char (form :jolt/type)) "char type")
(assert (= "newline" (form :name)) "char name"))
(assert (= :jolt/char (form :jolt/type)) "char type")
(assert (= 10 (form :ch)) "newline codepoint"))
(let [form (parse-string "\\a")]
(assert (= "a" (form :name)) "simple char name"))
(assert (= 97 (form :ch)) "simple char codepoint"))
(print "All reader tests passed!")