@@ -38,7 +38,7 @@ module Text.Parsing.Parser.String
38
38
, match
39
39
, regex
40
40
, RegexFlagsRow
41
- , splitMap
41
+ , consumeWith
42
42
) where
43
43
44
44
import Prelude hiding (between )
@@ -77,12 +77,12 @@ eof = ParserT
77
77
78
78
-- | Match the entire rest of the input stream. Always succeeds.
79
79
rest :: forall m . ParserT String m String
80
- rest = splitMap \consumed ->
80
+ rest = consumeWith \consumed ->
81
81
Right { value: consumed, consumed, remainder: " " }
82
82
83
83
-- | Match the specified string.
84
84
string :: forall m . String -> ParserT String m String
85
- string str = splitMap \input ->
85
+ string str = consumeWith \input ->
86
86
case stripPrefix (Pattern str) input of
87
87
Just remainder ->
88
88
Right { value: str, consumed: str, remainder }
@@ -141,7 +141,7 @@ char c = satisfy (_ == c) <?> show c
141
141
142
142
-- | Match a `String` exactly *N* characters long.
143
143
takeN :: forall m . Int -> ParserT String m String
144
- takeN n = splitMap \input -> do
144
+ takeN n = consumeWith \input -> do
145
145
let { before, after } = splitAt n input
146
146
if length before == n then
147
147
Right { value: before, consumed: before, remainder: after }
@@ -155,7 +155,7 @@ whiteSpace = fst <$> match skipSpaces
155
155
156
156
-- | Skip whitespace characters and throw them away. Always succeeds.
157
157
skipSpaces :: forall m . ParserT String m Unit
158
- skipSpaces = splitMap \input -> do
158
+ skipSpaces = consumeWith \input -> do
159
159
let consumed = takeWhile isSpace input
160
160
let remainder = SCU .drop (SCU .length consumed) input
161
161
Right { value: unit, consumed, remainder }
@@ -291,7 +291,7 @@ regex flags pattern =
291
291
Left paterr ->
292
292
fail $ " Regex pattern error " <> paterr
293
293
Right regexobj ->
294
- splitMap \input -> do
294
+ consumeWith \input -> do
295
295
case NonEmptyArray .head <$> Regex .match regexobj input of
296
296
Just (Just consumed) -> do
297
297
let remainder = SCU .drop (SCU .length consumed) input
@@ -320,15 +320,15 @@ type RegexFlagsRow =
320
320
, unicode :: Boolean
321
321
)
322
322
323
- -- | Splits the input string while yielding a value.
323
+ -- | Consumes a portion of the input string while yielding a value.
324
324
-- | * `value` is the value to return.
325
325
-- | * `consumed` is the input that was consumed and is used to update the parser position.
326
326
-- | * `remainder` is the new input state.
327
- splitMap
327
+ consumeWith
328
328
:: forall m a
329
329
. (String -> Either String { value :: a , consumed :: String , remainder :: String } )
330
330
-> ParserT String m a
331
- splitMap f = ParserT
331
+ consumeWith f = ParserT
332
332
( mkFn5 \state1@(ParseState input pos _) _ _ throw done ->
333
333
case f input of
334
334
Left err ->
0 commit comments