-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bff2a53
commit e651e1b
Showing
17 changed files
with
1,249 additions
and
714 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. | ||
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
(.using | ||
[library | ||
[lux (.except text macro) | ||
[type | ||
["[0]" nominal]] | ||
[aspect | ||
["[0]" view (.only View)]] | ||
[math | ||
["[0]" random (.only Random) (.use "[1]#[0]" functor)] | ||
[number | ||
[/64 | ||
["n" natural]]]] | ||
[function | ||
[predicate (.only Predicate)]] | ||
[error | ||
["[0]" try (.only Try)] | ||
["[0]" exception (.only Exception)]] | ||
[abstract | ||
[equivalence (.only Equivalence)]]]] | ||
["[0]" //]) | ||
|
||
(nominal.every .public Slice | ||
(Record | ||
[#space Text | ||
#origin Natural | ||
#size Natural]) | ||
|
||
(the .public (whole it) | ||
(-> Text | ||
Slice) | ||
(nominal.of [#space it | ||
#origin 0 | ||
#size (//.size it)])) | ||
|
||
(exception.the .public (cannot_slice [space origin size]) | ||
(Exception [Text Natural Natural]) | ||
(exception.report | ||
(list ["Origin" (by n.base_10 as origin)] | ||
["Size" (by n.base_10 as size)] | ||
["Space" (//.as_text space)]))) | ||
|
||
(the .public (partial origin size space) | ||
(-> Natural Natural Text | ||
(Try Slice)) | ||
(if (n.<= (//.size space) (n.+ origin size)) | ||
{try.#Success (nominal.of [#space space | ||
#origin origin | ||
#size size])} | ||
(exception.except ..cannot_slice [space origin size]))) | ||
|
||
(the (as_text it) | ||
(-> Slice | ||
Text) | ||
(let [it (nominal.as it)] | ||
(.text_clip# (its #origin it) | ||
(its #size it) | ||
(its #space it)))) | ||
|
||
(the .public text | ||
(View Slice | ||
Text) | ||
(view.new whole as_text)) | ||
|
||
(the .public size | ||
(-> Slice | ||
Natural) | ||
(|>> nominal.as | ||
(its #size))) | ||
|
||
(the .public empty | ||
Slice | ||
(whole //.empty)) | ||
|
||
(the .public empty? | ||
(Predicate Slice) | ||
(|>> size | ||
(n.= 0))) | ||
|
||
(these (the macro (.in_module# .prelude template#macro)) | ||
(the with_template (.in_module# .prelude with_template)) | ||
(with_template [,name ,slot] | ||
[(the ,name | ||
(macro (_ ,it) | ||
[(its ,slot (nominal.as ,it))]))] | ||
|
||
[[space ..#space] | ||
[origin ..#origin]])) | ||
|
||
(the .public (+ origin it) | ||
(-> Slice | ||
(Change Slice)) | ||
(if (empty? origin) | ||
it | ||
|
||
(empty? it) | ||
origin | ||
|
||
(let [same_space! | ||
(same? (..space origin) | ||
(..space it)) | ||
|
||
contiguity! | ||
(n.= (n.+ (..origin origin) | ||
(..size origin)) | ||
(..origin it))] | ||
(and same_space! | ||
contiguity!)) | ||
(nominal.of [#space (..space origin) | ||
#origin (..origin origin) | ||
#size (n.+ (..size origin) (..size it))]) | ||
|
||
... else | ||
(whole (.text (as_text origin) (as_text it))))) | ||
|
||
(the .public (random size) | ||
(-> Natural | ||
(Random Slice)) | ||
(|> (random.upper_cased size) | ||
(random#each whole))) | ||
|
||
(the .public (= reference it) | ||
(-> Slice | ||
(Predicate Slice)) | ||
(//.= (as_text reference) | ||
(as_text it))) | ||
|
||
(the .public equivalence | ||
(Equivalence Slice) | ||
(implementation | ||
(the = ..=))) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.