Skip to content

Commit 71a0831

Browse files
committed
Merge pull request purescript-contrib#17 from kRITZCREEK/master
Extend Combinator Documentation
2 parents ffbd299 + 267a4bc commit 71a0831

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

docs/Text/Parsing/Parser/Combinators.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
Combinators for creating parsers.
44

5+
### Notes:
6+
A few of the known combinators from Parsec are missing in this module. That
7+
is because they have already been defined in other libraries.
8+
9+
```purescript
10+
Text.Parsec.many = Data.(Array|List).many
11+
Text.Parsec.many1 = Data.(Array|List).some
12+
Text.Parsec.(<|>) = Control.Alt.alt (<|>)
13+
```
14+
15+
Because Strings are not Char Arrays in PureScript `many` and `some` on Char Parsers need to
16+
be used in conjunction with `Data.String.fromCharArray` to achieve "Parsec-like" results.
17+
18+
```purescript
19+
Text.Parsec.many (char 'x') <=> fromCharArray <$> Data.Array.many (char 'x')
20+
```
21+
22+
===
23+
524
#### `(<?>)`
625

726
``` purescript

src/Text/Parsing/Parser/Combinators.purs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
-- | Combinators for creating parsers.
2+
-- |
3+
-- | ### Notes:
4+
-- | A few of the known combinators from Parsec are missing in this module. That
5+
-- | is because they have already been defined in other libraries.
6+
-- |
7+
-- | ```purescript
8+
-- | Text.Parsec.many = Data.(Array|List).many
9+
-- | Text.Parsec.many1 = Data.(Array|List).some
10+
-- | Text.Parsec.(<|>) = Control.Alt.alt (<|>)
11+
-- | ```
12+
-- |
13+
-- | Because Strings are not Char Arrays in PureScript `many` and `some` on Char Parsers need to
14+
-- | be used in conjunction with `Data.String.fromCharArray` to achieve "Parsec-like" results.
15+
-- |
16+
-- | ```purescript
17+
-- | Text.Parsec.many (char 'x') <=> fromCharArray <$> Data.Array.many (char 'x')
18+
-- | ```
19+
-- |
20+
-- | ===
221

322
module Text.Parsing.Parser.Combinators where
423

@@ -30,7 +49,7 @@ import Text.Parsing.Parser
3049
-- | Wrap a parser with opening and closing markers.
3150
-- |
3251
-- | For example:
33-
-- |
52+
-- |
3453
-- | ```purescript
3554
-- | parens = between (string "(") (string ")")
3655
-- | ```
@@ -64,7 +83,7 @@ try p = ParserT $ \(PState { input: s, position: pos }) -> try' s pos <$> unPars
6483
-- | Parse phrases delimited by a separator.
6584
-- |
6685
-- | For example:
67-
-- |
86+
-- |
6887
-- | ```purescript
6988
-- | digit `sepBy` string ","
7089
-- | ```
@@ -109,7 +128,7 @@ endBy p sep = many $ do
109128
-- | Parse phrases delimited by a right-associative operator.
110129
-- |
111130
-- | For example:
112-
-- |
131+
-- |
113132
-- | ```purescript
114133
-- | chainr digit (string "+" *> add) 0
115134
-- | ```

0 commit comments

Comments
 (0)