@@ -9,7 +9,7 @@ import Prelude hiding (between, when)
99
1010import Control.Alt ((<|>))
1111import Control.Lazy (fix )
12- import Control.Monad.State (State , modify , runState )
12+ import Control.Monad.State (State , lift , modify , runState )
1313import Data.Array (some , toUnfoldable )
1414import Data.Array as Array
1515import Data.Bifunctor (lmap , rmap )
@@ -18,7 +18,7 @@ import Data.Foldable (oneOf)
1818import Data.List (List (..), fromFoldable , (:))
1919import Data.List.NonEmpty (NonEmptyList (..), catMaybes , cons , cons' )
2020import Data.List.NonEmpty as NE
21- import Data.Maybe (Maybe (..), fromJust )
21+ import Data.Maybe (Maybe (..), fromJust , maybe )
2222import Data.NonEmpty ((:|))
2323import Data.Number (infinity , nan )
2424import Data.Number as Data.Number
@@ -34,12 +34,12 @@ import Effect.Console (log, logShow)
3434import Effect.Unsafe (unsafePerformEffect )
3535import Node.Process (lookupEnv )
3636import 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 , (<?>), (<??>), (<~?>))
3838import Parsing.Expr (Assoc (..), Operator (..), buildExprParser )
3939import Parsing.Language (haskellDef , haskellStyle , javaStyle )
4040import 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 )
4343import Parsing.Token (TokenParser , makeTokenParser , token , when )
4444import Parsing.Token as Token
4545import Partial.Unsafe (unsafePartial )
@@ -951,20 +951,16 @@ main = do
951951 { actual: splitCap " abc" consume
952952 , expected: NonEmptyList $ Right unit :| Left " a" : Right unit : Left " b" : Right unit : Left " c" : Right unit : Nil
953953 }
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" )
960956 , expected: " aCd"
961957 }
962- assertEqual' " streamEdit3 "
963- { actual: streamEdit " abcd" (takeN 1 ) toUpper
958+ assertEqual' " replace3 "
959+ { actual: replace " abcd" (toUpper <$> takeN 1 )
964960 , expected: " ABCD"
965961 }
966- assertEqual' " streamEdit4 "
967- { actual: streamEdit " abc" (pure unit) (\_ -> " X" )
962+ assertEqual' " replace4 "
963+ { actual: replace " abc" (pure " X" )
968964 , expected: " XaXbXcX"
969965 }
970966 assertEqual' " String.Replace example0"
@@ -979,10 +975,17 @@ main = do
979975 { actual: catMaybes $ hush <$> splitCap " .A...\n ...A." (position <* string " A" )
980976 , expected: (Position { index: 1 , line: 1 , column: 2 }) : (Position { index: 9 , line: 2 , column: 4 } : Nil )
981977 }
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
984983 , expected: " ◀ " <> unsafePartial (fromJust (unsafePerformEffect (lookupEnv " HOME" ))) <> " ▶"
985984 }
985+ assertEqual' " String.Replace example4'"
986+ { actual: replace " 1 6 21 107" (show <$> (_ * 2 ) <$> intDecimal)
987+ , expected: " 2 12 42 214"
988+ }
986989 assertEqual' " String.Replace example4"
987990 { actual:
988991 let
@@ -1006,6 +1009,10 @@ main = do
10061009 rmap fst <$> splitCap " ((🌼)) (()())" (match balancedParens)
10071010 , expected: NonEmptyList $ Right " ((🌼))" :| Left " " : Right " (()())" : Nil
10081011 }
1012+ assertEqual' " String.Replace example6"
1013+ { actual: replace " hay needle hay" (toUpper <$> string " needle" )
1014+ , expected: " hay NEEDLE hay"
1015+ }
10091016
10101017 log " \n TESTS manyIndex\n "
10111018
0 commit comments