diff options
author | Eduardo Julian | 2020-12-10 22:29:32 -0400 |
---|---|---|
committer | Eduardo Julian | 2020-12-10 22:29:32 -0400 |
commit | 9af671a34728b35c48bff2ba163c371dc5084946 (patch) | |
tree | ec35f32b8f0cabec702708e0e3cc4462b587c752 /stdlib/source/lux/data/text/buffer.lux | |
parent | d747aada2d6df6538d0a88d70169f3757aef50af (diff) |
Render XML to text in an indented form for human readability.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/data/text/buffer.lux | 103 |
1 files changed, 56 insertions, 47 deletions
diff --git a/stdlib/source/lux/data/text/buffer.lux b/stdlib/source/lux/data/text/buffer.lux index 0e21157ba..397501cd2 100644 --- a/stdlib/source/lux/data/text/buffer.lux +++ b/stdlib/source/lux/data/text/buffer.lux @@ -1,6 +1,9 @@ (.module: [lux #* [host (#+ import:)] + ["@" target] + [control + ["." function]] [data ["." product] [number @@ -9,29 +12,31 @@ ["%" format (#+ format)]] [collection ["." row (#+ Row) ("#\." fold)]]] - [compiler - ["_" host]] [type abstract]] ["." //]) -(`` (for {(~~ (static _.old)) - (as-is (import: java/lang/CharSequence) +(with-expansions [<jvm> (as-is (import: java/lang/CharSequence) - (import: java/lang/Appendable - (append [java/lang/CharSequence] java/lang/Appendable)) + (import: java/lang/Appendable + ["#::." + (append [java/lang/CharSequence] java/lang/Appendable)]) - (import: java/lang/String - (new [int]) - (toString [] java/lang/String)) + (import: java/lang/String + ["#::." + (new [int]) + (toString [] java/lang/String)]) - (import: java/lang/StringBuilder - (new [int]) - (toString [] java/lang/String)))})) + (import: java/lang/StringBuilder + ["#::." + (new [int]) + (toString [] java/lang/String)]))] + (`` (for {@.old (as-is <jvm>) + @.jvm (as-is <jvm>)}))) (`` (abstract: #export Buffer - (for {(~~ (static _.old)) - [Nat (-> java/lang/StringBuilder java/lang/StringBuilder)]} + (for {@.old [Nat (-> java/lang/StringBuilder java/lang/StringBuilder)] + @.jvm [Nat (-> java/lang/StringBuilder java/lang/StringBuilder)]} ## default (Row Text)) @@ -39,45 +44,49 @@ (def: #export empty Buffer - (:abstraction (for {(~~ (static _.old)) - [0 id]} - ## default - row.empty))) + (:abstraction (with-expansions [<jvm> [0 function.identity]] + (for {@.old <jvm> + @.jvm <jvm>} + ## default + row.empty)))) (def: #export (append chunk buffer) (-> Text Buffer Buffer) - (for {(~~ (static _.old)) - (let [[capacity transform] (:representation buffer) - append! (: (-> Text java/lang/StringBuilder java/lang/StringBuilder) - (function (_ chunk builder) - (exec (java/lang/Appendable::append (:coerce java/lang/CharSequence chunk) - builder) - builder)))] - (:abstraction [(n.+ (//.size chunk) capacity) - (|>> transform (append! chunk))]))} - ## default - (|> buffer :representation (row.add chunk) :abstraction))) + (with-expansions [<jvm> (let [[capacity transform] (:representation buffer) + append! (: (-> Text java/lang/StringBuilder java/lang/StringBuilder) + (function (_ chunk builder) + (exec (java/lang/Appendable::append (:coerce java/lang/CharSequence chunk) + builder) + builder)))] + (:abstraction [(n.+ (//.size chunk) capacity) + (|>> transform (append! chunk))]))] + (for {@.old <jvm> + @.jvm <jvm>} + ## default + (|> buffer :representation (row.add chunk) :abstraction)))) - (def: #export (size buffer) + (def: #export size (-> Buffer Nat) - (for {(~~ (static _.old)) - (|> buffer :representation product.left)} - ## default - (row\fold (function (_ chunk total) - (n.+ (//.size chunk) total)) - 0 - (:representation buffer)))) + (with-expansions [<jvm> (|>> :representation product.left)] + (for {@.old <jvm> + @.jvm <jvm>} + ## default + (|>> :representation + (row\fold (function (_ chunk total) + (n.+ (//.size chunk) total)) + 0))))) (def: #export (text buffer) (-> Buffer Text) - (for {(~~ (static _.old)) - (let [[capacity transform] (:representation buffer)] - (|> (java/lang/StringBuilder::new (.int capacity)) - transform - java/lang/StringBuilder::toString))} - ## default - (row\fold (function (_ chunk total) - (format total chunk)) - "" - (:representation buffer)))) + (with-expansions [<jvm> (let [[capacity transform] (:representation buffer)] + (|> (java/lang/StringBuilder::new (.int capacity)) + transform + java/lang/StringBuilder::toString))] + (for {@.old <jvm> + @.jvm <jvm>} + ## default + (row\fold (function (_ chunk total) + (format total chunk)) + "" + (:representation buffer))))) )) |