aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/data/format
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/data/format')
-rw-r--r--stdlib/source/lux/data/format/html.lux18
-rw-r--r--stdlib/source/lux/data/format/json.lux12
-rw-r--r--stdlib/source/lux/data/format/xml.lux12
3 files changed, 22 insertions, 20 deletions
diff --git a/stdlib/source/lux/data/format/html.lux b/stdlib/source/lux/data/format/html.lux
index cc5e6d0e9..45a7117ad 100644
--- a/stdlib/source/lux/data/format/html.lux
+++ b/stdlib/source/lux/data/format/html.lux
@@ -18,7 +18,7 @@
(text.replace-all "&" "&")
(text.replace-all "<" "&lt;")
(text.replace-all ">" "&gt;")
- (text.replace-all "\"" "&quot;")
+ (text.replace-all text.double-quote "&quot;")
(text.replace-all "'" "&#x27;")
(text.replace-all "/" "&#x2F;")))
@@ -28,7 +28,7 @@
(def: attrs-to-text
(-> Attributes Text)
- (|>> (list/map (function (_ [key val]) (format key "=" "\"" (text val) "\"")))
+ (|>> (list/map (function (_ [key val]) (format key "=" text.double-quote (text val) text.double-quote)))
(text.join-with " ")))
(def: #export (tag name attrs children)
@@ -39,13 +39,15 @@
"</" name ">"))
(do-template [<name> <doc-type>]
- [(def: #export (<name> document)
+ [(def: #export <name>
(-> HTML HTML)
- (format <doc-type>
- document))]
+ (let [doc-type <doc-type>]
+ (function (_ document)
+ (format doc-type
+ document))))]
[html-5 "<!DOCTYPE html>"]
- [html-4_01 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">"]
- [xhtml-1_0 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"]
- [xhtml-1_1 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">"]
+ [html-4_01 (format "<!DOCTYPE HTML PUBLIC " text.double-quote "-//W3C//DTD HTML 4.01//EN" text.double-quote " " text.double-quote "http://www.w3.org/TR/html4/strict.dtd" text.double-quote ">")]
+ [xhtml-1_0 (format "<!DOCTYPE html PUBLIC " text.double-quote "-//W3C//DTD XHTML 1.0 Strict//EN" text.double-quote " " text.double-quote "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" text.double-quote ">")]
+ [xhtml-1_1 (format "<!DOCTYPE html PUBLIC " text.double-quote "-//W3C//DTD XHTML 1.1//EN" text.double-quote " " text.double-quote "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" text.double-quote ">")]
)
diff --git a/stdlib/source/lux/data/format/json.lux b/stdlib/source/lux/data/format/json.lux
index 1d0837b90..9189b375f 100644
--- a/stdlib/source/lux/data/format/json.lux
+++ b/stdlib/source/lux/data/format/json.lux
@@ -113,10 +113,10 @@
(#e.Success value)
#.None
- (#e.Error ($_ text/compose "Missing field \"" key "\" on object.")))
+ (#e.Error ($_ text/compose "Missing field '" key "' on object.")))
_
- (#e.Error ($_ text/compose "Cannot get field \"" key "\" of a non-object."))))
+ (#e.Error ($_ text/compose "Cannot get field '" key "' of a non-object."))))
(def: #export (set key value json)
{#.doc "A JSON object field setter."}
@@ -126,7 +126,7 @@
(#e.Success (#Object (dict.put key value obj)))
_
- (#e.Error ($_ text/compose "Cannot set field \"" key "\" of a non-object."))))
+ (#e.Error ($_ text/compose "Cannot set field '" key "' of a non-object."))))
(do-template [<name> <tag> <type> <desc>]
[(def: #export (<name> key json)
@@ -352,7 +352,7 @@
(fail error))
_
- (fail ($_ text/compose "JSON object does not have field \"" field-name "\".")))
+ (fail ($_ text/compose "JSON object does not have field '" field-name "'.")))
_
(fail "JSON value is not an object."))))
@@ -469,10 +469,10 @@
(def: string~
(l.Lexer String)
- (<| (l.enclosed ["\"" "\""])
+ (<| (l.enclosed [text.double-quote text.double-quote])
(loop [_ []])
(do p.Monad<Parser>
- [chars (l.some (l.none-of "\\\""))
+ [chars (l.some (l.none-of (text/compose "\\" text.double-quote)))
stop l.peek])
(if (text/= "\\" stop)
(do @
diff --git a/stdlib/source/lux/data/format/xml.lux b/stdlib/source/lux/data/format/xml.lux
index 61215813b..a5cb39ab5 100644
--- a/stdlib/source/lux/data/format/xml.lux
+++ b/stdlib/source/lux/data/format/xml.lux
@@ -33,7 +33,7 @@
(p.after (l.this "&gt;") (parser/wrap ">"))
(p.after (l.this "&amp;") (parser/wrap "&"))
(p.after (l.this "&apos;") (parser/wrap "'"))
- (p.after (l.this "&quot;") (parser/wrap "\""))))
+ (p.after (l.this "&quot;") (parser/wrap text.double-quote))))
(def: xml-unicode-escape-char^
(l.Lexer Text)
@@ -56,7 +56,7 @@
(def: xml-char^
(l.Lexer Text)
- (p.either (l.none-of "<>&'\"")
+ (p.either (l.none-of ($_ text/compose "<>&'" text.double-quote))
xml-escape-char^))
(def: xml-identifier
@@ -92,7 +92,7 @@
(def: attr-value^
(l.Lexer Text)
(let [value^ (l.some xml-char^)]
- (p.either (l.enclosed ["\"" "\""] value^)
+ (p.either (l.enclosed [text.double-quote text.double-quote] value^)
(l.enclosed ["'" "'"] value^))))
(def: attrs^
@@ -181,7 +181,7 @@
(text.replace-all "<" "&lt;")
(text.replace-all ">" "&gt;")
(text.replace-all "'" "&apos;")
- (text.replace-all "\"" "&quot;")))
+ (text.replace-all text.double-quote "&quot;")))
(def: (write-tag [namespace name])
(-> Tag Text)
@@ -194,12 +194,12 @@
(|> attrs
d.entries
(list/map (function (_ [key value])
- ($_ text/compose (write-tag key) "=" "\""(sanitize-value value) "\"")))
+ ($_ text/compose (write-tag key) "=" text.double-quote (sanitize-value value) text.double-quote)))
(text.join-with " ")))
(def: xml-header
Text
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
+ ($_ text/compose "<?xml version=" text.double-quote "1.0" text.double-quote " encoding=" text.double-quote "UTF-8" text.double-quote "?>"))
(def: #export (write input)
(-> XML Text)