From 872db9ad63d9e6a9b3dfeb068643bce4edfce3a7 Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Wed, 8 Mar 2017 22:49:48 +0000 Subject: [PATCH 01/29] Erl initial port --- src/Data/Char.erl | 7 +++ src/Data/String.erl | 92 ++++++++++++++++++++++++++++++++ src/Data/String.purs | 40 +++++++------- src/Data/String/Regex.erl | 70 ++++++++++++++++++++++++ src/Data/String/Unsafe.erl | 6 +++ test/Test/Data/String.purs | 30 +++++------ test/Test/Data/String/Regex.purs | 8 +-- 7 files changed, 214 insertions(+), 39 deletions(-) create mode 100644 src/Data/Char.erl create mode 100644 src/Data/String.erl create mode 100644 src/Data/String/Regex.erl create mode 100644 src/Data/String/Unsafe.erl diff --git a/src/Data/Char.erl b/src/Data/Char.erl new file mode 100644 index 0000000..0f4f06f --- /dev/null +++ b/src/Data/Char.erl @@ -0,0 +1,7 @@ +-module(data_char@foreign). +-export([toCharCode/1, fromCharCode/1, toLower/1, toUpper/1]). + +toCharCode(C) -> C. +fromCharCode(N) -> N. +toLower(C) -> string:to_lower(C). +toUpper(C) -> string:to_upper(C). diff --git a/src/Data/String.erl b/src/Data/String.erl new file mode 100644 index 0000000..3d31282 --- /dev/null +++ b/src/Data/String.erl @@ -0,0 +1,92 @@ +-module(data_string@foreign). +-export(['_charAt'/4, singleton/1, '_charCodeAt'/4, '_toChar'/3, fromCharArray/1, '_indexOf'/4, '_indexOf\''/5, '_lastIndexOf'/4,'_lastIndexOf\''/5, length/1, take/2, drop/2, count/2, split/2, '_splitAt'/4, toCharArray/1, toUpper/1, toLower/1, trim/1, joinWith/2]). + +'_charAt'(Just,Nothing,I,S) -> + case byte_size(S) of + N when I >= 0, I < N -> Just(binary:at(S, I)); + _ -> Nothing + end; +'_charAt'(Just,Nothing,I,S) -> Nothing. + +singleton(C) -> <>. + +'_charCodeAt'(Just,Nothing,I,S) -> '_charAt'(Just,Nothing,I,S). + +'_toChar'(Just,Nothing,<>) -> Just(C); +'_toChar'(Just,Nothing,_) -> Nothing. + +fromCharArray(A) -> unicode:characters_to_binary(array:to_list(A)). + +'_indexOf'(Just,Nothing,<<>>,_) -> Just(0); +'_indexOf'(Just,Nothing,X,S) -> + case string:str(unicode:characters_to_list(S), unicode:characters_to_list(X)) of + 0 -> Nothing; + N -> Just(N-1) + end. +'_indexOf\''(Just,Nothing,X,StartAt,S) when StartAt < 0; StartAt > byte_size(S) -> Nothing; +'_indexOf\''(Just,Nothing,X,StartAt,S) -> + case '_indexOf'(Just,Nothing,X,drop(StartAt,S)) of + {just,N} -> Just(N+StartAt); + _ -> Nothing + end. + +'_lastIndexOf'(Just,Nothing,<<>>,S) -> Just(byte_size(S)); +'_lastIndexOf'(Just,Nothing,X,S) -> + case string:rstr(unicode:characters_to_list(S), unicode:characters_to_list(X)) of + 0 -> Nothing; + N -> Just(N-1) + end. +'_lastIndexOf\''(Just,Nothing,X,StartAt,S) when StartAt < 0; StartAt > byte_size(S) -> Nothing; +'_lastIndexOf\''(Just,Nothing,X,StartAt,S) -> + case '_lastIndexOf'(Just,Nothing,X,take(min(byte_size(S), StartAt+byte_size(X)),S)) of + {just,N} -> Just(N); + _ -> Nothing + end. + +length(S) -> byte_size(S). + +% '_localeCompare'(Lt,Eq,Gt,S1,S2) -> error("not implemented"). +% replace(S1,S2,S3) -> error("not implemented"). +% replaceAll(S1,S2,S3)-> error("not implemented"). + +take(N,S) when N < 0 -> <<>>; +take(N,S) when N > byte_size(S) -> S; +take(N,S) -> binary:part(S, {0, N}). + +drop(N,S) -> + M = max(0, min(N, byte_size(S))), + binary:part(S, {M, byte_size(S)-M}). + +count(P,<>) -> + case P(C) of + true -> 1+count(P,S); + false -> 0 + end; +count(_,_) -> 0. + +split(Sep,S) -> + Split = re:split(S, Sep), + Res = case {Sep,S} of + {_,<<>>} -> lists:droplast(Split); + {<<>>,_} -> lists:droplast(Split); + _ -> Split + end, + array:from_list(Res). + +'_splitAt'(Just,Nothing,I,S) when I >= 0, I =< byte_size(S) -> + Just(array:from_list([binary:part(S, {0, I}), binary:part(S, {I, byte_size(S)-I})])); +'_splitAt'(Just,Nothing,I,S) -> Nothing. + +toCharArray(S) -> array:from_list(unicode:characters_to_list(S)). + +% TODO ugh +toLower(S) -> unicode:characters_to_binary(string:to_lower(unicode:characters_to_list(S))). + +toUpper(S) -> unicode:characters_to_binary(string:to_upper(unicode:characters_to_list(S))). + +trim(S) -> re:replace(S, "^\\s*(.*?)\\s*$","\\1", [{return, binary}]). + +joinWith(S, XS) -> + XS1 = lists:map(fun unicode:characters_to_list/1, array:to_list(XS)), + Res = string:join(XS1, unicode:characters_to_list(S)), + unicode:characters_to_binary(Res). diff --git a/src/Data/String.purs b/src/Data/String.purs index 9eb2f6c..a2fc01c 100644 --- a/src/Data/String.purs +++ b/src/Data/String.purs @@ -17,9 +17,9 @@ module Data.String , uncons , length , singleton - , localeCompare - , replace - , replaceAll + -- , localeCompare + -- , replace + -- , replaceAll , take , takeWhile , drop @@ -198,23 +198,23 @@ foreign import _lastIndexOf' -- | Returns the number of characters the string is composed of. foreign import length :: String -> Int --- | Locale-aware sort order comparison. -localeCompare :: String -> String -> Ordering -localeCompare = _localeCompare LT EQ GT - -foreign import _localeCompare - :: Ordering - -> Ordering - -> Ordering - -> String - -> String - -> Ordering - --- | Replaces the first occurence of the first argument with the second argument. -foreign import replace :: Pattern -> Replacement -> String -> String - --- | Replaces all occurences of the first argument with the second argument. -foreign import replaceAll :: Pattern -> Replacement -> String -> String +-- -- | Locale-aware sort order comparison. +-- localeCompare :: String -> String -> Ordering +-- localeCompare = _localeCompare LT EQ GT +-- +-- foreign import _localeCompare +-- :: Ordering +-- -> Ordering +-- -> Ordering +-- -> String +-- -> String +-- -> Ordering + +-- -- | Replaces the first occurence of the first argument with the second argument. +-- foreign import replace :: Pattern -> Replacement -> String -> String +-- +-- -- | Replaces all occurences of the first argument with the second argument. +-- foreign import replaceAll :: Pattern -> Replacement -> String -> String -- | Returns the first `n` characters of the string. foreign import take :: Int -> String -> String diff --git a/src/Data/String/Regex.erl b/src/Data/String/Regex.erl new file mode 100644 index 0000000..c20dac0 --- /dev/null +++ b/src/Data/String/Regex.erl @@ -0,0 +1,70 @@ +-module(data_string_regex@foreign). +-export(['showRegex\''/1, 'regex\''/4, source/1, 'flags\''/1, test/2, '_match'/4, replace/3, 'replace\''/3, '_search'/4, split/2]). + +'showRegex\''({_,{S,_}}) -> S. + +flags_to_options([], Acc) -> {opts, Acc}; +flags_to_options([$g|Flags], Acc) -> flags_to_options(Flags, Acc); +flags_to_options([$i|Flags], Acc) -> flags_to_options(Flags, [caseless|Acc]); +flags_to_options([$m|Flags], Acc) -> flags_to_options(Flags, [multiline|Acc]); +flags_to_options([$y|Flags], Acc) -> flags_to_options(Flags, Acc); +flags_to_options([$u|Flags], Acc) -> flags_to_options(Flags, [ucp|[unicode|Acc]]); +flags_to_options(_,_) -> err. + +is_global(S) -> case string:chr(unicode:characters_to_list(S), $g) of + 0 -> false; + _ -> true +end. + +'regex\''(Left,Right,S1,S2) -> + FlagsStr = unicode:characters_to_list(S2), + case flags_to_options(FlagsStr, []) of + {opts, Opts} -> + case re:compile(S1,Opts) of + {ok, R} -> Right({R,{S1,S2}}); + {error, {Err, _}} -> Left(Err) + end; + _ -> Left("Bad flags") +end. + +source({_,{S,_}}) -> S. + +'flags\''(R) -> error("no flags"). + +% exports["flags'"] = function (r) { +% return { +% multiline: r.multiline, +% ignoreCase: r.ignoreCase, +% global: r.global, +% sticky: !!r.sticky, +% unicode: !!r.unicode +% }; +% }; + +test({R,_},S) -> case re:run(S,R) of + {match, _} -> true; + _ -> false +end. + +'_match'(Just,Nothing,{R,_},S) -> case re:run(S,R,[{capture,all,binary}]) of + {match,Res} -> Just(array:from_list(lists:map(Just, Res))); + _ -> Nothing +end. + +replace({R,{_,F}},S1,S2) -> + G = case is_global(F) of true -> [global]; false -> [] end, + re:replace(S2,R,S1,G++[{return,binary}]). +% TODO +'replace\''({R,_},F,S2) -> error("replace' not supported"). + +'_search'(Just,Nothing,{R,_},S) -> case re:run(S,R) of + {match, [{I,_}]} -> Just(I); + _ -> Nothing +end. + +split({R,RS},S) -> + Res = re:split(S,R), + Res1 = case RS of + "" -> lists:droplast(Res); + _ -> Res end, + array:from_list(Res1). diff --git a/src/Data/String/Unsafe.erl b/src/Data/String/Unsafe.erl new file mode 100644 index 0000000..fb425d4 --- /dev/null +++ b/src/Data/String/Unsafe.erl @@ -0,0 +1,6 @@ +-module(data_string_unsafe@foreign). +-export([charCodeAt/2, charAt/2, char/1]). + +charCodeAt(I,S) -> binary:at(S, I). +charAt(I,S) -> binary:at(S, I). +char(<>) -> C. diff --git a/test/Test/Data/String.purs b/test/Test/Data/String.purs index e706ca1..9c765ad 100644 --- a/test/Test/Data/String.purs +++ b/test/Test/Data/String.purs @@ -1,6 +1,6 @@ module Test.Data.String (testString) where -import Prelude (Unit, Ordering(..), (==), ($), bind, negate, not, (/=), (&&)) +import Prelude (Unit, Ordering(..), (==), ($), bind, negate, not, (/=), (&&), show) import Control.Monad.Eff (Eff) import Control.Monad.Eff.Console (CONSOLE, log) @@ -117,20 +117,20 @@ testString = do assert $ length "a" == 1 assert $ length "ab" == 2 - log "localeCompare" - assert $ localeCompare "" "" == EQ - assert $ localeCompare "a" "a" == EQ - assert $ localeCompare "a" "b" == LT - assert $ localeCompare "b" "a" == GT - - log "replace" - assert $ replace (Pattern "b") (Replacement "") "abc" == "ac" - assert $ replace (Pattern "b") (Replacement "!") "abc" == "a!c" - assert $ replace (Pattern "d") (Replacement "!") "abc" == "abc" - - log "replaceAll" - assert $ replaceAll (Pattern "b") (Replacement "") "abbbbbc" == "ac" - assert $ replaceAll (Pattern "[b]") (Replacement "!") "a[b]c" == "a!c" + -- log "localeCompare" + -- assert $ localeCompare "" "" == EQ + -- assert $ localeCompare "a" "a" == EQ + -- assert $ localeCompare "a" "b" == LT + -- assert $ localeCompare "b" "a" == GT + + -- log "replace" + -- assert $ replace (Pattern "b") (Replacement "") "abc" == "ac" + -- assert $ replace (Pattern "b") (Replacement "!") "abc" == "a!c" + -- assert $ replace (Pattern "d") (Replacement "!") "abc" == "abc" + -- + -- log "replaceAll" + -- assert $ replaceAll (Pattern "b") (Replacement "") "abbbbbc" == "ac" + -- assert $ replaceAll (Pattern "[b]") (Replacement "!") "a[b]c" == "a!c" log "take" assert $ take 0 "ab" == "" diff --git a/test/Test/Data/String/Regex.purs b/test/Test/Data/String/Regex.purs index 8b9fc3f..f9cbfcb 100644 --- a/test/Test/Data/String/Regex.purs +++ b/test/Test/Data/String/Regex.purs @@ -31,16 +31,16 @@ testStringRegex = do log "replace" assert $ replace (unsafeRegex "-" noFlags) "!" "a-b-c" == "a!b-c" - log "replace'" - assert $ replace' (unsafeRegex "-" noFlags) (\s xs -> "!") "a-b-c" == "a!b-c" + -- log "replace'" + -- assert $ replace' (unsafeRegex "-" noFlags) (\s xs -> "!") "a-b-c" == "a!b-c" log "search" assert $ search (unsafeRegex "b" noFlags) "abc" == Just 1 assert $ search (unsafeRegex "d" noFlags) "abc" == Nothing log "split" - assert $ split (unsafeRegex "" noFlags) "" == [] - assert $ split (unsafeRegex "" noFlags) "abc" == ["a", "b", "c"] + -- assert $ split (unsafeRegex "" noFlags) "" == [] + -- assert $ split (unsafeRegex "" noFlags) "abc" == ["a", "b", "c"] assert $ split (unsafeRegex "b" noFlags) "" == [""] assert $ split (unsafeRegex "b" noFlags) "abc" == ["a", "c"] From 4ae0e73be0fd60d2d726f27e715870ed3b9d1d2e Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Sun, 2 Apr 2017 15:25:12 +0100 Subject: [PATCH 02/29] Erl fromCharArray with bad chars --- src/Data/String.erl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Data/String.erl b/src/Data/String.erl index 3d31282..15f0390 100644 --- a/src/Data/String.erl +++ b/src/Data/String.erl @@ -15,7 +15,10 @@ singleton(C) -> <>. '_toChar'(Just,Nothing,<>) -> Just(C); '_toChar'(Just,Nothing,_) -> Nothing. -fromCharArray(A) -> unicode:characters_to_binary(array:to_list(A)). +fromCharArray(A) -> case unicode:characters_to_binary(array:to_list(A)) of + {error, S, _} -> S; % In case of hitting bad character, return initial portion! + S -> S +end. '_indexOf'(Just,Nothing,<<>>,_) -> Just(0); '_indexOf'(Just,Nothing,X,S) -> From d659ee884bfc019301a0fff02057af950298ef9e Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Thu, 21 Jun 2018 23:06:29 +0100 Subject: [PATCH 03/29] Erl FFI updates --- src/Data/Char.erl | 7 ------- src/Data/String/CodeUnits.erl | 19 +++++++++++++++---- 2 files changed, 15 insertions(+), 11 deletions(-) delete mode 100644 src/Data/Char.erl diff --git a/src/Data/Char.erl b/src/Data/Char.erl deleted file mode 100644 index 0f4f06f..0000000 --- a/src/Data/Char.erl +++ /dev/null @@ -1,7 +0,0 @@ --module(data_char@foreign). --export([toCharCode/1, fromCharCode/1, toLower/1, toUpper/1]). - -toCharCode(C) -> C. -fromCharCode(N) -> N. -toLower(C) -> string:to_lower(C). -toUpper(C) -> string:to_upper(C). diff --git a/src/Data/String/CodeUnits.erl b/src/Data/String/CodeUnits.erl index c47cf7c..a60b608 100644 --- a/src/Data/String/CodeUnits.erl +++ b/src/Data/String/CodeUnits.erl @@ -1,5 +1,5 @@ -module(data_string_codeUnits@foreign). --export([fromCharArray/1, toCharArray/1, singleton/1, '_charAt'/4, '_toChar'/3,length/1, '_indexOf'/4, '_indexOf\''/5,'_lastIndexOf'/4,'_lastIndexOf\''/5,take/2, drop/2,'_splitAt'/4]). +-export([fromCharArray/1, toCharArray/1, singleton/1, '_charAt'/4, '_toChar'/3,length/1, '_indexOf'/4, '_indexOf\''/5,'_lastIndexOf'/4,'_lastIndexOf\''/5,take/2, drop/2,'_splitAt'/4, countPrefix/2, '_slice'/3, splitAt/2]). fromCharArray(A) -> case unicode:characters_to_binary(array:to_list(A)) of {error, S, _} -> S; % In case of hitting bad character, return initial portion! @@ -61,7 +61,18 @@ drop(N,S) -> '_splitAt'(_,Nothing,_,_) -> Nothing. +countPrefixImpl(_, S, I) when I > byte_size(S) -> I; +countPrefixImpl(P, S, I) -> + case P(binary:at(S, I)) of + true -> countPrefixImpl(P, S, I+1); + false -> I + end. + +countPrefix(P, S) -> countPrefixImpl(P, S, 0). + +'_slice'(B, E, S) -> binary:part(S, B, E). -% countPrefix -% _slice -% splitAt \ No newline at end of file +splitAt(I, S) -> + Start = binary:part(S, 0, I), + End = binary:part(S, I, (binary:size(S)-1)), + #{before => Start, 'after' => End}. From 765d7159ef78afaa2e9f0c2818ae1a19b106c3d9 Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Tue, 18 Sep 2018 14:31:37 +0000 Subject: [PATCH 04/29] Fix string split, implement replace --- src/Data/String/Common.erl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Data/String/Common.erl b/src/Data/String/Common.erl index ac1eda2..05f3616 100644 --- a/src/Data/String/Common.erl +++ b/src/Data/String/Common.erl @@ -2,14 +2,13 @@ -export(['_localeCompare'/5, replace/3, replaceAll/3, split/2, toLower/1, toUpper/1, trim/1, joinWith/2]). '_localeCompare'(_Lt,_Eq,_Gt,_S1,_S2) -> error("not implemented"). -replace(_S1,_S2,_S3) -> error("not implemented"). -replaceAll(_S1,_S2,_S3)-> error("not implemented"). +replace(S1,S2,S3) -> string:replace(S3, S1, S2). +replaceAll(S1,S2,S3) -> string:replace(S3, S1, S2, all). split(Sep,S) -> - Split = re:split(S, Sep), + Split = string:split(S, Sep, all), Res = case {Sep,S} of {_,<<>>} -> lists:droplast(Split); - {<<>>,_} -> lists:droplast(Split); _ -> Split end, array:from_list(Res). From 09d5fa453d590d229c854f298d56d3c0ff5b0deb Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Wed, 19 Sep 2018 08:43:33 +0000 Subject: [PATCH 05/29] Fix splitAt, remove defunct _splitAt --- src/Data/String/CodeUnits.erl | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Data/String/CodeUnits.erl b/src/Data/String/CodeUnits.erl index a60b608..11d0504 100644 --- a/src/Data/String/CodeUnits.erl +++ b/src/Data/String/CodeUnits.erl @@ -1,5 +1,5 @@ -module(data_string_codeUnits@foreign). --export([fromCharArray/1, toCharArray/1, singleton/1, '_charAt'/4, '_toChar'/3,length/1, '_indexOf'/4, '_indexOf\''/5,'_lastIndexOf'/4,'_lastIndexOf\''/5,take/2, drop/2,'_splitAt'/4, countPrefix/2, '_slice'/3, splitAt/2]). +-export([fromCharArray/1, toCharArray/1, singleton/1, '_charAt'/4, '_toChar'/3,length/1, '_indexOf'/4, '_indexOf\''/5,'_lastIndexOf'/4,'_lastIndexOf\''/5,take/2, drop/2, countPrefix/2, '_slice'/3, splitAt/2]). fromCharArray(A) -> case unicode:characters_to_binary(array:to_list(A)) of {error, S, _} -> S; % In case of hitting bad character, return initial portion! @@ -56,11 +56,6 @@ drop(N,S) -> M = max(0, min(N, byte_size(S))), binary:part(S, {M, byte_size(S)-M}). -'_splitAt'(Just,_,I,S) when I >= 0, I =< byte_size(S) -> - Just(array:from_list([binary:part(S, {0, I}), binary:part(S, {I, byte_size(S)-I})])); -'_splitAt'(_,Nothing,_,_) -> Nothing. - - countPrefixImpl(_, S, I) when I > byte_size(S) -> I; countPrefixImpl(P, S, I) -> case P(binary:at(S, I)) of @@ -72,7 +67,8 @@ countPrefix(P, S) -> countPrefixImpl(P, S, 0). '_slice'(B, E, S) -> binary:part(S, B, E). -splitAt(I, S) -> +splitAt(I0, S) -> + I = min(max(0, I0), erlang:byte_size(S)), Start = binary:part(S, 0, I), - End = binary:part(S, I, (binary:size(S)-1)), + End = binary:part(S, I, erlang:byte_size(S)-I), #{before => Start, 'after' => End}. From abf732a17f28832b2847007ea53903b4b0b97856 Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Wed, 3 Apr 2019 15:58:41 +0000 Subject: [PATCH 06/29] Remove pointless case --- src/Data/String/CodeUnits.erl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Data/String/CodeUnits.erl b/src/Data/String/CodeUnits.erl index 11d0504..07c9acd 100644 --- a/src/Data/String/CodeUnits.erl +++ b/src/Data/String/CodeUnits.erl @@ -14,8 +14,7 @@ singleton(C) -> <>. case byte_size(S) of N when I >= 0, I < N -> Just(binary:at(S, I)); _ -> Nothing - end; -'_charAt'(_,Nothing,_,_) -> Nothing. + end. '_toChar'(Just,_,<>) -> Just(C); '_toChar'(_,Nothing,_) -> Nothing. From fc1bead0fb180e292edea4305ceb36cc103169d1 Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Fri, 13 Dec 2019 12:25:06 +0000 Subject: [PATCH 07/29] purerl fix replace, split --- src/Data/String/Common.erl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Data/String/Common.erl b/src/Data/String/Common.erl index 05f3616..70c2c4c 100644 --- a/src/Data/String/Common.erl +++ b/src/Data/String/Common.erl @@ -2,13 +2,18 @@ -export(['_localeCompare'/5, replace/3, replaceAll/3, split/2, toLower/1, toUpper/1, trim/1, joinWith/2]). '_localeCompare'(_Lt,_Eq,_Gt,_S1,_S2) -> error("not implemented"). -replace(S1,S2,S3) -> string:replace(S3, S1, S2). -replaceAll(S1,S2,S3) -> string:replace(S3, S1, S2, all). +replace(S1,S2,S3) -> iolist_to_binary(string:replace(S3, S1, S2)). +replaceAll(S1,S2,S3) -> iolist_to_binary(string:replace(S3, S1, S2, all)). split(Sep,S) -> Split = string:split(S, Sep, all), Res = case {Sep,S} of - {_,<<>>} -> lists:droplast(Split); + {<<>>,<<>>} -> []; %% string:split says [<<>>] but JS says [] + {<<>>,_} -> + %% string:split does not work on empty split pattern + lists:map(fun (C) -> unicode:characters_to_binary([C], utf8) end, unicode:characters_to_list(S, utf8)); + + %% {_,<<>>} behaves the same in JS vs string:split _ -> Split end, array:from_list(Res). From 1ef7b4969f202dedcc3e1089d950a9ce270d4fdc Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Fri, 13 Dec 2019 14:10:27 +0000 Subject: [PATCH 08/29] Off by 1 in code point lookup --- src/Data/String/CodePoints.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/String/CodePoints.erl b/src/Data/String/CodePoints.erl index 0446eb1..535b366 100644 --- a/src/Data/String/CodePoints.erl +++ b/src/Data/String/CodePoints.erl @@ -12,7 +12,7 @@ end. Cps = unicode:characters_to_list(Str, utf8), case length(Cps) of Length when Index < 0, Index >= Length -> Nothing; - _ -> Just(lists:nth(Index, Cps)) + _ -> Just(lists:nth(Index+1, Cps)) end . From a4d68f5fbe3babbab97db08d59dec50f71e3d64a Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Wed, 3 Mar 2021 16:59:11 +0000 Subject: [PATCH 09/29] Tests --- test/Test/Data/String.purs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/test/Test/Data/String.purs b/test/Test/Data/String.purs index c496798..79f9d87 100644 --- a/test/Test/Data/String.purs +++ b/test/Test/Data/String.purs @@ -44,23 +44,23 @@ testString = do assert $ S.contains (Pattern "bc") "abcd" assert $ not S.contains (Pattern "cb") "abcd" - log "localeCompare" - assertEqual - { actual: S.localeCompare "" "" - , expected: EQ - } - assertEqual - { actual: S.localeCompare "a" "a" - , expected: EQ - } - assertEqual - { actual: S.localeCompare "a" "b" - , expected: LT - } - assertEqual - { actual: S.localeCompare "b" "a" - , expected: GT - } + -- log "localeCompare" + -- assertEqual + -- { actual: S.localeCompare "" "" + -- , expected: EQ + -- } + -- assertEqual + -- { actual: S.localeCompare "a" "a" + -- , expected: EQ + -- } + -- assertEqual + -- { actual: S.localeCompare "a" "b" + -- , expected: LT + -- } + -- assertEqual + -- { actual: S.localeCompare "b" "a" + -- , expected: GT + -- } log "replace" assertEqual From 1f81f43c80f74c7c185616a4b3ae1fc86f0aa43e Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Thu, 4 Mar 2021 11:04:41 +0000 Subject: [PATCH 10/29] Erl merge related changes --- src/Data/String/CodeUnits.erl | 28 +++++++++++++------ src/Data/String/NonEmpty/CodeUnits.purs | 5 +--- src/Data/String/Regex.erl | 10 +++---- test/Test/Data/String/NonEmpty.purs | 26 ++++++++--------- test/Test/Data/String/NonEmpty/CodeUnits.purs | 16 +++++------ test/Test/Data/String/Regex.purs | 18 ++++++------ test/Test/Main.purs | 2 +- 7 files changed, 57 insertions(+), 48 deletions(-) diff --git a/src/Data/String/CodeUnits.erl b/src/Data/String/CodeUnits.erl index 07c9acd..38dc055 100644 --- a/src/Data/String/CodeUnits.erl +++ b/src/Data/String/CodeUnits.erl @@ -1,5 +1,5 @@ -module(data_string_codeUnits@foreign). --export([fromCharArray/1, toCharArray/1, singleton/1, '_charAt'/4, '_toChar'/3,length/1, '_indexOf'/4, '_indexOf\''/5,'_lastIndexOf'/4,'_lastIndexOf\''/5,take/2, drop/2, countPrefix/2, '_slice'/3, splitAt/2]). +-export([fromCharArray/1, toCharArray/1, singleton/1, '_charAt'/4, '_toChar'/3,length/1, '_indexOf'/4, '_indexOfStartingAt'/5,'_lastIndexOf'/4,'_lastIndexOfStartingAt'/5,take/2, drop/2, countPrefix/2, '_slice'/3, splitAt/2]). fromCharArray(A) -> case unicode:characters_to_binary(array:to_list(A)) of {error, S, _} -> S; % In case of hitting bad character, return initial portion! @@ -27,8 +27,8 @@ length(S) -> byte_size(S). 0 -> Nothing; N -> Just(N-1) end. -'_indexOf\''(_Just,Nothing,_X,StartAt,S) when StartAt < 0; StartAt > byte_size(S) -> Nothing; -'_indexOf\''(Just,Nothing,X,StartAt,S) -> +'_indexOfStartingAt'(_Just,Nothing,_X,StartAt,S) when StartAt < 0; StartAt > byte_size(S) -> Nothing; +'_indexOfStartingAt'(Just,Nothing,X,StartAt,S) -> case '_indexOf'(Just,Nothing,X,drop(StartAt,S)) of {just,N} -> Just(N+StartAt); _ -> Nothing @@ -40,9 +40,11 @@ length(S) -> byte_size(S). 0 -> Nothing; N -> Just(N-1) end. -'_lastIndexOf\''(_Just,Nothing,_X,StartAt,S) when StartAt < 0; StartAt > byte_size(S) -> Nothing; -'_lastIndexOf\''(Just,Nothing,X,StartAt,S) -> - case '_lastIndexOf'(Just,Nothing,X,take(min(byte_size(S), StartAt+byte_size(X)),S)) of +'_lastIndexOfStartingAt'(Just,Nothing,X,StartAt,S) -> + L = byte_size(S), + S0 = min(L, max(0, StartAt)), + Part = binary:part(S, {0, S0+byte_size(X)}), + case '_lastIndexOf'(Just,Nothing,X,Part) of {just,N} -> Just(N); _ -> Nothing end. @@ -55,7 +57,7 @@ drop(N,S) -> M = max(0, min(N, byte_size(S))), binary:part(S, {M, byte_size(S)-M}). -countPrefixImpl(_, S, I) when I > byte_size(S) -> I; +countPrefixImpl(_, S, I) when I >= byte_size(S) -> I; countPrefixImpl(P, S, I) -> case P(binary:at(S, I)) of true -> countPrefixImpl(P, S, I+1); @@ -64,7 +66,17 @@ countPrefixImpl(P, S, I) -> countPrefix(P, S) -> countPrefixImpl(P, S, 0). -'_slice'(B, E, S) -> binary:part(S, B, E). +'_slice'(B, E, S) -> + L = byte_size(S), + BB = case B < 0 of + true -> L + B; + false -> B + end, + EE = case E < 0 of + true -> L + E; + false -> E + end, + binary:part(S, BB, (EE-BB)). splitAt(I0, S) -> I = min(max(0, I0), erlang:byte_size(S)), diff --git a/src/Data/String/NonEmpty/CodeUnits.purs b/src/Data/String/NonEmpty/CodeUnits.purs index af3de43..1faa090 100644 --- a/src/Data/String/NonEmpty/CodeUnits.purs +++ b/src/Data/String/NonEmpty/CodeUnits.purs @@ -91,10 +91,7 @@ snoc c s = toNonEmptyString (s <> CU.singleton c) -- | Creates a `NonEmptyString` from a `Foldable1` container carrying -- | characters. fromFoldable1 :: forall f. Foldable1 f => f Char -> NonEmptyString -fromFoldable1 = F1.fold1 <<< coe - where - coe ∷ f Char -> f NonEmptyString - coe = unsafeCoerce +fromFoldable1 = F1.foldMap1 (NonEmptyString <<< CU.singleton) -- | Converts the `NonEmptyString` into an array of characters. -- | diff --git a/src/Data/String/Regex.erl b/src/Data/String/Regex.erl index c20dac0..357be05 100644 --- a/src/Data/String/Regex.erl +++ b/src/Data/String/Regex.erl @@ -1,7 +1,7 @@ -module(data_string_regex@foreign). --export(['showRegex\''/1, 'regex\''/4, source/1, 'flags\''/1, test/2, '_match'/4, replace/3, 'replace\''/3, '_search'/4, split/2]). +-export([showRegexImpl/1, regexImpl/4, source/1, flagsImpl/1, test/2, '_match'/4, replace/3, '_replaceBy'/5, '_search'/4, split/2]). -'showRegex\''({_,{S,_}}) -> S. +showRegexImpl({_,{S,_}}) -> S. flags_to_options([], Acc) -> {opts, Acc}; flags_to_options([$g|Flags], Acc) -> flags_to_options(Flags, Acc); @@ -16,7 +16,7 @@ is_global(S) -> case string:chr(unicode:characters_to_list(S), $g) of _ -> true end. -'regex\''(Left,Right,S1,S2) -> +regexImpl(Left,Right,S1,S2) -> FlagsStr = unicode:characters_to_list(S2), case flags_to_options(FlagsStr, []) of {opts, Opts} -> @@ -29,7 +29,7 @@ end. source({_,{S,_}}) -> S. -'flags\''(R) -> error("no flags"). +flagsImpl(R) -> error("no flags"). % exports["flags'"] = function (r) { % return { @@ -55,7 +55,7 @@ replace({R,{_,F}},S1,S2) -> G = case is_global(F) of true -> [global]; false -> [] end, re:replace(S2,R,S1,G++[{return,binary}]). % TODO -'replace\''({R,_},F,S2) -> error("replace' not supported"). +'_replaceBy'(_Just,_Nothing,{_R,_},_F,_S2) -> error("_replaceBy not supported"). '_search'(Just,Nothing,{R,_},S) -> case re:run(S,R) of {match, [{I,_}]} -> Just(I); diff --git a/test/Test/Data/String/NonEmpty.purs b/test/Test/Data/String/NonEmpty.purs index a4103ec..151fb0f 100644 --- a/test/Test/Data/String/NonEmpty.purs +++ b/test/Test/Data/String/NonEmpty.purs @@ -58,19 +58,19 @@ testNonEmptyString = do assert $ NES.contains (Pattern "needle") (nes (Proxy :: Proxy "haystack with needle")) assert $ not NES.contains (Pattern "needle") (nes (Proxy :: Proxy "haystack")) - log "localeCompare" - assertEqual - { actual: NES.localeCompare (nes (Proxy :: Proxy "a")) (nes (Proxy :: Proxy "a")) - , expected: EQ - } - assertEqual - { actual: NES.localeCompare (nes (Proxy :: Proxy "a")) (nes (Proxy :: Proxy "b")) - , expected: LT - } - assertEqual - { actual: NES.localeCompare (nes (Proxy :: Proxy "b")) (nes (Proxy :: Proxy "a")) - , expected: GT - } + -- log "localeCompare" + -- assertEqual + -- { actual: NES.localeCompare (nes (Proxy :: Proxy "a")) (nes (Proxy :: Proxy "a")) + -- , expected: EQ + -- } + -- assertEqual + -- { actual: NES.localeCompare (nes (Proxy :: Proxy "a")) (nes (Proxy :: Proxy "b")) + -- , expected: LT + -- } + -- assertEqual + -- { actual: NES.localeCompare (nes (Proxy :: Proxy "b")) (nes (Proxy :: Proxy "a")) + -- , expected: GT + -- } log "replace" assertEqual diff --git a/test/Test/Data/String/NonEmpty/CodeUnits.purs b/test/Test/Data/String/NonEmpty/CodeUnits.purs index 9a33b0c..5f01cf2 100644 --- a/test/Test/Data/String/NonEmpty/CodeUnits.purs +++ b/test/Test/Data/String/NonEmpty/CodeUnits.purs @@ -119,14 +119,14 @@ testNonEmptyStringCodeUnits = do { actual: fromEnum <$> NESCU.charAt 2 (nes (Proxy :: Proxy "ab")) , expected: Nothing } - assertEqual - { actual: fromEnum <$> NESCU.charAt 2 (nes (Proxy :: Proxy "5 €")) - , expected: Just 0x20AC - } - assertEqual - { actual: fromEnum <$> NESCU.charAt 10 (nes (Proxy :: Proxy "5 €")) - , expected: Nothing - } + -- assertEqual + -- { actual: fromEnum <$> NESCU.charAt 2 (nes (Proxy :: Proxy "5 €")) + -- , expected: Just 0x20AC + -- } + -- assertEqual + -- { actual: fromEnum <$> NESCU.charAt 10 (nes (Proxy :: Proxy "5 €")) + -- , expected: Nothing + -- } log "toChar" assertEqual diff --git a/test/Test/Data/String/Regex.purs b/test/Test/Data/String/Regex.purs index 4893603..245057f 100644 --- a/test/Test/Data/String/Regex.purs +++ b/test/Test/Data/String/Regex.purs @@ -20,11 +20,11 @@ testStringRegex = do assert $ not (test (unsafeRegex "^b" noFlags) "abc") assert $ isLeft (regex "+" noFlags) - log "flags" - assert $ "quxbarfoobaz" == replace (unsafeRegex "foo" noFlags) "qux" "foobarfoobaz" - assert $ "quxbarquxbaz" == replace (unsafeRegex "foo" global) "qux" "foobarfoobaz" - assert $ "quxbarquxbaz" == replace (unsafeRegex "foo" (global <> ignoreCase)) "qux" "foobarFOObaz" - assert $ "quxbarfoobaz" == replace (unsafeRegex ".foo" dotAll) "qux" "\nfoobarfoobaz" + -- log "flags" + -- assert $ "quxbarfoobaz" == replace (unsafeRegex "foo" noFlags) "qux" "foobarfoobaz" + -- assert $ "quxbarquxbaz" == replace (unsafeRegex "foo" global) "qux" "foobarfoobaz" + -- assert $ "quxbarquxbaz" == replace (unsafeRegex "foo" (global <> ignoreCase)) "qux" "foobarFOObaz" + -- assert $ "quxbarfoobaz" == replace (unsafeRegex ".foo" dotAll) "qux" "\nfoobarfoobaz" log "match" assert $ match (unsafeRegex "^abc$" noFlags) "abc" == Just (nea [Just "abc"]) @@ -35,10 +35,10 @@ testStringRegex = do -- log "replace'" -- assert $ replace' (unsafeRegex "-" noFlags) (\s xs -> "!") "a-b-c" == "a!b-c" - assert $ replace' (unsafeRegex "(foo)(bar)?" noFlags) (\s xs -> show xs) "<>" == "<>" - assert $ replace' (unsafeRegex "(foo)(bar)?" noFlags) (\s xs -> show xs) "" == "<[(Just \"foo\"),Nothing]>" - assert $ replace' (unsafeRegex "(foo)(bar)?" noFlags) (\s xs -> show xs) "" == "<[(Just \"foo\"),(Just \"bar\")]>" - assert $ replace' (unsafeRegex "@(?\\w+)" noFlags) (\s xs -> show xs) "@purescript" == "[(Just \"purescript\")]" + -- assert $ replace' (unsafeRegex "(foo)(bar)?" noFlags) (\s xs -> show xs) "<>" == "<>" + -- assert $ replace' (unsafeRegex "(foo)(bar)?" noFlags) (\s xs -> show xs) "" == "<[(Just \"foo\"),Nothing]>" + -- assert $ replace' (unsafeRegex "(foo)(bar)?" noFlags) (\s xs -> show xs) "" == "<[(Just \"foo\"),(Just \"bar\")]>" + -- assert $ replace' (unsafeRegex "@(?\\w+)" noFlags) (\s xs -> show xs) "@purescript" == "[(Just \"purescript\")]" log "search" assert $ search (unsafeRegex "b" noFlags) "abc" == Just 1 diff --git a/test/Test/Main.purs b/test/Test/Main.purs index fb9f32e..b54f540 100644 --- a/test/Test/Main.purs +++ b/test/Test/Main.purs @@ -18,7 +18,7 @@ main = do log "\n--- Data.String ---\n" testString log "\n--- Data.String.CodePoints ---\n" - testStringCodePoints + -- testStringCodePoints log "\n--- Data.String.CodeUnits ---\n" testStringCodeUnits log "\n--- Data.String.Unsafe ---\n" From e50086b780ade1efa79e249a09e525bdaf2af203 Mon Sep 17 00:00:00 2001 From: robashton Date: Fri, 7 May 2021 15:54:11 +0100 Subject: [PATCH 11/29] Add code point to string array implementation --- src/Data/String/CodePoints.erl | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Data/String/CodePoints.erl b/src/Data/String/CodePoints.erl index 535b366..5570116 100644 --- a/src/Data/String/CodePoints.erl +++ b/src/Data/String/CodePoints.erl @@ -1,5 +1,11 @@ -module(data_string_codePoints@foreign). --export(['_unsafeCodePointAt0'/1, '_codePointAt'/6, '_countPrefix'/0, '_fromCodePointArray'/0, '_singleton'/1, '_take'/1, '_toCodePointArray'/1]). +-export(['_unsafeCodePointAt0'/1 + , '_codePointAt'/6 + , '_countPrefix'/0 + , '_fromCodePointArray'/2 + , '_singleton'/1 + , '_take'/1 + , '_toCodePointArray'/1]). '_unsafeCodePointAt0'(_Fallback) -> fun (Str) -> case unicode:characters_to_list(Str) of @@ -17,7 +23,10 @@ end. . '_countPrefix'() -> error("unimplemented"). -'_fromCodePointArray'() -> error("unimplemented"). +'_fromCodePointArray'(_Fallback, Array) -> + List = array:to_list(Array), + unicode:characters_to_binary(List, utf8). + '_singleton'(_Fallback) -> fun (CP) -> unicode:characters_to_binary([CP], utf8) end. @@ -25,7 +34,7 @@ end. fun (N) -> fun (S) -> unicode:characters_to_binary(lists:sublist(unicode:characters_to_list(S, utf8), N), utf8) - end + end end. '_toCodePointArray'(_Fallback) -> fun (_UnsafeCodePointAt0) -> fun (Str) -> From 5d7183103eb7d24cb44ccf7dcacb5b518bea98f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Thu, 15 Dec 2022 11:11:00 +0100 Subject: [PATCH 12/29] Update CI --- .github/workflows/ci.yml | 33 --------------------------- .github/workflows/on-each-commit.yaml | 13 +++++++++++ 2 files changed, 13 insertions(+), 33 deletions(-) delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/on-each-commit.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 43d2897..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: CI - -on: - push: - branches: [master] - pull_request: - branches: [master] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - uses: purescript-contrib/setup-purescript@main - - - uses: actions/setup-node@v1 - with: - node-version: "12" - - - name: Install dependencies - run: | - npm install -g bower - npm install - bower install --production - - - name: Build source - run: npm run-script build - - - name: Run tests - run: | - bower install - npm run-script test --if-present diff --git a/.github/workflows/on-each-commit.yaml b/.github/workflows/on-each-commit.yaml new file mode 100644 index 0000000..b933847 --- /dev/null +++ b/.github/workflows/on-each-commit.yaml @@ -0,0 +1,13 @@ +on: [push] + +jobs: + run_tests: + runs-on: ubuntu-latest + container: + image: fredthedino/purerl:0.0.16 + steps: + - uses: actions/checkout@v2 + - name: 'Compile' + run: spago build + - name: 'Test' + run: spago test From c0994103df0fb386f3396d75fd20fcec8d7486b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Thu, 15 Dec 2022 11:11:07 +0100 Subject: [PATCH 13/29] Port project to Spago --- packages.dhall | 105 +++++++++++++++++++++++++++++++++++++++++++++++++ spago.dhall | 38 ++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 packages.dhall create mode 100644 spago.dhall diff --git a/packages.dhall b/packages.dhall new file mode 100644 index 0000000..f2bb70c --- /dev/null +++ b/packages.dhall @@ -0,0 +1,105 @@ +{- +Welcome to your new Dhall package-set! + +Below are instructions for how to edit this file for most use +cases, so that you don't need to know Dhall to use it. + +## Use Cases + +Most will want to do one or both of these options: +1. Override/Patch a package's dependency +2. Add a package not already in the default package set + +This file will continue to work whether you use one or both options. +Instructions for each option are explained below. + +### Overriding/Patching a package + +Purpose: +- Change a package's dependency to a newer/older release than the + default package set's release +- Use your own modified version of some dependency that may + include new API, changed API, removed API by + using your custom git repo of the library rather than + the package set's repo + +Syntax: +where `entityName` is one of the following: +- dependencies +- repo +- version +------------------------------- +let upstream = -- +in upstream + with packageName.entityName = "new value" +------------------------------- + +Example: +------------------------------- +let upstream = -- +in upstream + with halogen.version = "master" + with halogen.repo = "https://example.com/path/to/git/repo.git" + + with halogen-vdom.version = "v4.0.0" + with halogen-vdom.dependencies = [ "extra-dependency" ] # halogen-vdom.dependencies +------------------------------- + +### Additions + +Purpose: +- Add packages that aren't already included in the default package set + +Syntax: +where `` is: +- a tag (i.e. "v4.0.0") +- a branch (i.e. "master") +- commit hash (i.e. "701f3e44aafb1a6459281714858fadf2c4c2a977") +------------------------------- +let upstream = -- +in upstream + with new-package-name = + { dependencies = + [ "dependency1" + , "dependency2" + ] + , repo = + "https://example.com/path/to/git/repo.git" + , version = + "" + } +------------------------------- + +Example: +------------------------------- +let upstream = -- +in upstream + with benchotron = + { dependencies = + [ "arrays" + , "exists" + , "profunctor" + , "strings" + , "quickcheck" + , "lcg" + , "transformers" + , "foldable-traversable" + , "exceptions" + , "node-fs" + , "node-buffer" + , "node-readline" + , "datetime" + , "now" + ] + , repo = + "https://github.com/hdgarrood/purescript-benchotron.git" + , version = + "v7.0.0" + } +------------------------------- +-} +let upstream = + https://github.com/purerl/package-sets/releases/download/erl-0.15.3-20220629/packages.dhall + sha256:48ee9f3558c00e234eae6b8f23b4b8b66eb9715c7f2154864e1e425042a0723b + +in upstream diff --git a/spago.dhall b/spago.dhall new file mode 100644 index 0000000..cf4d9e1 --- /dev/null +++ b/spago.dhall @@ -0,0 +1,38 @@ +{- +Welcome to a Spago project! +You can edit this file as you like. + +Need help? See the following resources: +- Spago documentation: https://github.com/purescript/spago +- Dhall language tour: https://docs.dhall-lang.org/tutorials/Language-Tour.html + +When creating a new Spago project, you can use +`spago init --no-comments` or `spago init -C` +to generate this file without the comments in this block. +-} +{ name = "strings" +, backend = "purerl" +, dependencies = + [ "arrays" + , "assert" + , "console" + , "control" + , "effect" + , "either" + , "enums" + , "foldable-traversable" + , "gen" + , "integers" + , "maybe" + , "newtype" + , "nonempty" + , "partial" + , "prelude" + , "tailrec" + , "tuples" + , "unfoldable" + , "unsafe-coerce" + ] +, packages = ./packages.dhall +, sources = [ "src/**/*.purs", "test/**/*.purs" ] +} From 77e6c68df30f6c4e8f3103b4c95bf9567e0fec4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Thu, 15 Dec 2022 11:11:29 +0100 Subject: [PATCH 14/29] Fix wierd compilation error --- src/Data/String/NonEmpty/Internal.purs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Data/String/NonEmpty/Internal.purs b/src/Data/String/NonEmpty/Internal.purs index 707b779..8722654 100644 --- a/src/Data/String/NonEmpty/Internal.purs +++ b/src/Data/String/NonEmpty/Internal.purs @@ -16,6 +16,7 @@ import Data.String as String import Data.String.Pattern (Pattern) import Data.Symbol (class IsSymbol, reflectSymbol) import Prim.TypeError as TE +import Type.Proxy (Proxy) import Unsafe.Coerce (unsafeCoerce) -- | A string that is known not to be empty. @@ -41,7 +42,7 @@ instance showNonEmptyString :: Show NonEmptyString where -- | something = nes (Proxy :: Proxy "something") -- | ``` class MakeNonEmpty (s :: Symbol) where - nes :: forall proxy. proxy s -> NonEmptyString + nes :: Proxy s -> NonEmptyString instance makeNonEmptyBad :: TE.Fail (TE.Text "Cannot create an NonEmptyString from an empty Symbol") => MakeNonEmpty "" where nes _ = NonEmptyString "" From 56faeab61171b1df61db28c5dd245d5b0c7b3821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Thu, 15 Dec 2022 11:11:55 +0100 Subject: [PATCH 15/29] Remove the crash in _countPrefix and use the one in PureScript --- src/Data/String/CodePoints.erl | 2 -- src/Data/String/CodePoints.purs | 9 +-------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/Data/String/CodePoints.erl b/src/Data/String/CodePoints.erl index 5570116..05b5938 100644 --- a/src/Data/String/CodePoints.erl +++ b/src/Data/String/CodePoints.erl @@ -1,7 +1,6 @@ -module(data_string_codePoints@foreign). -export(['_unsafeCodePointAt0'/1 , '_codePointAt'/6 - , '_countPrefix'/0 , '_fromCodePointArray'/2 , '_singleton'/1 , '_take'/1 @@ -22,7 +21,6 @@ end. end . -'_countPrefix'() -> error("unimplemented"). '_fromCodePointArray'(_Fallback, Array) -> List = array:to_list(Array), unicode:characters_to_binary(List, utf8). diff --git a/src/Data/String/CodePoints.purs b/src/Data/String/CodePoints.purs index 65e0b55..11a3559 100644 --- a/src/Data/String/CodePoints.purs +++ b/src/Data/String/CodePoints.purs @@ -225,14 +225,7 @@ length = Array.length <<< toCodePointArray -- | ``` -- | countPrefix :: (CodePoint -> Boolean) -> String -> Int -countPrefix = _countPrefix countFallback unsafeCodePointAt0 - -foreign import _countPrefix - :: ((CodePoint -> Boolean) -> String -> Int) - -> (String -> CodePoint) - -> (CodePoint -> Boolean) - -> String - -> Int +countPrefix = countFallback countFallback :: (CodePoint -> Boolean) -> String -> Int countFallback p s = countTail p s 0 From 1588058ab6c77c84fbce2a51bf1afe9e9b49048b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Thu, 15 Dec 2022 11:19:16 +0100 Subject: [PATCH 16/29] Downgrade the package set --- packages.dhall | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages.dhall b/packages.dhall index f2bb70c..48d4786 100644 --- a/packages.dhall +++ b/packages.dhall @@ -99,7 +99,7 @@ in upstream ------------------------------- -} let upstream = - https://github.com/purerl/package-sets/releases/download/erl-0.15.3-20220629/packages.dhall - sha256:48ee9f3558c00e234eae6b8f23b4b8b66eb9715c7f2154864e1e425042a0723b + https://github.com/purerl/package-sets/releases/download/erl-0.14.5-20220204-2/packages.dhall + sha256:bf284d597ad053b43591b964a52aa0f41ed12a576c3efde85ba999ad65072fc9 in upstream From 0ab0db4feb7e0080607889998a270702377b65a9 Mon Sep 17 00:00:00 2001 From: Jan-Felix Wittmann Date: Thu, 30 Mar 2023 11:31:12 +0200 Subject: [PATCH 17/29] fix Warning: variable 'R' is unused --- .gitignore | 1 + packages.dhall | 4 ++-- src/Data/String/Regex.erl | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index b846b63..7cd304e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /node_modules/ /output/ package-lock.json +/ebin/ diff --git a/packages.dhall b/packages.dhall index 48d4786..f2bb70c 100644 --- a/packages.dhall +++ b/packages.dhall @@ -99,7 +99,7 @@ in upstream ------------------------------- -} let upstream = - https://github.com/purerl/package-sets/releases/download/erl-0.14.5-20220204-2/packages.dhall - sha256:bf284d597ad053b43591b964a52aa0f41ed12a576c3efde85ba999ad65072fc9 + https://github.com/purerl/package-sets/releases/download/erl-0.15.3-20220629/packages.dhall + sha256:48ee9f3558c00e234eae6b8f23b4b8b66eb9715c7f2154864e1e425042a0723b in upstream diff --git a/src/Data/String/Regex.erl b/src/Data/String/Regex.erl index 357be05..d03ac6f 100644 --- a/src/Data/String/Regex.erl +++ b/src/Data/String/Regex.erl @@ -29,7 +29,7 @@ end. source({_,{S,_}}) -> S. -flagsImpl(R) -> error("no flags"). +flagsImpl(_R) -> error("no flags"). % exports["flags'"] = function (r) { % return { From 4a50f53ea661fc8ce528ce4b4aa529473e2a3d46 Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Thu, 10 Aug 2023 13:51:47 +0000 Subject: [PATCH 18/29] Fix indexOf related functions for CodeUnits for multiple byte sequences --- src/Data/String/CodeUnits.erl | 22 +++++++++-------- test/Test/Data/String/CodeUnits.purs | 14 +++++++++++ test/Test/Main.purs | 36 ++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 10 deletions(-) diff --git a/src/Data/String/CodeUnits.erl b/src/Data/String/CodeUnits.erl index 38dc055..cd51c52 100644 --- a/src/Data/String/CodeUnits.erl +++ b/src/Data/String/CodeUnits.erl @@ -23,23 +23,25 @@ length(S) -> byte_size(S). '_indexOf'(Just,_,<<>>,_) -> Just(0); '_indexOf'(Just,Nothing,X,S) -> - case string:str(unicode:characters_to_list(S), unicode:characters_to_list(X)) of - 0 -> Nothing; - N -> Just(N-1) + case binary:match(S, X) of + nomatch -> Nothing; + { Start, _Length } -> Just(Start) end. '_indexOfStartingAt'(_Just,Nothing,_X,StartAt,S) when StartAt < 0; StartAt > byte_size(S) -> Nothing; +'_indexOfStartingAt'(Just,_Nothing,<<>>,StartAt,_S) -> Just(StartAt); '_indexOfStartingAt'(Just,Nothing,X,StartAt,S) -> - case '_indexOf'(Just,Nothing,X,drop(StartAt,S)) of - {just,N} -> Just(N+StartAt); - _ -> Nothing + case binary:match(S, X, [{scope, {StartAt, byte_size(S)-StartAt}}]) of + nomatch -> Nothing; + { Start, _Length } -> Just(Start) end. '_lastIndexOf'(Just,_,<<>>,S) -> Just(byte_size(S)); '_lastIndexOf'(Just,Nothing,X,S) -> - case string:rstr(unicode:characters_to_list(S), unicode:characters_to_list(X)) of - 0 -> Nothing; - N -> Just(N-1) - end. + % there is no binary reverse match, and matches returns only nonoverlapping so would not always include the last match + case string:find(S, X, trailing) of + nomatch -> Nothing; + Substr -> Just(byte_size(S) - byte_size(Substr)) + end. '_lastIndexOfStartingAt'(Just,Nothing,X,StartAt,S) -> L = byte_size(S), S0 = min(L, max(0, StartAt)), diff --git a/test/Test/Data/String/CodeUnits.purs b/test/Test/Data/String/CodeUnits.purs index 9cf010b..f4cff17 100644 --- a/test/Test/Data/String/CodeUnits.purs +++ b/test/Test/Data/String/CodeUnits.purs @@ -203,6 +203,11 @@ testStringCodeUnits = do , expected: Nothing } + assertEqual + { actual: SCU.indexOf (Pattern " ") "360° sehen können" + , expected: Just 5 -- not 4 + } + log "indexOf'" assertEqual { actual: SCU.indexOf' (Pattern "") 0 "" @@ -244,6 +249,10 @@ testStringCodeUnits = do { actual: SCU.indexOf' (Pattern "cb") 0 "abcd" , expected: Nothing } + assertEqual + { actual: SCU.indexOf' (Pattern " ") 8 "360° sehen können" + , expected: Just 11 + } log "lastIndexOf" assertEqual @@ -262,6 +271,11 @@ testStringCodeUnits = do { actual: SCU.lastIndexOf (Pattern "cb") "abcd" , expected: Nothing } + assertEqual + { actual: SCU.lastIndexOf (Pattern " ") "360° sehen können" + , expected: Just 11 + } + log "lastIndexOf'" assertEqual diff --git a/test/Test/Main.purs b/test/Test/Main.purs index b54f540..4209dda 100644 --- a/test/Test/Main.purs +++ b/test/Test/Main.purs @@ -1,9 +1,14 @@ module Test.Main where +import Debug import Prelude +import Data.Maybe (Maybe(..)) +import Data.String (Pattern(..), indexOf) +import Data.String.CodeUnits as CU import Effect (Effect) import Effect.Console (log) +import Test.Assert (assertEqual, assertEqual') import Test.Data.String (testString) import Test.Data.String.CaseInsensitive (testCaseInsensitiveString) import Test.Data.String.CodePoints (testStringCodePoints) @@ -13,8 +18,39 @@ import Test.Data.String.NonEmpty.CodeUnits (testNonEmptyStringCodeUnits) import Test.Data.String.Regex (testStringRegex) import Test.Data.String.Unsafe (testStringUnsafe) +foo = "360° sehen können" + + +-- go = do +-- log $ "LOG: " <> foo +-- traceM foo +-- let _ = spy foo foo +-- bar' = spy "CU.indexOf" $ CU.indexOf (spy "pattern" (Pattern " ")) (spy "string" "360° sehen können") + +-- bar = spy "CU.take 5" $ CU.take 5 "360° sehen können" +-- bar'' = spy "CU.take 10" $ CU.take 10 "360° sehen können" + + +-- pure unit + +-- splitOnSpace :: String -> { current :: String, next :: String } +-- splitOnSpace text = +-- case CP.indexOf (Pattern " ") text of +-- Just i -> +-- let +-- { before: current, after: next } = Logger.spy "Splitresult" $ splitAt i text +-- in +-- { current: trim current, next: trim next } +-- Nothing -> { current: text, next: "" } + + + main :: Effect Unit main = do + assertEqual' "CU split utf8" { expected: Just 5, actual: CU.indexOf (Pattern " ") "360° sehen können" } + assertEqual' "CP normal string" { expected: Just 4, actual: indexOf (Pattern " ") "this is a string" } + assertEqual' "CP split utf8" { expected: Just 4, actual: indexOf (Pattern " ") "360° sehen können" } + log "\n--- Data.String ---\n" testString log "\n--- Data.String.CodePoints ---\n" From 035d5f1227b303c9b1982713f5e13ea63f0067d7 Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Thu, 10 Aug 2023 13:52:19 +0000 Subject: [PATCH 19/29] spago --- spago.dhall | 50 +++++++++++++++++++------------------------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/spago.dhall b/spago.dhall index cf4d9e1..3eec113 100644 --- a/spago.dhall +++ b/spago.dhall @@ -1,38 +1,26 @@ {- Welcome to a Spago project! You can edit this file as you like. - -Need help? See the following resources: -- Spago documentation: https://github.com/purescript/spago -- Dhall language tour: https://docs.dhall-lang.org/tutorials/Language-Tour.html - -When creating a new Spago project, you can use -`spago init --no-comments` or `spago init -C` -to generate this file without the comments in this block. -} { name = "strings" -, backend = "purerl" -, dependencies = - [ "arrays" - , "assert" - , "console" - , "control" - , "effect" - , "either" - , "enums" - , "foldable-traversable" - , "gen" - , "integers" - , "maybe" - , "newtype" - , "nonempty" - , "partial" - , "prelude" - , "tailrec" - , "tuples" - , "unfoldable" - , "unsafe-coerce" - ] +, dependencies = [ "arrays" + , "control" + , "either" + , "enums" + , "foldable-traversable" + , "gen" + , "integers" + , "maybe" + , "newtype" + , "nonempty" + , "partial" + , "prelude" + , "tailrec" + , "tuples" + , "unfoldable" + , "unsafe-coerce" + ] , packages = ./packages.dhall -, sources = [ "src/**/*.purs", "test/**/*.purs" ] +, sources = [ "src/**/*.purs" ] +, backend = "purerl" } From c50b00f6769b5132038a22c194b09e0f4b28efec Mon Sep 17 00:00:00 2001 From: Richard Carlsson Date: Thu, 30 Nov 2023 14:43:03 +0100 Subject: [PATCH 20/29] Use modern Erlang string functions in Data.String.Common Fixes broken use of regexp in trim and Latin-1 limitations in replace. --- src/Data/String/Common.erl | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Data/String/Common.erl b/src/Data/String/Common.erl index 70c2c4c..f8e8e63 100644 --- a/src/Data/String/Common.erl +++ b/src/Data/String/Common.erl @@ -2,11 +2,12 @@ -export(['_localeCompare'/5, replace/3, replaceAll/3, split/2, toLower/1, toUpper/1, trim/1, joinWith/2]). '_localeCompare'(_Lt,_Eq,_Gt,_S1,_S2) -> error("not implemented"). -replace(S1,S2,S3) -> iolist_to_binary(string:replace(S3, S1, S2)). -replaceAll(S1,S2,S3) -> iolist_to_binary(string:replace(S3, S1, S2, all)). + +replace(S1,S2,S3) -> unicode:characters_to_binary(string:replace(S3, S1, S2)). + +replaceAll(S1,S2,S3) -> unicode:characters_to_binary(string:replace(S3, S1, S2, all)). split(Sep,S) -> - Split = string:split(S, Sep, all), Res = case {Sep,S} of {<<>>,<<>>} -> []; %% string:split says [<<>>] but JS says [] {<<>>,_} -> @@ -14,18 +15,15 @@ split(Sep,S) -> lists:map(fun (C) -> unicode:characters_to_binary([C], utf8) end, unicode:characters_to_list(S, utf8)); %% {_,<<>>} behaves the same in JS vs string:split - _ -> Split + _ -> string:split(S, Sep, all) end, array:from_list(Res). -% TODO ugh -toLower(S) -> unicode:characters_to_binary(string:to_lower(unicode:characters_to_list(S))). +toLower(S) -> string:lowercase(S). -toUpper(S) -> unicode:characters_to_binary(string:to_upper(unicode:characters_to_list(S))). +toUpper(S) -> string:uppercase(S). -trim(S) -> re:replace(S, "^\\s*(.*?)\\s*$","\\1", [{return, binary}]). +trim(S) -> string:trim(S). joinWith(S, XS) -> - XS1 = lists:map(fun unicode:characters_to_list/1, array:to_list(XS)), - Res = string:join(XS1, unicode:characters_to_list(S)), - unicode:characters_to_binary(Res). + unicode:characters_to_binary(lists:join(S, array:to_list(XS))). From b1b3bf0da2810cee3a91a01093422fdd0ad31ac3 Mon Sep 17 00:00:00 2001 From: Richard Carlsson Date: Sat, 2 Dec 2023 11:18:07 +0100 Subject: [PATCH 21/29] Use modern Erlang string functions in Data.String.CodePoints Fixes complexity of take and codePointAt. --- src/Data/String/CodePoints.erl | 35 ++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/Data/String/CodePoints.erl b/src/Data/String/CodePoints.erl index 05b5938..276dfca 100644 --- a/src/Data/String/CodePoints.erl +++ b/src/Data/String/CodePoints.erl @@ -7,19 +7,21 @@ , '_toCodePointArray'/1]). '_unsafeCodePointAt0'(_Fallback) -> fun (Str) -> - case unicode:characters_to_list(Str) of - [CP|_] -> CP; - _ -> error("told you I was unsafe") + case string:next_codepoint(Str) of + [CP|_Rest] -> CP; + _ -> error(badarg) % malformed utf-8 end end. '_codePointAt'(_Fallback, Just, Nothing, _unsafeCodePointAt0, Index, Str) -> - Cps = unicode:characters_to_list(Str, utf8), - case length(Cps) of - Length when Index < 0, Index >= Length -> Nothing; - _ -> Just(lists:nth(Index+1, Cps)) - end -. + if is_integer(Index), Index >= 0, Index < byte_size(Str) -> + <<_:Index/binary,S/binary>> = Str, + case string:next_codepoint(S) of + [CP | _Rest] -> Just(CP); + _ -> Nothing % malformed utf-8 + end; + true -> Nothing + end. '_fromCodePointArray'(_Fallback, Array) -> List = array:to_list(Array), @@ -28,12 +30,21 @@ end. '_singleton'(_Fallback) -> fun (CP) -> unicode:characters_to_binary([CP], utf8) end. + '_take'(_Fallback) -> fun (N) -> - fun (S) -> - unicode:characters_to_binary(lists:sublist(unicode:characters_to_list(S, utf8), N), utf8) - end + fun (S) -> take(N, S, <<>>) end end. + +take(N, _S, Cs) when N =< 0 -> Cs; +take(_N, <<>>, _Cs) -> <<>>; % trying to take too many yields empty string +take(N, S, Cs) -> + %% note that right-appending to a binary in a loop is efficient + case string:next_codepoint(S) of + [CP | Rest] -> take(N-1, Rest, <>); + _ -> error(badarg) % malformed utf-8 + end. + '_toCodePointArray'(_Fallback) -> fun (_UnsafeCodePointAt0) -> fun (Str) -> array:from_list(unicode:characters_to_list(Str, utf8)) From 3003fa3cb5bd92ebf4aac38f88599ba7164a7cec Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Tue, 24 Dec 2024 10:46:07 +0000 Subject: [PATCH 22/29] Fix string trim, regex stuff. Use some functions introduced in OTP20 --- src/Data/String/Common.erl | 7 +++---- src/Data/String/Regex.erl | 3 ++- test/Test/Data/String.purs | 6 ++++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Data/String/Common.erl b/src/Data/String/Common.erl index 70c2c4c..654a36b 100644 --- a/src/Data/String/Common.erl +++ b/src/Data/String/Common.erl @@ -18,12 +18,11 @@ split(Sep,S) -> end, array:from_list(Res). -% TODO ugh -toLower(S) -> unicode:characters_to_binary(string:to_lower(unicode:characters_to_list(S))). +toLower(S) -> string:lowercase(S). -toUpper(S) -> unicode:characters_to_binary(string:to_upper(unicode:characters_to_list(S))). +toUpper(S) -> string:uppercase(S). -trim(S) -> re:replace(S, "^\\s*(.*?)\\s*$","\\1", [{return, binary}]). +trim(S) -> re:replace(S, "^\\s*(.*?)\\s*$","\\1", [{return, binary}, dotall]). joinWith(S, XS) -> XS1 = lists:map(fun unicode:characters_to_list/1, array:to_list(XS)), diff --git a/src/Data/String/Regex.erl b/src/Data/String/Regex.erl index d03ac6f..3bda113 100644 --- a/src/Data/String/Regex.erl +++ b/src/Data/String/Regex.erl @@ -7,7 +7,8 @@ flags_to_options([], Acc) -> {opts, Acc}; flags_to_options([$g|Flags], Acc) -> flags_to_options(Flags, Acc); flags_to_options([$i|Flags], Acc) -> flags_to_options(Flags, [caseless|Acc]); flags_to_options([$m|Flags], Acc) -> flags_to_options(Flags, [multiline|Acc]); -flags_to_options([$y|Flags], Acc) -> flags_to_options(Flags, Acc); +flags_to_options([$s|Flags], Acc) -> flags_to_options(Flags, [dotall|Acc]); +flags_to_options([$y|Flags], Acc) -> flags_to_options(Flags, [anchored|Acc]); %% this is basically sticky given there is no way to advance the index flags_to_options([$u|Flags], Acc) -> flags_to_options(Flags, [ucp|[unicode|Acc]]); flags_to_options(_,_) -> err. diff --git a/test/Test/Data/String.purs b/test/Test/Data/String.purs index 4f69455..ae9344d 100644 --- a/test/Test/Data/String.purs +++ b/test/Test/Data/String.purs @@ -118,6 +118,12 @@ testString = do , expected: "abc" } + log "trim multiline" + assertEqual + { actual: S.trim " abc\n def \n" + , expected: "abc\n def" + } + log "joinWith" assertEqual { actual: S.joinWith "" [] From df3cca51f16702c512891e71f902acab0fd546bc Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Tue, 24 Dec 2024 10:46:41 +0000 Subject: [PATCH 23/29] new spago --- package.json | 18 - shell.nix | 46 ++ spago.dhall | 26 - spago.lock | 1560 ++++++++++++++++++++++++++++++++++++++++++++++++++ spago.yaml | 32 ++ 5 files changed, 1638 insertions(+), 44 deletions(-) delete mode 100644 package.json create mode 100644 shell.nix delete mode 100644 spago.dhall create mode 100644 spago.lock create mode 100644 spago.yaml diff --git a/package.json b/package.json deleted file mode 100644 index c116cae..0000000 --- a/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "private": true, - "scripts": { - "clean": "rimraf output && rimraf .pulp-cache", - "build": "eslint src && pulp build -- --censor-lib --strict", - "test": "pulp test && npm run test:run:without_codePointAt", - "test:run:without_codePointAt": "node -e \"delete String.prototype.codePointAt; require('./output/Test.Main/index.js').main();\"", - "bench:build": "purs compile 'bench/**/*.purs' 'src/**/*.purs' 'bower_components/*/src/**/*.purs'", - "bench:run": "node --expose-gc -e 'require(\"./output/Bench.Main/index.js\").main()'", - "bench": "npm run bench:build && npm run bench:run" - }, - "devDependencies": { - "eslint": "^7.15.0", - "pulp": "^15.0.0", - "purescript-psa": "^0.8.0", - "rimraf": "^3.0.2" - } -} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..8702b13 --- /dev/null +++ b/shell.nix @@ -0,0 +1,46 @@ +let + purescript-overlay = + builtins.fetchGit { + name = "purescript-overlay"; + url = "https://github.com/thomashoneyman/purescript-overlay.git"; + rev = "526c92c34a1a0213dc5c4761756375e13d85f8d4"; + }; + purerlReleases = + builtins.fetchGit { + url = "https://github.com/purerl/nixpkgs-purerl.git"; + ref = "master"; + rev = "69ea3146f3c4f715c5dbc6e0f8ba7d0ee57bb3bd"; + }; + erlangReleases = + builtins.fetchGit { + name = "nixpkgs-nixerl"; + url = "https://github.com/id3as/nixpkgs-nixerl.git"; + rev = "2822128d0fe5c8aac42f0b80045e80e6ac22bfcc"; + }; + + pkgs = import { + overlays = [ + (import purescript-overlay).overlays.default + (import purerlReleases) + (import erlangReleases) + + ]; + }; + erlang = pkgs.nixerl.erlang-26-1; + +in + +pkgs.mkShell { + # nativeBuildInputs is usually what you want -- tools you need to run + nativeBuildInputs = with pkgs.buildPackages; + [ + nodejs + spago-unstable + purs-bin.purs-0_15_14 + purs-tidy + purerl.purerl-0-0-22 + erlang.erlang + ]; + +} + diff --git a/spago.dhall b/spago.dhall deleted file mode 100644 index 3eec113..0000000 --- a/spago.dhall +++ /dev/null @@ -1,26 +0,0 @@ -{- -Welcome to a Spago project! -You can edit this file as you like. --} -{ name = "strings" -, dependencies = [ "arrays" - , "control" - , "either" - , "enums" - , "foldable-traversable" - , "gen" - , "integers" - , "maybe" - , "newtype" - , "nonempty" - , "partial" - , "prelude" - , "tailrec" - , "tuples" - , "unfoldable" - , "unsafe-coerce" - ] -, packages = ./packages.dhall -, sources = [ "src/**/*.purs" ] -, backend = "purerl" -} diff --git a/spago.lock b/spago.lock new file mode 100644 index 0000000..1531722 --- /dev/null +++ b/spago.lock @@ -0,0 +1,1560 @@ +workspace: + packages: + strings: + path: ./ + dependencies: + - arrays + - control + - either + - enums + - foldable-traversable + - gen + - integers + - maybe + - newtype + - nonempty + - partial + - prelude + - tailrec + - tuples + - unfoldable + - unsafe-coerce + test_dependencies: + - assert + - debug + build_plan: + - arrays + - assert + - bifunctors + - console + - const + - contravariant + - control + - debug + - distributive + - effect + - either + - enums + - exists + - foldable-traversable + - functions + - functors + - gen + - identity + - integers + - invariant + - math + - maybe + - newtype + - nonempty + - numbers + - orders + - partial + - prelude + - profunctor + - refs + - safe-coerce + - tailrec + - tuples + - type-equality + - unfoldable + - unsafe-coerce + package_set: + address: + hash: sha256-kLmZv2u5dWVUUaQEwK0b3T1Ghce5a/hG0zlizaYfcXs= + url: https://raw.githubusercontent.com/purerl/package-sets/erl-0.15.3-20220629/packages.json + compiler: ">=0.15.0 <0.16.0" + content: + arrays: + repo: https://github.com/purerl/purescript-arrays.git + version: v6.0.0-erl1 + dependencies: + - bifunctors + - control + - foldable-traversable + - maybe + - nonempty + - partial + - prelude + - tailrec + - tuples + - unfoldable + - unsafe-coerce + assert: + repo: https://github.com/purerl/purescript-assert.git + version: v5.0.0-erl1 + dependencies: + - console + - effect + - prelude + bifunctors: + repo: https://github.com/purescript/purescript-bifunctors.git + version: v5.0.0 + dependencies: + - const + - either + - newtype + - prelude + - tuples + catenable-lists: + repo: https://github.com/purescript/purescript-catenable-lists.git + version: v6.0.1 + dependencies: + - control + - foldable-traversable + - lists + - maybe + - prelude + - tuples + - unfoldable + console: + repo: https://github.com/purerl/purescript-console.git + version: v5.0.0-erl1 + dependencies: + - effect + - prelude + const: + repo: https://github.com/purescript/purescript-const.git + version: v5.0.0 + dependencies: + - invariant + - newtype + - prelude + contravariant: + repo: https://github.com/purescript/purescript-contravariant.git + version: v5.0.0 + dependencies: + - const + - either + - newtype + - prelude + - tuples + control: + repo: https://github.com/purerl/purescript-control.git + version: v5.0.0-erl1 + dependencies: + - newtype + - prelude + convertable-options: + repo: https://github.com/natefaubion/purescript-convertable-options + version: v1.0.0 + dependencies: + - effect + - maybe + - record + datetime: + repo: https://github.com/purerl/purescript-datetime.git + version: v5.0.2-erl1 + dependencies: + - bifunctors + - control + - either + - enums + - foldable-traversable + - functions + - gen + - integers + - lists + - math + - maybe + - newtype + - ordered-collections + - partial + - prelude + - tuples + datetime-parsing: + repo: https://github.com/flounders/purescript-datetime-parsing + version: 10c0a9aecc60a2a5e8cff35bebe45be4dacaa7f8 + dependencies: + - arrays + - datetime + - either + - enums + - foldable-traversable + - integers + - lists + - maybe + - numbers + - parsing + - prelude + - psci-support + - strings + debug: + repo: https://github.com/purerl/purescript-debug.git + version: v5.0.0-erl1 + dependencies: + - prelude + distributive: + repo: https://github.com/purescript/purescript-distributive.git + version: v5.0.0 + dependencies: + - identity + - newtype + - prelude + - tuples + - type-equality + effect: + repo: https://github.com/purerl/purescript-effect.git + version: v3.0.0-erl1 + dependencies: + - prelude + either: + repo: https://github.com/purescript/purescript-either.git + version: v5.0.0 + dependencies: + - control + - invariant + - maybe + - prelude + enums: + repo: https://github.com/purerl/purescript-enums.git + version: v5.0.0-erl1 + dependencies: + - control + - either + - gen + - maybe + - newtype + - nonempty + - partial + - prelude + - tuples + - unfoldable + erl-atom: + repo: https://github.com/purerl/purescript-erl-atom.git + version: v1.2.0 + dependencies: + - prelude + - unsafe-coerce + erl-binary: + repo: https://github.com/purerl/purescript-erl-binary.git + version: v0.6.0 + dependencies: + - prelude + - maybe + - erl-lists + erl-cowboy: + repo: https://github.com/purerl/purescript-erl-cowboy + version: v0.11.0 + dependencies: + - effect + - either + - erl-atom + - erl-binary + - erl-kernel + - erl-lists + - erl-maps + - erl-modules + - erl-ranch + - erl-ssl + - erl-tuples + - foreign + - functions + - maybe + - prelude + - record + - transformers + - tuples + - unsafe-coerce + erl-file: + repo: https://github.com/purerl/purescript-erl-file.git + version: v0.0.3 + dependencies: + - erl-atom + - erl-binary + - prelude + erl-gun: + repo: https://github.com/id3as/purescript-erl-gun.git + version: v0.0.2 + dependencies: + - convertable-options + - datetime + - effect + - either + - erl-atom + - erl-binary + - erl-kernel + - erl-lists + - erl-maps + - erl-process + - erl-ssl + - erl-tuples + - erl-untagged-union + - foreign + - functions + - maybe + - prelude + - record + - simple-json + - typelevel-prelude + erl-jsone: + repo: https://github.com/purerl/purescript-erl-jsone + version: v0.4.0 + dependencies: + - arrays + - integers + - assert + - either + - erl-lists + - erl-tuples + erl-kernel: + repo: https://github.com/id3as/purescript-erl-kernel.git + version: v0.0.3 + dependencies: + - convertable-options + - datetime + - effect + - either + - erl-atom + - erl-binary + - erl-lists + - erl-maps + - erl-process + - erl-tuples + - erl-untagged-union + - foldable-traversable + - foreign + - functions + - integers + - maybe + - newtype + - partial + - prelude + - record + - typelevel-prelude + - unsafe-coerce + erl-lager: + repo: https://github.com/purerl/purescript-erl-lager.git + version: v0.0.1 + dependencies: + - erl-lists + erl-lists: + repo: https://github.com/purerl/purescript-erl-lists.git + version: v4.0.1 + dependencies: + - prelude + - foldable-traversable + - unfoldable + - filterable + - tuples + erl-logger: + repo: https://github.com/id3as/purescript-erl-logger.git + version: v0.0.3 + dependencies: + - prelude + - erl-atom + - erl-lists + - record + erl-maps: + repo: https://github.com/purerl/purescript-erl-maps.git + version: v0.5.0 + dependencies: + - erl-lists + - functions + - prelude + - tuples + - unfoldable + erl-modules: + repo: https://github.com/purerl/purescript-erl-modules.git + version: v0.1.6 + dependencies: + - erl-atom + - prelude + - strings + erl-nativerefs: + repo: https://github.com/id3as/purescript-erl-nativerefs.git + version: v0.1.0 + dependencies: + - prelude + - effect + - erl-tuples + erl-opentelemetry: + repo: https://github.com/id3as/purescript-erl-opentelemetry.git + version: v0.0.1 + dependencies: + - effect + - erl-atom + - erl-lists + - erl-maps + - erl-tuples + - erl-untagged-union + - maybe + - prelude + - tuples + - unsafe-reference + erl-otp-types: + repo: https://github.com/id3as/purescript-erl-otp-types.git + version: v0.0.2 + dependencies: + - erl-atom + - erl-binary + - erl-kernel + - foreign + - prelude + - unsafe-reference + erl-pinto: + repo: https://github.com/id3as/purescript-erl-pinto.git + version: v0.2.0 + dependencies: + - erl-process + - erl-lists + - erl-atom + - erl-kernel + - datetime + - erl-tuples + - erl-modules + - foreign + erl-process: + repo: https://github.com/purerl/purescript-erl-process.git + version: v3.3.0 + dependencies: + - datetime + - effect + - either + - foreign + - integers + - prelude + erl-queue: + repo: https://github.com/id3as/purescript-erl-queue.git + version: v0.0.2 + dependencies: + - control + - either + - erl-lists + - filterable + - foldable-traversable + - lists + - maybe + - newtype + - nonempty + - prelude + - tuples + - unfoldable + erl-ranch: + repo: https://github.com/id3as/purescript-erl-ranch.git + version: v0.0.2 + dependencies: + - convertable-options + - effect + - either + - erl-atom + - erl-kernel + - erl-lists + - erl-maps + - erl-otp-types + - erl-process + - erl-ssl + - erl-tuples + - exceptions + - foreign + - maybe + - prelude + - record + - typelevel-prelude + - unsafe-coerce + erl-simplebus: + repo: https://github.com/id3as/purescript-erl-simplebus.git + version: v0.0.3 + dependencies: + - effect + - erl-process + - maybe + - newtype + - prelude + erl-ssl: + repo: https://github.com/id3as/purescript-erl-ssl.git + version: v0.0.2 + dependencies: + - convertable-options + - datetime + - effect + - either + - maybe + - erl-atom + - erl-binary + - erl-lists + - erl-kernel + - erl-tuples + - erl-logger + - erl-otp-types + - foreign + - maybe + - partial + - prelude + - record + - unsafe-reference + erl-stetson: + repo: https://github.com/id3as/purescript-erl-stetson.git + version: v0.13.0 + dependencies: + - erl-atom + - erl-binary + - erl-lists + - erl-maps + - erl-tuples + - erl-modules + - erl-cowboy + - foreign + - maybe + - prelude + - transformers + - routing-duplex + erl-test-eunit: + repo: https://github.com/id3as/purescript-erl-test-eunit.git + version: v0.0.4 + dependencies: + - assert + - console + - debug + - erl-lists + - erl-tuples + - erl-atom + - foreign + - free + - prelude + - psci-support + erl-test-eunit-discovery: + repo: https://github.com/id3as/purescript-erl-test-eunit-discovery.git + version: d0b6d9f5bcab13f79c3941c64e52ee86f7cd4e2b + dependencies: + - effect + - erl-lists + - erl-modules + - erl-test-eunit + - filterable + - foldable-traversable + - maybe + - free + - prelude + erl-tuples: + repo: https://github.com/purerl/purescript-erl-tuples.git + version: v3.3.1 + dependencies: + - unfoldable + - tuples + erl-untagged-union: + repo: https://github.com/id3as/purescript-erl-untagged-union.git + version: v0.0.2 + dependencies: + - erl-atom + - erl-binary + - erl-lists + - erl-tuples + - foreign + - typelevel-prelude + - maybe + - partial + - prelude + - unsafe-coerce + - erl-process + exceptions: + repo: https://github.com/purerl/purescript-exceptions.git + version: v5.0.0-erl1 + dependencies: + - maybe + - either + - effect + exists: + repo: https://github.com/purescript/purescript-exists.git + version: v5.1.0 + dependencies: + - unsafe-coerce + expect-inferred: + repo: https://github.com/justinwoo/purescript-expect-inferred + version: v2.0.0 + dependencies: + - prelude + - typelevel-prelude + filterable: + repo: https://github.com/purescript/purescript-filterable.git + version: v3.0.1 + dependencies: + - arrays + - either + - foldable-traversable + - identity + - lists + - ordered-collections + foldable-traversable: + repo: https://github.com/purerl/purescript-foldable-traversable.git + version: v5.0.1-erl1 + dependencies: + - bifunctors + - const + - control + - either + - functors + - identity + - maybe + - newtype + - orders + - prelude + - tuples + foreign: + repo: https://github.com/purerl/purescript-foreign.git + version: v6.0.1-erl1 + dependencies: + - either + - functions + - identity + - integers + - lists + - maybe + - prelude + - strings + - transformers + formatters: + repo: https://github.com/id3as/purescript-formatters + version: v5.0.1-erl1 + dependencies: + - arrays + - bifunctors + - control + - datetime + - either + - enums + - foldable-traversable + - integers + - lists + - math + - maybe + - newtype + - numbers + - ordered-collections + - parsing + - partial + - prelude + - psci-support + - strings + - transformers + - tuples + free: + repo: https://github.com/purescript/purescript-free.git + version: v6.0.1 + dependencies: + - catenable-lists + - control + - distributive + - either + - exists + - foldable-traversable + - invariant + - lazy + - maybe + - prelude + - tailrec + - transformers + - tuples + - unsafe-coerce + functions: + repo: https://github.com/purerl/purescript-functions.git + version: v5.0.0-erl1 + dependencies: + - prelude + functors: + repo: https://github.com/purescript/purescript-functors.git + version: v4.1.1 + dependencies: + - bifunctors + - const + - contravariant + - control + - distributive + - either + - invariant + - maybe + - newtype + - prelude + - profunctor + - tuples + - unsafe-coerce + gen: + repo: https://github.com/purescript/purescript-gen.git + version: v3.0.0 + dependencies: + - either + - foldable-traversable + - identity + - maybe + - newtype + - nonempty + - prelude + - tailrec + - tuples + - unfoldable + graphs: + repo: https://github.com/purescript/purescript-graphs.git + version: v5.0.0 + dependencies: + - catenable-lists + - ordered-collections + heterogeneous: + repo: https://github.com/natefaubion/purescript-heterogeneous.git + version: v0.5.1 + dependencies: + - prelude + - record + - tuples + - functors + - variant + - either + identity: + repo: https://github.com/purescript/purescript-identity.git + version: v5.0.0 + dependencies: + - control + - invariant + - newtype + - prelude + integers: + repo: https://github.com/purerl/purescript-integers.git + version: v5.0.0-erl1 + dependencies: + - math + - maybe + - numbers + - prelude + invariant: + repo: https://github.com/purescript/purescript-invariant.git + version: v5.0.0 + dependencies: + - control + - prelude + js-uri: + repo: https://github.com/purerl/purescript-js-uri.git + version: v2.0.0-erl1 + dependencies: + - functions + - maybe + lazy: + repo: https://github.com/purerl/purescript-lazy.git + version: v5.0.0-erl1 + dependencies: + - control + - foldable-traversable + - invariant + - prelude + lcg: + repo: https://github.com/purescript/purescript-lcg.git + version: v3.0.0 + dependencies: + - effect + - integers + - math + - maybe + - partial + - prelude + - random + lists: + repo: https://github.com/purescript/purescript-lists.git + version: v6.0.1 + dependencies: + - bifunctors + - control + - foldable-traversable + - lazy + - maybe + - newtype + - nonempty + - partial + - prelude + - tailrec + - tuples + - unfoldable + math: + repo: https://github.com/purerl/purescript-math.git + version: v3.0.0-erl1 + dependencies: [] + maybe: + repo: https://github.com/purescript/purescript-maybe.git + version: v5.0.0 + dependencies: + - control + - invariant + - newtype + - prelude + media-types: + repo: https://github.com/purescript-contrib/purescript-media-types.git + version: v5.0.0 + dependencies: + - prelude + - newtype + metadata: + repo: https://github.com/spacchetti/purescript-metadata.git + version: v0.15.0 + dependencies: [] + newtype: + repo: https://github.com/purescript/purescript-newtype.git + version: v4.0.0 + dependencies: + - prelude + - safe-coerce + nonempty: + repo: https://github.com/purescript/purescript-nonempty.git + version: v6.0.0 + dependencies: + - control + - foldable-traversable + - maybe + - prelude + - tuples + - unfoldable + nullable: + repo: https://github.com/purerl/purescript-nullable.git + version: v5.0.0-erl1 + dependencies: + - maybe + - functions + numbers: + repo: https://github.com/purerl/purescript-numbers.git + version: v8.0.0-erl1 + dependencies: + - functions + - math + - maybe + ordered-collections: + repo: https://github.com/purerl/purescript-ordered-collections.git + version: v2.0.2-erl1 + dependencies: + - arrays + - foldable-traversable + - gen + - lists + - maybe + - partial + - prelude + - tailrec + - tuples + - unfoldable + - unsafe-coerce + orders: + repo: https://github.com/purescript/purescript-orders.git + version: v5.0.0 + dependencies: + - newtype + - prelude + parallel: + repo: https://github.com/purescript/purescript-parallel.git + version: v5.0.0 + dependencies: + - control + - effect + - either + - foldable-traversable + - functors + - maybe + - newtype + - prelude + - profunctor + - refs + - transformers + parsing: + repo: https://github.com/id3as/purescript-parsing + version: v6.0.2-erl1 + dependencies: + - arrays + - assert + - console + - control + - effect + - either + - foldable-traversable + - identity + - integers + - lists + - math + - maybe + - newtype + - prelude + - psci-support + - strings + - tailrec + - transformers + - tuples + - unicode + partial: + repo: https://github.com/purerl/purescript-partial.git + version: v3.0.0-erl2 + dependencies: [] + pathy: + repo: https://github.com/id3as/purescript-pathy + version: v8.1.0-erl1 + dependencies: + - arrays + - either + - exceptions + - foldable-traversable + - gen + - identity + - lists + - maybe + - newtype + - nonempty + - partial + - prelude + - psci-support + - strings + - tailrec + - tuples + - typelevel-prelude + - unsafe-coerce + prelude: + repo: https://github.com/purerl/purescript-prelude.git + version: v5.0.1-erl1 + dependencies: [] + profunctor: + repo: https://github.com/purescript/purescript-profunctor.git + version: v5.0.0 + dependencies: + - control + - distributive + - either + - exists + - invariant + - newtype + - prelude + - tuples + profunctor-lenses: + repo: https://github.com/purerl/purescript-profunctor-lenses.git + version: v8.0.0-erl1 + dependencies: + - arrays + - bifunctors + - const + - control + - distributive + - either + - foldable-traversable + - functors + - identity + - lists + - maybe + - newtype + - ordered-collections + - partial + - prelude + - profunctor + - record + - transformers + - tuples + - erl-maps + psci-support: + repo: https://github.com/purescript/purescript-psci-support.git + version: v5.0.0 + dependencies: + - console + - effect + - prelude + quickcheck: + repo: https://github.com/purerl/purescript-quickcheck.git + version: v7.1.0-erl1 + dependencies: + - arrays + - console + - control + - effect + - either + - enums + - exceptions + - foldable-traversable + - gen + - identity + - integers + - lazy + - lcg + - lists + - math + - maybe + - newtype + - nonempty + - partial + - prelude + - record + - strings + - tailrec + - transformers + - tuples + - unfoldable + quickcheck-laws: + repo: https://github.com/purescript-contrib/purescript-quickcheck-laws + version: v6.0.1 + dependencies: + - arrays + - console + - control + - effect + - either + - enums + - foldable-traversable + - identity + - lists + - maybe + - newtype + - prelude + - quickcheck + - tuples + random: + repo: https://github.com/purerl/purescript-random.git + version: v5.0.0-erl1 + dependencies: + - effect + - integers + - math + rationals: + repo: https://github.com/anttih/purescript-rationals.git + version: c883c972513380ae161d816ed42108acfe8cc8f6 + dependencies: + - prelude + - integers + record: + repo: https://github.com/purerl/purescript-record.git + version: v3.0.0-erl1 + dependencies: + - functions + - typelevel-prelude + - unsafe-coerce + record-prefix: + repo: https://github.com/dariooddenino/purescript-record-prefix.git + version: v1.0.0 + dependencies: + - prelude + - heterogeneous + - console + - typelevel-prelude + refs: + repo: https://github.com/purerl/purescript-refs.git + version: v5.0.0-erl2 + dependencies: + - effect + - prelude + routing-duplex: + repo: https://github.com/natefaubion/purescript-routing-duplex.git + version: v0.5.0 + dependencies: + - arrays + - control + - either + - js-uri + - lazy + - numbers + - prelude + - profunctor + - record + - strings + - typelevel-prelude + safe-coerce: + repo: https://github.com/purescript/purescript-safe-coerce.git + version: v1.0.0 + dependencies: + - unsafe-coerce + semirings: + repo: https://github.com/purescript/purescript-semirings.git + version: v6.0.0 + dependencies: + - foldable-traversable + - lists + - newtype + - prelude + sequences: + repo: https://github.com/hdgarrood/purescript-sequences.git + version: v3.0.2 + dependencies: + - prelude + - unsafe-coerce + - partial + - unfoldable + - lazy + - arrays + - profunctor + - maybe + - tuples + - newtype + simple-json: + repo: https://github.com/purerl/purescript-simple-json.git + version: baad5dd0d613df6fb2f054fd241d46e11a92e181 + dependencies: + - exceptions + - foreign + - nullable + - prelude + - record + - typelevel-prelude + - variant + - erl-lists + - erl-maps + - erl-kernel + simple-json-generics: + repo: https://github.com/justinwoo/purescript-simple-json-generics + version: v0.1.0 + dependencies: + - prelude + - simple-json + strings: + repo: https://github.com/purerl/purescript-strings.git + version: v5.0.0-erl2 + dependencies: + - arrays + - control + - either + - enums + - foldable-traversable + - gen + - integers + - maybe + - newtype + - nonempty + - partial + - prelude + - tailrec + - tuples + - unfoldable + - unsafe-coerce + tailrec: + repo: https://github.com/purerl/purescript-tailrec.git + version: v5.0.1-erl1 + dependencies: + - bifunctors + - effect + - either + - identity + - maybe + - partial + - prelude + - refs + these: + repo: https://github.com/purescript-contrib/purescript-these.git + version: v5.0.0 + dependencies: + - arrays + - gen + - lists + - quickcheck + - quickcheck-laws + - tuples + transformers: + repo: https://github.com/purescript/purescript-transformers.git + version: v5.2.0 + dependencies: + - control + - distributive + - effect + - either + - exceptions + - foldable-traversable + - identity + - lazy + - maybe + - newtype + - prelude + - tailrec + - tuples + - unfoldable + tuples: + repo: https://github.com/purescript/purescript-tuples.git + version: v6.0.1 + dependencies: + - control + - invariant + - prelude + type-equality: + repo: https://github.com/purescript/purescript-type-equality.git + version: v4.0.0 + dependencies: [] + typelevel-prelude: + repo: https://github.com/purescript/purescript-typelevel-prelude.git + version: v6.0.0 + dependencies: + - prelude + - type-equality + undefinable: + repo: https://github.com/purerl/purescript-undefinable.git + version: v4.0.0-erl1 + dependencies: + - maybe + - functions + unfoldable: + repo: https://github.com/purerl/purescript-unfoldable.git + version: v5.0.0-erl1 + dependencies: + - foldable-traversable + - maybe + - partial + - prelude + - tuples + unicode: + repo: https://github.com/id3as/purescript-unicode + version: v5.0.0-erl1 + dependencies: + - foldable-traversable + - maybe + - psci-support + - strings + unsafe-coerce: + repo: https://github.com/purerl/purescript-unsafe-coerce.git + version: v5.0.0-erl1 + dependencies: [] + unsafe-reference: + repo: https://github.com/purerl/purescript-unsafe-reference.git + version: v4.0.0-erl1 + dependencies: + - prelude + uri: + repo: https://github.com/purescript-contrib/purescript-uri + version: v8.0.1 + dependencies: + - arrays + - integers + - js-uri + - numbers + - parsing + - prelude + - profunctor-lenses + - these + - transformers + - unfoldable + validation: + repo: https://github.com/purescript/purescript-validation.git + version: v5.0.0 + dependencies: + - bifunctors + - control + - either + - foldable-traversable + - newtype + - prelude + variant: + repo: https://github.com/natefaubion/purescript-variant.git + version: v7.0.3 + dependencies: + - enums + - lists + - maybe + - partial + - prelude + - record + - tuples + - unsafe-coerce + extra_packages: {} +packages: + arrays: + type: git + url: https://github.com/purerl/purescript-arrays.git + rev: 24ac35d3598af6bfb5e479d313f9493ab4d62984 + dependencies: + - bifunctors + - control + - foldable-traversable + - maybe + - nonempty + - partial + - prelude + - tailrec + - tuples + - unfoldable + - unsafe-coerce + assert: + type: git + url: https://github.com/purerl/purescript-assert.git + rev: b3f25ea1b27e64881c99032a5ec8d461b4491e25 + dependencies: + - console + - effect + - prelude + bifunctors: + type: git + url: https://github.com/purescript/purescript-bifunctors.git + rev: a31d0fc4bbebf19d5e9b21b65493c28b8d3fba62 + dependencies: + - const + - either + - newtype + - prelude + - tuples + console: + type: git + url: https://github.com/purerl/purescript-console.git + rev: 56cfd5294acb79758cf30b357751f624650f18e3 + dependencies: + - effect + - prelude + const: + type: git + url: https://github.com/purescript/purescript-const.git + rev: 3a3a4bdc44f71311cf27de9bd22039b110277540 + dependencies: + - invariant + - newtype + - prelude + contravariant: + type: git + url: https://github.com/purescript/purescript-contravariant.git + rev: ae1a765f7ddbfd96ae1f12e399e46d554d8e3b38 + dependencies: + - const + - either + - newtype + - prelude + - tuples + control: + type: git + url: https://github.com/purerl/purescript-control.git + rev: e3add624f8dacb4d6bec6d9ed682df692e197b5b + dependencies: + - newtype + - prelude + debug: + type: git + url: https://github.com/purerl/purescript-debug.git + rev: 3f6d18679e224249685bc690dfd5f0884a580374 + dependencies: + - prelude + distributive: + type: git + url: https://github.com/purescript/purescript-distributive.git + rev: 11f3f87ca5720899e1739cedb58dd6227cae6ad5 + dependencies: + - identity + - newtype + - prelude + - tuples + - type-equality + effect: + type: git + url: https://github.com/purerl/purescript-effect.git + rev: 69ba78cd96a27a0af6a723d255dc05a32c6eaa43 + dependencies: + - prelude + either: + type: git + url: https://github.com/purescript/purescript-either.git + rev: c1a1af35684f10eecaf6ac7d38dbf6bd48af2ced + dependencies: + - control + - invariant + - maybe + - prelude + enums: + type: git + url: https://github.com/purerl/purescript-enums.git + rev: 9c3ec61d03c04642af91e2ac72500cdd6009bd98 + dependencies: + - control + - either + - gen + - maybe + - newtype + - nonempty + - partial + - prelude + - tuples + - unfoldable + exists: + type: git + url: https://github.com/purescript/purescript-exists.git + rev: c34820f8b2d15be29abdd5097c3d636f5df8f28c + dependencies: + - unsafe-coerce + foldable-traversable: + type: git + url: https://github.com/purerl/purescript-foldable-traversable.git + rev: 444a611d64800a82259b9c22999330b6a7b48a3d + dependencies: + - bifunctors + - const + - control + - either + - functors + - identity + - maybe + - newtype + - orders + - prelude + - tuples + functions: + type: git + url: https://github.com/purerl/purescript-functions.git + rev: 6f0854f056b5295835db2cc3d06bf8763c181536 + dependencies: + - prelude + functors: + type: git + url: https://github.com/purescript/purescript-functors.git + rev: e936f7a8d2ec53a344c478ccada5add93273848c + dependencies: + - bifunctors + - const + - contravariant + - control + - distributive + - either + - invariant + - maybe + - newtype + - prelude + - profunctor + - tuples + - unsafe-coerce + gen: + type: git + url: https://github.com/purescript/purescript-gen.git + rev: 85c369f56545a3de834b7e7475a56bc9193bb4b4 + dependencies: + - either + - foldable-traversable + - identity + - maybe + - newtype + - nonempty + - prelude + - tailrec + - tuples + - unfoldable + identity: + type: git + url: https://github.com/purescript/purescript-identity.git + rev: 5c150ac5ee4fa6f145932f6322a1020463dae8e9 + dependencies: + - control + - invariant + - newtype + - prelude + integers: + type: git + url: https://github.com/purerl/purescript-integers.git + rev: 5549373344321575727cc1b3526ee946cff77a43 + dependencies: + - math + - maybe + - numbers + - prelude + invariant: + type: git + url: https://github.com/purescript/purescript-invariant.git + rev: c421b49dec7a1511073bb408a08bdd8c9d17d7b1 + dependencies: + - control + - prelude + math: + type: git + url: https://github.com/purerl/purescript-math.git + rev: c4760c2620980dbd7168b17ed21dfab12b8c5b39 + dependencies: [] + maybe: + type: git + url: https://github.com/purescript/purescript-maybe.git + rev: 8e96ca0187208e78e8df6a464c281850e5c9400c + dependencies: + - control + - invariant + - newtype + - prelude + newtype: + type: git + url: https://github.com/purescript/purescript-newtype.git + rev: 7b292fcd2ac7c4a25d7a7a8d3387d0ee7de89b13 + dependencies: + - prelude + - safe-coerce + nonempty: + type: git + url: https://github.com/purescript/purescript-nonempty.git + rev: d3e91e3d6e06e5bdcc5b2c21c8e5d0f9b946bb9e + dependencies: + - control + - foldable-traversable + - maybe + - prelude + - tuples + - unfoldable + numbers: + type: git + url: https://github.com/purerl/purescript-numbers.git + rev: 5446bc018f2970d91a8573c3424bba0b59305a21 + dependencies: + - functions + - math + - maybe + orders: + type: git + url: https://github.com/purescript/purescript-orders.git + rev: c25b7075426cf82bcb960495f28d2541c9a75510 + dependencies: + - newtype + - prelude + partial: + type: git + url: https://github.com/purerl/purescript-partial.git + rev: 6fe347eb3a36c70cacd4aeb581b5748a9d5035aa + dependencies: [] + prelude: + type: git + url: https://github.com/purerl/purescript-prelude.git + rev: 75a86f361270985ae983b59d4a69c0513b7f1cb1 + dependencies: [] + profunctor: + type: git + url: https://github.com/purescript/purescript-profunctor.git + rev: 4551b8e437a00268cc9b687cbe691d75e812e82b + dependencies: + - control + - distributive + - either + - exists + - invariant + - newtype + - prelude + - tuples + refs: + type: git + url: https://github.com/purerl/purescript-refs.git + rev: 1a921991d2c0900c4582d69586bfbd5ce3d53952 + dependencies: + - effect + - prelude + safe-coerce: + type: git + url: https://github.com/purescript/purescript-safe-coerce.git + rev: e719defd227d932da067a1f0d62a60b3d3ff3637 + dependencies: + - unsafe-coerce + tailrec: + type: git + url: https://github.com/purerl/purescript-tailrec.git + rev: a865d0787fef54e7350d8c1e8d2e9ed94fae47b7 + dependencies: + - bifunctors + - effect + - either + - identity + - maybe + - partial + - prelude + - refs + tuples: + type: git + url: https://github.com/purescript/purescript-tuples.git + rev: d4fe8ffe9e8c512111ee0bc18a6ba0fd056a6773 + dependencies: + - control + - invariant + - prelude + type-equality: + type: git + url: https://github.com/purescript/purescript-type-equality.git + rev: f7644468f22ed267a15d398173d234fa6f45e2e0 + dependencies: [] + unfoldable: + type: git + url: https://github.com/purerl/purescript-unfoldable.git + rev: 5d3b6ac48757c9aa93f6410f86266034fd510599 + dependencies: + - foldable-traversable + - maybe + - partial + - prelude + - tuples + unsafe-coerce: + type: git + url: https://github.com/purerl/purescript-unsafe-coerce.git + rev: 7150d261d40cd92112e8c2064124c5682627f137 + dependencies: [] diff --git a/spago.yaml b/spago.yaml new file mode 100644 index 0000000..c3f411c --- /dev/null +++ b/spago.yaml @@ -0,0 +1,32 @@ + +package: + name: strings + dependencies: + - arrays + - control + - either + - enums + - foldable-traversable + - gen + - integers + - maybe + - newtype + - nonempty + - partial + - prelude + - tailrec + - tuples + - unfoldable + - unsafe-coerce + test: + main: Test.Main + dependencies: + - assert + - debug +workspace: + package_set: + url: https://raw.githubusercontent.com/purerl/package-sets/erl-0.15.3-20220629/packages.json + hash: sha256-kLmZv2u5dWVUUaQEwK0b3T1Ghce5a/hG0zlizaYfcXs= + extra_packages: {} + backend: + cmd: purerl From 120eca495790eda7b019b5dfb0309a02829026e6 Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Tue, 24 Dec 2024 11:03:36 +0000 Subject: [PATCH 24/29] Update build to some copied nix thing --- .github/workflows/on-each-commit.yaml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/workflows/on-each-commit.yaml b/.github/workflows/on-each-commit.yaml index b933847..b323ff0 100644 --- a/.github/workflows/on-each-commit.yaml +++ b/.github/workflows/on-each-commit.yaml @@ -1,13 +1,12 @@ -on: [push] +name: build +on: + pull_request: + push: jobs: - run_tests: + tests: runs-on: ubuntu-latest - container: - image: fredthedino/purerl:0.0.16 steps: - - uses: actions/checkout@v2 - - name: 'Compile' - run: spago build - - name: 'Test' - run: spago test + - uses: actions/checkout@v2 + - uses: cachix/install-nix-action@v12 + - run: nix-shell --run 'spago test' From 7e2a53110baecec4453956c5752589a72ffcb58e Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Tue, 24 Dec 2024 11:09:25 +0000 Subject: [PATCH 25/29] build --- .github/workflows/on-each-commit.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/on-each-commit.yaml b/.github/workflows/on-each-commit.yaml index b323ff0..80ff207 100644 --- a/.github/workflows/on-each-commit.yaml +++ b/.github/workflows/on-each-commit.yaml @@ -9,4 +9,6 @@ jobs: steps: - uses: actions/checkout@v2 - uses: cachix/install-nix-action@v12 + with: + nix_path: nixpkgs=channel:nixos-unstable - run: nix-shell --run 'spago test' From 5c0e4320d994efacc793c8a468217f430ab24c43 Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Tue, 24 Dec 2024 11:18:35 +0000 Subject: [PATCH 26/29] Fix regex split bug per @richcarl --- src/Data/String/Regex.erl | 4 ++-- test/Test/Data/String/Regex.purs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Data/String/Regex.erl b/src/Data/String/Regex.erl index 3bda113..2331fe9 100644 --- a/src/Data/String/Regex.erl +++ b/src/Data/String/Regex.erl @@ -63,9 +63,9 @@ replace({R,{_,F}},S1,S2) -> _ -> Nothing end. -split({R,RS},S) -> +split({R,{RS,_Flags}},S) -> Res = re:split(S,R), Res1 = case RS of - "" -> lists:droplast(Res); + <<"">> -> lists:droplast(Res); _ -> Res end, array:from_list(Res1). diff --git a/test/Test/Data/String/Regex.purs b/test/Test/Data/String/Regex.purs index 245057f..9bcc9f0 100644 --- a/test/Test/Data/String/Regex.purs +++ b/test/Test/Data/String/Regex.purs @@ -45,8 +45,8 @@ testStringRegex = do assert $ search (unsafeRegex "d" noFlags) "abc" == Nothing log "split" - -- assert $ split (unsafeRegex "" noFlags) "" == [] - -- assert $ split (unsafeRegex "" noFlags) "abc" == ["a", "b", "c"] + assert $ split (unsafeRegex "" noFlags) "" == [] + assert $ split (unsafeRegex "" noFlags) "abc" == ["a", "b", "c"] assert $ split (unsafeRegex "b" noFlags) "" == [""] assert $ split (unsafeRegex "b" noFlags) "abc" == ["a", "c"] From 0601c7d2a652d270e0f986b4b795ddde351c4247 Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Tue, 24 Dec 2024 11:18:35 +0000 Subject: [PATCH 27/29] Fix regex split bug per @richcarl --- src/Data/String/Regex.erl | 4 ++-- test/Test/Data/String/Regex.purs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Data/String/Regex.erl b/src/Data/String/Regex.erl index 3bda113..2331fe9 100644 --- a/src/Data/String/Regex.erl +++ b/src/Data/String/Regex.erl @@ -63,9 +63,9 @@ replace({R,{_,F}},S1,S2) -> _ -> Nothing end. -split({R,RS},S) -> +split({R,{RS,_Flags}},S) -> Res = re:split(S,R), Res1 = case RS of - "" -> lists:droplast(Res); + <<"">> -> lists:droplast(Res); _ -> Res end, array:from_list(Res1). diff --git a/test/Test/Data/String/Regex.purs b/test/Test/Data/String/Regex.purs index 245057f..9bcc9f0 100644 --- a/test/Test/Data/String/Regex.purs +++ b/test/Test/Data/String/Regex.purs @@ -45,8 +45,8 @@ testStringRegex = do assert $ search (unsafeRegex "d" noFlags) "abc" == Nothing log "split" - -- assert $ split (unsafeRegex "" noFlags) "" == [] - -- assert $ split (unsafeRegex "" noFlags) "abc" == ["a", "b", "c"] + assert $ split (unsafeRegex "" noFlags) "" == [] + assert $ split (unsafeRegex "" noFlags) "abc" == ["a", "b", "c"] assert $ split (unsafeRegex "b" noFlags) "" == [""] assert $ split (unsafeRegex "b" noFlags) "abc" == ["a", "c"] From d0368d1d56db369ba9de440d0b741e045667172e Mon Sep 17 00:00:00 2001 From: Richard Carlsson Date: Sat, 2 Dec 2023 13:26:24 +0100 Subject: [PATCH 28/29] Use modern Erlang string functions in Data.String.Regex Drop use of obsolete string:chr(). --- src/Data/String/Regex.erl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Data/String/Regex.erl b/src/Data/String/Regex.erl index 2331fe9..4d22910 100644 --- a/src/Data/String/Regex.erl +++ b/src/Data/String/Regex.erl @@ -12,8 +12,8 @@ flags_to_options([$y|Flags], Acc) -> flags_to_options(Flags, [anchored|Acc]); %% flags_to_options([$u|Flags], Acc) -> flags_to_options(Flags, [ucp|[unicode|Acc]]); flags_to_options(_,_) -> err. -is_global(S) -> case string:chr(unicode:characters_to_list(S), $g) of - 0 -> false; +is_global(S) -> case string:find(S, <<"g"/utf8>>) of + nomatch -> false; _ -> true end. @@ -55,6 +55,7 @@ end. replace({R,{_,F}},S1,S2) -> G = case is_global(F) of true -> [global]; false -> [] end, re:replace(S2,R,S1,G++[{return,binary}]). + % TODO '_replaceBy'(_Just,_Nothing,{_R,_},_F,_S2) -> error("_replaceBy not supported"). From 9e80666fbdd0ee9aea956ca14f6d3a1feb255aef Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Tue, 2 Dec 2025 12:48:23 +0000 Subject: [PATCH 29/29] Fix CP.uncons by directly using erlang lib --- src/Data/String/CodePoints.erl | 11 ++++++++++- src/Data/String/CodePoints.purs | 26 ++++++++++++++------------ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/Data/String/CodePoints.erl b/src/Data/String/CodePoints.erl index a94dda1..91dd883 100644 --- a/src/Data/String/CodePoints.erl +++ b/src/Data/String/CodePoints.erl @@ -4,7 +4,10 @@ , '_fromCodePointArray'/2 , '_singleton'/1 , '_take'/1 - , '_toCodePointArray'/1]). + , '_toCodePointArray'/1 + , uncons/1, + take/3 + ]). '_unsafeCodePointAt0'(_Fallback) -> fun (Str) -> case string:next_codepoint(Str) of @@ -50,3 +53,9 @@ take(N, S, Cs) -> array:from_list(unicode:characters_to_list(Str, utf8)) end end. + +uncons(Str) -> + case string:next_codepoint(Str) of + [CP|Rest] -> {just, #{head => CP, tail => Rest}}; + _ -> {nothing} + end. diff --git a/src/Data/String/CodePoints.purs b/src/Data/String/CodePoints.purs index 11a3559..2f40f1b 100644 --- a/src/Data/String/CodePoints.purs +++ b/src/Data/String/CodePoints.purs @@ -188,18 +188,20 @@ codePointAtFallback n s = case uncons s of -- | Nothing -- | ``` -- | -uncons :: String -> Maybe { head :: CodePoint, tail :: String } -uncons s = case CU.length s of - 0 -> Nothing - 1 -> Just { head: CodePoint (fromEnum (Unsafe.charAt 0 s)), tail: "" } - _ -> - let - cu0 = fromEnum (Unsafe.charAt 0 s) - cu1 = fromEnum (Unsafe.charAt 1 s) - in - if isLead cu0 && isTrail cu1 - then Just { head: unsurrogate cu0 cu1, tail: CU.drop 2 s } - else Just { head: CodePoint cu0, tail: CU.drop 1 s } +foreign import uncons :: String -> Maybe { head :: CodePoint, tail :: String } + +-- uncons :: String -> Maybe { head :: CodePoint, tail :: String } +-- uncons s = case CU.length s of +-- 0 -> Nothing +-- 1 -> Just { head: CodePoint (fromEnum (Unsafe.charAt 0 s)), tail: "" } +-- _ -> +-- let +-- cu0 = fromEnum (Unsafe.charAt 0 s) +-- cu1 = fromEnum (Unsafe.charAt 1 s) +-- in +-- if isLead cu0 && isTrail cu1 +-- then Just { head: unsurrogate cu0 cu1, tail: CU.drop 2 s } +-- else Just { head: CodePoint cu0, tail: CU.drop 1 s } -- | Returns the number of code points in the string. Operates in constant -- | space and in time linear to the length of the string.