|
| 1 | +... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. |
| 2 | +... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 3 | + |
| 4 | +(.using |
| 5 | + [library |
| 6 | + [lux (.except text macro) |
| 7 | + [type |
| 8 | + ["[0]" nominal]] |
| 9 | + [aspect |
| 10 | + ["[0]" view (.only View)]] |
| 11 | + [math |
| 12 | + ["[0]" random (.only Random) (.use "[1]#[0]" functor)] |
| 13 | + [number |
| 14 | + [/64 |
| 15 | + ["n" natural]]]] |
| 16 | + [function |
| 17 | + [predicate (.only Predicate)]] |
| 18 | + [error |
| 19 | + ["[0]" try (.only Try)] |
| 20 | + ["[0]" exception (.only Exception)]] |
| 21 | + [abstract |
| 22 | + [equivalence (.only Equivalence)]]]] |
| 23 | + ["[0]" //]) |
| 24 | + |
| 25 | +(nominal.every .public Slice |
| 26 | + (Record |
| 27 | + [#space Text |
| 28 | + #origin Natural |
| 29 | + #size Natural]) |
| 30 | + |
| 31 | + (the .public (whole it) |
| 32 | + (-> Text |
| 33 | + Slice) |
| 34 | + (nominal.of [#space it |
| 35 | + #origin 0 |
| 36 | + #size (//.size it)])) |
| 37 | + |
| 38 | + (exception.the .public (cannot_slice [space origin size]) |
| 39 | + (Exception [Text Natural Natural]) |
| 40 | + (exception.report |
| 41 | + (list ["Origin" (by n.base_10 as origin)] |
| 42 | + ["Size" (by n.base_10 as size)] |
| 43 | + ["Space" (//.as_text space)]))) |
| 44 | + |
| 45 | + (the .public (partial origin size space) |
| 46 | + (-> Natural Natural Text |
| 47 | + (Try Slice)) |
| 48 | + (if (n.<= (//.size space) (n.+ origin size)) |
| 49 | + {try.#Success (nominal.of [#space space |
| 50 | + #origin origin |
| 51 | + #size size])} |
| 52 | + (exception.except ..cannot_slice [space origin size]))) |
| 53 | + |
| 54 | + (the (as_text it) |
| 55 | + (-> Slice |
| 56 | + Text) |
| 57 | + (let [it (nominal.as it)] |
| 58 | + (.text_clip# (its #origin it) |
| 59 | + (its #size it) |
| 60 | + (its #space it)))) |
| 61 | + |
| 62 | + (the .public text |
| 63 | + (View Slice |
| 64 | + Text) |
| 65 | + (view.new whole as_text)) |
| 66 | + |
| 67 | + (the .public size |
| 68 | + (-> Slice |
| 69 | + Natural) |
| 70 | + (|>> nominal.as |
| 71 | + (its #size))) |
| 72 | + |
| 73 | + (the .public empty |
| 74 | + Slice |
| 75 | + (whole //.empty)) |
| 76 | + |
| 77 | + (the .public empty? |
| 78 | + (Predicate Slice) |
| 79 | + (|>> size |
| 80 | + (n.= 0))) |
| 81 | + |
| 82 | + (these (the macro (.in_module# .prelude template#macro)) |
| 83 | + (the with_template (.in_module# .prelude with_template)) |
| 84 | + (with_template [,name ,slot] |
| 85 | + [(the ,name |
| 86 | + (macro (_ ,it) |
| 87 | + [(its ,slot (nominal.as ,it))]))] |
| 88 | + |
| 89 | + [[space ..#space] |
| 90 | + [origin ..#origin]])) |
| 91 | + |
| 92 | + (the .public (+ origin it) |
| 93 | + (-> Slice |
| 94 | + (Change Slice)) |
| 95 | + (if (empty? origin) |
| 96 | + it |
| 97 | + |
| 98 | + (empty? it) |
| 99 | + origin |
| 100 | + |
| 101 | + (let [same_space! |
| 102 | + (same? (..space origin) |
| 103 | + (..space it)) |
| 104 | + |
| 105 | + contiguity! |
| 106 | + (n.= (n.+ (..origin origin) |
| 107 | + (..size origin)) |
| 108 | + (..origin it))] |
| 109 | + (and same_space! |
| 110 | + contiguity!)) |
| 111 | + (nominal.of [#space (..space origin) |
| 112 | + #origin (..origin origin) |
| 113 | + #size (n.+ (..size origin) (..size it))]) |
| 114 | + |
| 115 | + ... else |
| 116 | + (whole (.text (as_text origin) (as_text it))))) |
| 117 | + |
| 118 | + (the .public (random size) |
| 119 | + (-> Natural |
| 120 | + (Random Slice)) |
| 121 | + (|> (random.upper_cased size) |
| 122 | + (random#each whole))) |
| 123 | + |
| 124 | + (the .public (= reference it) |
| 125 | + (-> Slice |
| 126 | + (Predicate Slice)) |
| 127 | + (//.= (as_text reference) |
| 128 | + (as_text it))) |
| 129 | + |
| 130 | + (the .public equivalence |
| 131 | + (Equivalence Slice) |
| 132 | + (implementation |
| 133 | + (the = ..=))) |
| 134 | + ) |
0 commit comments