Skip to content

Commit 7531526

Browse files
committed
Add docs for keep and skip
1 parent ebf6415 commit 7531526

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

src/Parser.gren

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module Parser exposing
2121
@docs int, float, number, symbol, keyword, variable, end
2222

2323
# Pipelines
24-
@docs succeed, (|=), (|.), lazy, andThen, problem
24+
@docs succeed, (|=), (|.), keep, skip, lazy, andThen, problem
2525

2626
# Branches
2727
@docs oneOf, map, backtrackable, commit, token
@@ -233,22 +233,36 @@ succeed =
233233
A.succeed
234234

235235

236+
{-| Deprecated. Please look at [keep](#keep) instead.
237+
-}
238+
keeper : Parser (a -> b) -> Parser a -> Parser b
239+
keeper =
240+
(|=)
241+
242+
243+
{-| Deprecated. Please look at [skip](#skip) instead.
244+
-}
245+
ignorer : Parser keep -> Parser ignore -> Parser keep
246+
ignorer =
247+
(|.)
248+
249+
236250
{-| **Keep** values in a parser pipeline. For example, we could say:
237251

238252
type alias Point = { x : Float, y : Float }
239253

240254
point : Parser Point
241255
point =
242256
succeed (\x y -> { x = x, y = y })
243-
|. symbol "("
244-
|. spaces
245-
|= float
246-
|. spaces
247-
|. symbol ","
248-
|. spaces
249-
|= float
250-
|. spaces
251-
|. symbol ")"
257+
|> skip (symbol "(")
258+
|> skip spaces
259+
|> keep float
260+
|> skip spaces
261+
|> skip (symbol ",")
262+
|> skip spaces
263+
|> keep float
264+
|> skip spaces
265+
|> skip (symbol ")")
252266

253267
All the parsers in this pipeline will chomp characters and produce values. So
254268
`symbol "("` will chomp one paren and produce a `{}` value. Similarly, `float`
@@ -258,9 +272,9 @@ operators just decide whether we give the values to the `Point` function.
258272
So in this case, we skip the `{}` from `symbol "("`, we skip the `{}` from
259273
`spaces`, we keep the `Float` from `float`, etc.
260274
-}
261-
keeper : Parser (a -> b) -> Parser a -> Parser b
262-
keeper =
263-
(|=)
275+
keep : Parser keep -> Parser (keep -> b) -> Parser b
276+
keep =
277+
A.keep
264278

265279

266280
{-| **Skip** values in a parser pipeline. For example, maybe we want to parse
@@ -270,8 +284,8 @@ some JavaScript variables:
270284
var =
271285
getChompedString <|
272286
succeed {}
273-
|. chompIf isStartChar
274-
|. chompWhile isInnerChar
287+
|> skip (chompIf isStartChar)
288+
|> skip (chompWhile isInnerChar)
275289

276290
isStartChar : Char -> Bool
277291
isStartChar char =
@@ -286,16 +300,6 @@ some JavaScript variables:
286300
value. The `(|.)` operators are saying to still chomp all the characters, but
287301
skip the two `{}` values that get produced. No one cares about them.
288302
-}
289-
ignorer : Parser keep -> Parser ignore -> Parser keep
290-
ignorer =
291-
(|.)
292-
293-
294-
keep : Parser keep -> Parser (keep -> b) -> Parser b
295-
keep =
296-
A.keep
297-
298-
299303
skip : Parser ignore -> Parser kept -> Parser kept
300304
skip =
301305
A.skip

src/Parser/Advanced.gren

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ certain scenarios.**
2727
@docs int, float, number, symbol, keyword, variable, end
2828

2929
# Pipelines
30-
@docs succeed, (|=), (|.), lazy, andThen, problem
30+
@docs succeed, (|=), (|.), keep, skip, lazy, andThen, problem
3131

3232
# Branches
3333
@docs oneOf, map, backtrackable, commit, token
@@ -322,14 +322,14 @@ ignorer keepParser ignoreParser =
322322
map2 (\val _ -> val) keepParser ignoreParser
323323

324324

325-
{-| Just like the [`(|=)`](Parser#|=) from the `Parser` module.
325+
{-| Just like [keep](Parser#keep) from the `Parser` module.
326326
-}
327327
keep : Parser c x a -> Parser c x (a -> b) -> Parser c x b
328328
keep parseArg parseFunc =
329329
map2 (<|) parseFunc parseArg
330330

331331

332-
{-| Just like the [`(|.)`](Parser#|.) from the `Parser` module.
332+
{-| Just like [skip](Parser#skip) from the `Parser` module.
333333
-}
334334
skip : Parser c x ignore -> Parser c x keep -> Parser c x keep
335335
skip ignoreParser keepParser =

0 commit comments

Comments
 (0)