@@ -9,7 +9,7 @@ import Prelude hiding (between, when)
9
9
10
10
import Control.Alt ((<|>))
11
11
import Control.Lazy (fix )
12
- import Control.Monad.State (State , modify , runState )
12
+ import Control.Monad.State (State , lift , modify , runState )
13
13
import Data.Array (some , toUnfoldable )
14
14
import Data.Array as Array
15
15
import Data.Bifunctor (lmap , rmap )
@@ -18,7 +18,7 @@ import Data.Foldable (oneOf)
18
18
import Data.List (List (..), fromFoldable , (:))
19
19
import Data.List.NonEmpty (NonEmptyList (..), catMaybes , cons , cons' )
20
20
import Data.List.NonEmpty as NE
21
- import Data.Maybe (Maybe (..), fromJust )
21
+ import Data.Maybe (Maybe (..), fromJust , maybe )
22
22
import Data.NonEmpty ((:|))
23
23
import Data.Number (infinity , nan )
24
24
import Data.Number as Data.Number
@@ -34,12 +34,12 @@ import Effect.Console (log, logShow)
34
34
import Effect.Unsafe (unsafePerformEffect )
35
35
import Node.Process (lookupEnv )
36
36
import Parsing (ParseError (..), Parser , ParserT , Position (..), consume , fail , initialPos , parseErrorMessage , parseErrorPosition , position , region , runParser )
37
- import Parsing.Combinators (advance , between , chainl , chainl1 , chainr , chainr1 , choice , endBy , endBy1 , lookAhead , many , many1 , many1Till , many1Till_ , manyIndex , manyTill , manyTill_ , notFollowedBy , optionMaybe , sepBy , sepBy1 , sepEndBy , sepEndBy1 , skipMany , skipMany1 , try , (<?>), (<??>), (<~?>))
37
+ import Parsing.Combinators (advance , between , chainl , chainl1 , chainr , chainr1 , choice , empty , endBy , endBy1 , lookAhead , many , many1 , many1Till , many1Till_ , manyIndex , manyTill , manyTill_ , notFollowedBy , optionMaybe , sepBy , sepBy1 , sepEndBy , sepEndBy1 , skipMany , skipMany1 , try , (<?>), (<??>), (<~?>))
38
38
import Parsing.Expr (Assoc (..), Operator (..), buildExprParser )
39
39
import Parsing.Language (haskellDef , haskellStyle , javaStyle )
40
40
import Parsing.String (anyChar , anyCodePoint , anyTill , char , eof , match , regex , rest , satisfy , string , takeN )
41
- import Parsing.String.Basic (intDecimal , number , letter , noneOfCodePoints , oneOfCodePoints , whiteSpace )
42
- import Parsing.String.Replace (breakCap , splitCap , splitCapT , streamEdit , streamEditT )
41
+ import Parsing.String.Basic (intDecimal , letter , noneOfCodePoints , number , oneOfCodePoints , whiteSpace )
42
+ import Parsing.String.Replace (breakCap , replace , replaceT , splitCap , splitCapT )
43
43
import Parsing.Token (TokenParser , makeTokenParser , token , when )
44
44
import Parsing.Token as Token
45
45
import Partial.Unsafe (unsafePartial )
@@ -951,20 +951,16 @@ main = do
951
951
{ actual: splitCap " abc" consume
952
952
, expected: NonEmptyList $ Right unit :| Left " a" : Right unit : Left " b" : Right unit : Left " c" : Right unit : Nil
953
953
}
954
- assertEqual' " streamEdit1"
955
- { actual: streamEdit " aBc" (match $ string " B" ) fst
956
- , expected: " aBc"
957
- }
958
- assertEqual' " streamEdit2"
959
- { actual: streamEdit " aBd" (string " B" ) (const " C" )
954
+ assertEqual' " replace2"
955
+ { actual: replace " aBd" (string " B" *> pure " C" )
960
956
, expected: " aCd"
961
957
}
962
- assertEqual' " streamEdit3 "
963
- { actual: streamEdit " abcd" (takeN 1 ) toUpper
958
+ assertEqual' " replace3 "
959
+ { actual: replace " abcd" (toUpper <$> takeN 1 )
964
960
, expected: " ABCD"
965
961
}
966
- assertEqual' " streamEdit4 "
967
- { actual: streamEdit " abc" (pure unit) (\_ -> " X" )
962
+ assertEqual' " replace4 "
963
+ { actual: replace " abc" (pure " X" )
968
964
, expected: " XaXbXcX"
969
965
}
970
966
assertEqual' " String.Replace example0"
@@ -979,10 +975,17 @@ main = do
979
975
{ actual: catMaybes $ hush <$> splitCap " .A...\n ...A." (position <* string " A" )
980
976
, expected: (Position { index: 1 , line: 1 , column: 2 }) : (Position { index: 9 , line: 2 , column: 4 } : Nil )
981
977
}
982
- assertEqual' " String.Replace example3"
983
- { actual: unsafePerformEffect $ streamEditT " ◀ {HOME} ▶" (string " {" *> anyTill (string " }" )) (fst >>> lookupEnv >=> unsafePartial fromJust >>> pure)
978
+ assertEqual' " String.Replace example3'"
979
+ { actual: unsafePerformEffect $ replaceT " ◀ {HOME} ▶" do
980
+ _ <- string " {"
981
+ Tuple home _ <- anyTill (string " }" )
982
+ lift (lookupEnv home) >>= maybe empty pure
984
983
, expected: " ◀ " <> unsafePartial (fromJust (unsafePerformEffect (lookupEnv " HOME" ))) <> " ▶"
985
984
}
985
+ assertEqual' " String.Replace example4'"
986
+ { actual: replace " 1 6 21 107" (show <$> (_ * 2 ) <$> intDecimal)
987
+ , expected: " 2 12 42 214"
988
+ }
986
989
assertEqual' " String.Replace example4"
987
990
{ actual:
988
991
let
@@ -1006,6 +1009,10 @@ main = do
1006
1009
rmap fst <$> splitCap " ((🌼)) (()())" (match balancedParens)
1007
1010
, expected: NonEmptyList $ Right " ((🌼))" :| Left " " : Right " (()())" : Nil
1008
1011
}
1012
+ assertEqual' " String.Replace example6"
1013
+ { actual: replace " hay needle hay" (toUpper <$> string " needle" )
1014
+ , expected: " hay NEEDLE hay"
1015
+ }
1009
1016
1010
1017
log " \n TESTS manyIndex\n "
1011
1018
0 commit comments