diff options
author | Eduardo Julian | 2020-11-28 21:40:29 -0400 |
---|---|---|
committer | Eduardo Julian | 2020-11-28 21:40:29 -0400 |
commit | 7444deb1b80d469280fcb0684d91c13f752a86d6 (patch) | |
tree | 132f8aa480dad400c20971f5e085876da8772b75 /stdlib/source/lux/data/format | |
parent | a02b7bf8ff358ccfa35b03272d28537aeac723ae (diff) |
Re-named "_.claim" to "_.cover'".
Diffstat (limited to 'stdlib/source/lux/data/format')
-rw-r--r-- | stdlib/source/lux/data/format/binary.lux | 12 | ||||
-rw-r--r-- | stdlib/source/lux/data/format/html.lux | 22 | ||||
-rw-r--r-- | stdlib/source/lux/data/format/json.lux | 62 | ||||
-rw-r--r-- | stdlib/source/lux/data/format/tar.lux | 16 | ||||
-rw-r--r-- | stdlib/source/lux/data/format/xml.lux | 189 |
5 files changed, 151 insertions, 150 deletions
diff --git a/stdlib/source/lux/data/format/binary.lux b/stdlib/source/lux/data/format/binary.lux index 111d6abe8..692dc37ee 100644 --- a/stdlib/source/lux/data/format/binary.lux +++ b/stdlib/source/lux/data/format/binary.lux @@ -10,7 +10,7 @@ [pipe (#+ case>)] ["." function] ["." try (#+ Try)] - ["<>" parser ("#@." monad) + ["<>" parser ("#\." monad) ["/" binary (#+ Offset Size Parser)]]] [data ["." product] @@ -24,7 +24,7 @@ ["%" format (#+ format)]] [collection ["." list] - ["." row (#+ Row) ("#@." functor)] + ["." row (#+ Row) ("#\." functor)] ["." set (#+ Set)]]]]) (def: mask @@ -184,13 +184,13 @@ value (if (n.= original-count capped-count) value (|> value row.to-list (list.take capped-count) row.from-list)) - (^open "specification@.") ..monoid + (^open "specification\.") ..monoid [size mutation] (|> value - (row@map valueW) + (row\map valueW) (:: row.fold fold (function (_ post pre) - (specification@compose pre post)) - specification@identity))] + (specification\compose pre post)) + specification\identity))] [(n.+ <size> size) (function (_ [offset binary]) (try.assume diff --git a/stdlib/source/lux/data/format/html.lux b/stdlib/source/lux/data/format/html.lux index a5fbce4d7..62991f6b9 100644 --- a/stdlib/source/lux/data/format/html.lux +++ b/stdlib/source/lux/data/format/html.lux @@ -3,11 +3,11 @@ ["." function] [data ["." product] - ["." maybe ("#@." functor)] + ["." maybe ("#\." functor)] ["." text ["%" format (#+ format)]] [collection - ["." list ("#@." functor fold)]]] + ["." list ("#\." functor fold)]]] [type abstract] [host @@ -60,7 +60,7 @@ (def: attributes (-> Attributes Text) - (|>> (list@map (function (_ [key val]) + (|>> (list\map (function (_ [key val]) (format key "=" text.double-quote (..sanitize val) text.double-quote))) (text.join-with " "))) @@ -186,7 +186,7 @@ (def: #export (script attributes inline) (-> Attributes (Maybe Script) Meta) (|> inline - (maybe@map js.code) + (maybe\map js.code) (maybe.default "") (..raw "script" attributes))) @@ -254,7 +254,7 @@ (def: (%polygon [first second third extra]) (Format Polygon) (|> (list& first second third extra) - (list@map %coord) + (list\map %coord) (text.join-with ..coord-separator))) (type: #export Shape @@ -290,13 +290,13 @@ (-> Attributes (List [Attributes Shape]) Image Image) ($_ ..and for - (case (list@map (product.uncurry ..area) areas) + (case (list\map (product.uncurry ..area) areas) #.Nil (..empty "map" attributes) (#.Cons head tail) (..tag "map" attributes - (list@fold (function.flip ..and) head tail))))) + (list\fold (function.flip ..and) head tail))))) (template [<name> <tag> <type>] [(def: #export <name> @@ -450,7 +450,7 @@ (def: #export (description-list attributes descriptions) (-> Attributes (List [Content Element]) Element) - (case (list@map (function (_ [term description]) + (case (list\map (function (_ [term description]) ($_ ..and (..term term) (..description description))) @@ -460,7 +460,7 @@ (#.Cons head tail) (..tag "dl" attributes - (list@fold (function.flip ..and) head tail)))) + (list\fold (function.flip ..and) head tail)))) (def: #export p ..paragraph) @@ -512,14 +512,14 @@ (def: #export (table attributes caption columns headers rows footer) (-> Attributes (Maybe Content) (Maybe Column) Header (List Cell) (Maybe Cell) Element) (let [head (..table-head (..table-row headers)) - content (case (list@map table-row rows) + content (case (list\map table-row rows) #.Nil head (#.Cons first rest) (..and head (..table-body - (list@fold (function.flip ..and) first rest)))) + (list\fold (function.flip ..and) first rest)))) content (case footer #.None content diff --git a/stdlib/source/lux/data/format/json.lux b/stdlib/source/lux/data/format/json.lux index a5611a7c3..5f46f997e 100644 --- a/stdlib/source/lux/data/format/json.lux +++ b/stdlib/source/lux/data/format/json.lux @@ -10,19 +10,19 @@ [control pipe ["." try (#+ Try)] - ["<>" parser ("#@." monad) + ["<>" parser ("#\." monad) ["<.>" text (#+ Parser)]]] [data ["." bit] ["." maybe] ["." product] - ["." text ("#@." equivalence monoid)] + ["." text ("#\." equivalence monoid)] [number ["n" nat] - ["f" frac ("#@." decimal)]] + ["f" frac ("#\." decimal)]] [collection - ["." list ("#@." fold functor)] - ["." row (#+ Row row) ("#@." monad)] + ["." list ("#\." fold functor)] + ["." row (#+ Row row) ("#\." monad)] ["." dictionary (#+ Dictionary)]]] [macro [syntax (#+ syntax:)] @@ -86,7 +86,7 @@ (wrap (list (` (: JSON #..Null)))) [_ (#.Tuple members)] - (wrap (list (` (: JSON (#..Array ((~! row) (~+ (list@map wrapper members)))))))) + (wrap (list (` (: JSON (#..Array ((~! row) (~+ (list\map wrapper members)))))))) [_ (#.Record pairs)] (do {! ..monad} @@ -114,7 +114,7 @@ (#try.Success (dictionary.keys obj)) _ - (#try.Failure ($_ text@compose "Cannot get the fields of a non-object.")))) + (#try.Failure ($_ text\compose "Cannot get the fields of a non-object.")))) (def: #export (get key json) {#.doc "A JSON object field getter."} @@ -126,10 +126,10 @@ (#try.Success value) #.None - (#try.Failure ($_ text@compose "Missing field '" key "' on object."))) + (#try.Failure ($_ text\compose "Missing field '" key "' on object."))) _ - (#try.Failure ($_ text@compose "Cannot get field '" key "' on a non-object.")))) + (#try.Failure ($_ text\compose "Cannot get field '" key "' on a non-object.")))) (def: #export (set key value json) {#.doc "A JSON object field setter."} @@ -139,18 +139,18 @@ (#try.Success (#Object (dictionary.put key value obj))) _ - (#try.Failure ($_ text@compose "Cannot set field '" key "' on a non-object.")))) + (#try.Failure ($_ text\compose "Cannot set field '" key "' on a non-object.")))) (template [<name> <tag> <type> <desc>] [(def: #export (<name> key json) - {#.doc (code.text ($_ text@compose "A JSON object field getter for " <desc> "."))} + {#.doc (code.text ($_ text\compose "A JSON object field getter for " <desc> "."))} (-> Text JSON (Try <type>)) (case (get key json) (#try.Success (<tag> value)) (#try.Success value) (#try.Success _) - (#try.Failure ($_ text@compose "Wrong value type at key: " key)) + (#try.Failure ($_ text\compose "Wrong value type at key: " key)) (#try.Failure error) (#try.Failure error)))] @@ -179,7 +179,7 @@ [(#Array xs) (#Array ys)] (and (n.= (row.size xs) (row.size ys)) - (list@fold (function (_ idx prev) + (list\fold (function (_ idx prev) (and prev (maybe.default #0 (do maybe.monad @@ -191,7 +191,7 @@ [(#Object xs) (#Object ys)] (and (n.= (dictionary.size xs) (dictionary.size ys)) - (list@fold (function (_ [xk xv] prev) + (list\fold (function (_ [xk xv] prev) (and prev (case (dictionary.get xk ys) #.None #0 @@ -226,7 +226,7 @@ (|> raw (text.split 1) maybe.assume product.right)))))) (def: escape "\") -(def: escaped-dq (text@compose ..escape text.double-quote)) +(def: escaped-dq (text\compose ..escape text.double-quote)) (def: format-string (-> String Text) @@ -250,14 +250,14 @@ (def: (format-array format) (-> (-> JSON Text) (-> Array Text)) - (|>> (row@map format) + (|>> (row\map format) row.to-list (text.join-with ..separator) (text.enclose [..open-array ..close-array]))) (def: (format-kv format [key value]) (-> (-> JSON Text) (-> [String JSON] Text)) - ($_ text@compose + ($_ text\compose (..format-string key) ..entry-separator (format value) @@ -266,7 +266,7 @@ (def: (format-object format) (-> (-> JSON Text) (-> Object Text)) (|>> dictionary.entries - (list@map (..format-kv format)) + (list\map (..format-kv format)) (text.join-with ..separator) (text.enclose [..open-object ..close-object]))) @@ -336,8 +336,8 @@ [mark (<text>.one-of "eE") signed?' (<>.parses? (<text>.this "-")) offset (<text>.many <text>.decimal)] - (wrap ($_ text@compose mark (if signed?' "-" "") offset))))] - (case (f@decode ($_ text@compose (if signed? "-" "") digits "." decimals exp)) + (wrap ($_ text\compose mark (if signed?' "-" "") offset))))] + (case (f\decode ($_ text\compose (if signed? "-" "") digits "." decimals exp)) (#try.Failure message) (<>.fail message) @@ -348,32 +348,32 @@ (Parser Text) ($_ <>.either (<>.after (<text>.this "\t") - (<>@wrap text.tab)) + (<>\wrap text.tab)) (<>.after (<text>.this "\b") - (<>@wrap text.back-space)) + (<>\wrap text.back-space)) (<>.after (<text>.this "\n") - (<>@wrap text.new-line)) + (<>\wrap text.new-line)) (<>.after (<text>.this "\r") - (<>@wrap text.carriage-return)) + (<>\wrap text.carriage-return)) (<>.after (<text>.this "\f") - (<>@wrap text.form-feed)) - (<>.after (<text>.this (text@compose "\" text.double-quote)) - (<>@wrap text.double-quote)) + (<>\wrap text.form-feed)) + (<>.after (<text>.this (text\compose "\" text.double-quote)) + (<>\wrap text.double-quote)) (<>.after (<text>.this "\\") - (<>@wrap "\")))) + (<>\wrap "\")))) (def: parse-string (Parser String) (<| (<text>.enclosed [text.double-quote text.double-quote]) (loop [_ []]) (do {! <>.monad} - [chars (<text>.some (<text>.none-of (text@compose "\" text.double-quote))) + [chars (<text>.some (<text>.none-of (text\compose "\" text.double-quote))) stop <text>.peek]) - (if (text@= "\" stop) + (if (text\= "\" stop) (do ! [escaped parse-escaped next-chars (recur [])] - (wrap ($_ text@compose chars escaped next-chars))) + (wrap ($_ text\compose chars escaped next-chars))) (wrap chars)))) (def: (parse-kv parse-json) diff --git a/stdlib/source/lux/data/format/tar.lux b/stdlib/source/lux/data/format/tar.lux index 65e25c528..c18d81d33 100644 --- a/stdlib/source/lux/data/format/tar.lux +++ b/stdlib/source/lux/data/format/tar.lux @@ -18,10 +18,10 @@ ["n" nat] ["." i64]] ["." format #_ - ["#" binary (#+ Writer) ("#@." monoid)]] + ["#" binary (#+ Writer) ("#\." monoid)]] [collection - ["." list ("#@." fold)] - ["." row (#+ Row) ("#@." fold)]]] + ["." list ("#\." fold)] + ["." row (#+ Row) ("#\." fold)]]] [time ["." instant (#+ Instant)] ["." duration]] @@ -56,7 +56,7 @@ Nat (|> ..octal-size (list.repeat <size>) - (list@fold n.* 1) + (list\fold n.* 1) inc)) (exception: #export (<exception> {value Nat}) @@ -515,7 +515,7 @@ Nat (|> ..octal-size (list.repeat ..content-size) - (list@fold n.* 1))) + (list\fold n.* 1))) (abstract: #export Content [Big Binary] @@ -720,9 +720,9 @@ (Writer Tar) (let [end-of-archive (binary.create ..end-of-archive-size)] (function (_ tar) - (format@compose (row@fold (function (_ next total) - (format@compose total (..entry-writer next))) - format@identity + (format\compose (row\fold (function (_ next total) + (format\compose total (..entry-writer next))) + format\identity tar) (format.segment ..end-of-archive-size end-of-archive))))) diff --git a/stdlib/source/lux/data/format/xml.lux b/stdlib/source/lux/data/format/xml.lux index b64e2eb62..512438c56 100644 --- a/stdlib/source/lux/data/format/xml.lux +++ b/stdlib/source/lux/data/format/xml.lux @@ -6,17 +6,17 @@ [codec (#+ Codec)]] [control [try (#+ Try)] - ["p" parser ("#@." monad) - ["l" text (#+ Parser)]]] + ["<>" parser ("#\." monad) + ["<.>" text (#+ Parser)]]] [data ["." product] - ["." name ("#@." equivalence codec)] + ["." name ("#\." equivalence codec)] [number ["n" nat] ["." int]] - ["." text ("#@." equivalence monoid)] + ["." text ("#\." equivalence monoid)] [collection - ["." list ("#@." functor)] + ["." list ("#\." functor)] ["." dictionary (#+ Dictionary)]]]]) (type: #export Tag @@ -28,7 +28,7 @@ (type: #export Attrs (Dictionary Attribute Text)) -(def: #export attrs +(def: #export attributes Attrs (dictionary.new name.hash)) @@ -41,51 +41,52 @@ (def: xml-standard-escape-char^ (Parser Text) - ($_ p.either - (p.after (l.this "<") (p@wrap "<")) - (p.after (l.this ">") (p@wrap ">")) - (p.after (l.this "&") (p@wrap "&")) - (p.after (l.this "'") (p@wrap "'")) - (p.after (l.this """) (p@wrap text.double-quote)))) + ($_ <>.either + (<>.after (<text>.this "<") (<>\wrap "<")) + (<>.after (<text>.this ">") (<>\wrap ">")) + (<>.after (<text>.this "&") (<>\wrap "&")) + (<>.after (<text>.this "'") (<>\wrap "'")) + (<>.after (<text>.this """) (<>\wrap text.double-quote)) + )) (def: xml-unicode-escape-char^ (Parser Text) - (|> (do p.monad - [hex? (p.maybe (l.this "x")) + (|> (do <>.monad + [hex? (<>.maybe (<text>.this "x")) code (case hex? #.None - (p.codec int.decimal (l.many l.decimal)) + (<>.codec int.decimal (<text>.many <text>.decimal)) (#.Some _) - (p.codec int.decimal (l.many l.hexadecimal)))] + (<>.codec int.decimal (<text>.many <text>.hexadecimal)))] (wrap (|> code .nat text.from-code))) - (p.before (l.this ";")) - (p.after (l.this "&#")))) + (<>.before (<text>.this ";")) + (<>.after (<text>.this "&#")))) (def: xml-escape-char^ (Parser Text) - (p.either xml-standard-escape-char^ - xml-unicode-escape-char^)) + (<>.either xml-standard-escape-char^ + xml-unicode-escape-char^)) (def: xml-char^ (Parser Text) - (p.either (l.none-of ($_ text@compose "<>&'" text.double-quote)) - xml-escape-char^)) + (<>.either (<text>.none-of ($_ text\compose "<>&'" text.double-quote)) + xml-escape-char^)) (def: xml-identifier (Parser Text) - (do p.monad - [head (p.either (l.one-of "_") - l.alpha) - tail (l.some (p.either (l.one-of "_.-") - l.alpha-num))] - (wrap ($_ text@compose head tail)))) + (do <>.monad + [head (<>.either (<text>.one-of "_") + <text>.alpha) + tail (<text>.some (<>.either (<text>.one-of "_.-") + <text>.alpha-num))] + (wrap ($_ text\compose head tail)))) (def: namespaced-symbol^ (Parser Name) - (do p.monad + (do <>.monad [first-part xml-identifier - ?second-part (<| p.maybe (p.after (l.this ..namespace-separator)) xml-identifier)] + ?second-part (<| <>.maybe (<>.after (<text>.this ..namespace-separator)) xml-identifier)] (case ?second-part #.None (wrap ["" first-part]) @@ -98,94 +99,94 @@ (def: spaced^ (All [a] (-> (Parser a) (Parser a))) - (let [white-space^ (p.some l.space)] - (|>> (p.before white-space^) - (p.after white-space^)))) + (let [white-space^ (<>.some <text>.space)] + (|>> (<>.before white-space^) + (<>.after white-space^)))) (def: attr-value^ (Parser Text) - (let [value^ (l.some xml-char^)] - (p.either (l.enclosed [text.double-quote text.double-quote] value^) - (l.enclosed ["'" "'"] value^)))) + (let [value^ (<text>.some xml-char^)] + (<>.either (<text>.enclosed [text.double-quote text.double-quote] value^) + (<text>.enclosed ["'" "'"] value^)))) (def: attrs^ (Parser Attrs) - (<| (:: p.monad map (dictionary.from-list name.hash)) - p.some - (p.and (spaced^ attr-name^)) - (p.after (l.this "=")) + (<| (:: <>.monad map (dictionary.from-list name.hash)) + <>.some + (<>.and (spaced^ attr-name^)) + (<>.after (<text>.this "=")) (spaced^ attr-value^))) (def: (close-tag^ expected) (-> Tag (Parser [])) - (do p.monad + (do <>.monad [actual (|> tag^ spaced^ - (p.after (l.this "/")) - (l.enclosed ["<" ">"]))] - (p.assert ($_ text@compose "Close tag does not match open tag." text.new-line - "Expected: " (name@encode expected) text.new-line - " Actual: " (name@encode actual) text.new-line) - (name@= expected actual)))) + (<>.after (<text>.this "/")) + (<text>.enclosed ["<" ">"]))] + (<>.assert ($_ text\compose "Close tag does not match open tag." text.new-line + "Expected: " (name\encode expected) text.new-line + " Actual: " (name\encode actual) text.new-line) + (name\= expected actual)))) (def: comment^ (Parser Text) - (|> (l.not (l.this "--")) - l.some - (l.enclosed ["<--" "-->"]) + (|> (<text>.not (<text>.this "--")) + <text>.some + (<text>.enclosed ["<--" "-->"]) spaced^)) (def: xml-header^ (Parser Attrs) (|> (spaced^ attrs^) - (p.before (l.this "?>")) - (p.after (l.this "<?xml")) + (<>.before (<text>.this "?>")) + (<>.after (<text>.this "<?xml")) spaced^)) (def: cdata^ (Parser Text) - (let [end (l.this "]]>")] - (|> (l.some (l.not end)) - (p.after end) - (p.after (l.this "<![CDATA[")) + (let [end (<text>.this "]]>")] + (|> (<text>.some (<text>.not end)) + (<>.after end) + (<>.after (<text>.this "<![CDATA[")) spaced^))) (def: text^ (Parser XML) - (|> (p.either cdata^ - (l.many xml-char^)) - (p@map (|>> #Text)))) + (|> (<>.either cdata^ + (<text>.many xml-char^)) + (<>\map (|>> #Text)))) (def: xml^ (Parser XML) - (|> (p.rec + (|> (<>.rec (function (_ node^) - (p.either text^ - (spaced^ - (do p.monad - [_ (l.this "<") - tag (spaced^ tag^) - attrs (spaced^ attrs^) - #let [no-children^ (do p.monad - [_ (l.this "/>")] - (wrap (#Node tag attrs (list)))) - with-children^ (do p.monad - [_ (l.this ">") - children (p.some node^) - _ (close-tag^ tag)] - (wrap (#Node tag attrs children)))]] - (p.either no-children^ - with-children^)))))) + (<>.either text^ + (spaced^ + (do <>.monad + [_ (<text>.this "<") + tag (spaced^ tag^) + attrs (spaced^ attrs^) + #let [no-children^ (do <>.monad + [_ (<text>.this "/>")] + (wrap (#Node tag attrs (list)))) + with-children^ (do <>.monad + [_ (<text>.this ">") + children (<>.some node^) + _ (close-tag^ tag)] + (wrap (#Node tag attrs children)))]] + (<>.either no-children^ + with-children^)))))) ## This is put outside of the call to "rec" because comments ## cannot be located inside of XML nodes. ## This way, the comments can only be before or after the main document. - (p.before (p.some comment^)) - (p.after (p.some comment^)) - (p.after (p.maybe xml-header^)))) + (<>.before (<>.some comment^)) + (<>.after (<>.some comment^)) + (<>.after (<>.maybe xml-header^)))) -(def: #export read +(def: read (-> Text (Try XML)) - (l.run xml^)) + (<text>.run xml^)) (def: (sanitize-value input) (-> Text Text) @@ -200,7 +201,7 @@ (-> Tag Text) (case namespace "" name - _ ($_ text@compose namespace ..namespace-separator name))) + _ ($_ text\compose namespace ..namespace-separator name))) (def: #export attribute (-> Attribute Text) @@ -210,17 +211,17 @@ (-> Attrs Text) (|> attrs dictionary.entries - (list@map (function (_ [key value]) - ($_ text@compose (..attribute key) "=" text.double-quote (sanitize-value value) text.double-quote))) + (list\map (function (_ [key value]) + ($_ text\compose (..attribute key) "=" text.double-quote (sanitize-value value) text.double-quote))) (text.join-with " "))) (def: xml-header Text - ($_ text@compose "<?xml version=" text.double-quote "1.0" text.double-quote " encoding=" text.double-quote "UTF-8" text.double-quote "?>")) + ($_ 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) +(def: (write input) (-> XML Text) - ($_ text@compose xml-header + ($_ text\compose xml-header (loop [input input] (case input (#Text value) @@ -230,12 +231,12 @@ (let [tag (..tag xml-tag) attrs (if (dictionary.empty? xml-attrs) "" - ($_ text@compose " " (write-attrs xml-attrs)))] + ($_ text\compose " " (write-attrs xml-attrs)))] (if (list.empty? xml-children) - ($_ text@compose "<" tag attrs "/>") - ($_ text@compose "<" tag attrs ">" + ($_ text\compose "<" tag attrs "/>") + ($_ text\compose "<" tag attrs ">" (|> xml-children - (list@map recur) + (list\map recur) (text.join-with "")) "</" tag ">"))))))) @@ -251,11 +252,11 @@ (def: (= reference sample) (case [reference sample] [(#Text reference/value) (#Text sample/value)] - (text@= reference/value sample/value) + (text\= reference/value sample/value) [(#Node reference/tag reference/attrs reference/children) (#Node sample/tag sample/attrs sample/children)] - (and (name@= reference/tag sample/tag) + (and (name\= reference/tag sample/tag) (:: (dictionary.equivalence text.equivalence) = reference/attrs sample/attrs) (n.= (list.size reference/children) (list.size sample/children)) @@ -263,4 +264,4 @@ (list.every? (product.uncurry =)))) _ - #0))) + false))) |