Skip to content

Commit 03a4dfe

Browse files
committed
Updates for 0.7
1 parent 147e431 commit 03a4dfe

File tree

14 files changed

+521
-161
lines changed

14 files changed

+521
-161
lines changed

Gruntfile.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# purescript-string-parsers
22

3-
A parsing library for parsing strings
3+
A parsing library for parsing strings.
44

5+
This library is a simpler, faster alternative to `purescript-parsing`, for when you know your input will be a string.
6+
7+
## Installing
8+
9+
bower i purescript-string-parsers
10+
11+
- [Module Documentation](docs/)

bower.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
"package.json"
1818
],
1919
"dependencies": {
20-
"purescript-control": "~0.2.0",
21-
"purescript-arrays": "~0.3.0",
22-
"purescript-maybe": "~0.2.0",
23-
"purescript-strings": "~0.4.2",
24-
"purescript-foldable-traversable": "~0.3.0"
20+
"purescript-control": "^0.3.0",
21+
"purescript-arrays": "^0.4.0",
22+
"purescript-maybe": "^0.3.0",
23+
"purescript-strings": "^0.5.0",
24+
"purescript-foldable-traversable": "^0.4.0"
2525
},
2626
"devDependencies": {
27-
"purescript-math": "~0.1.0",
28-
"purescript-quickcheck": "~0.5.0"
27+
"purescript-math": "^0.2.0",
28+
"purescript-quickcheck": "^0.6.0"
2929
}
3030
}

docs/Text/Parsing/StringParser.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
## Module Text.Parsing.StringParser
2+
3+
This module defines the `Parser` type of string parsers, and its instances.
4+
5+
#### `Pos`
6+
7+
``` purescript
8+
type Pos = Int
9+
```
10+
11+
A poition in an input string.
12+
13+
#### `PosString`
14+
15+
``` purescript
16+
type PosString = { str :: String, pos :: Pos }
17+
```
18+
19+
Strings are represented as a string with an index from the
20+
start of the string.
21+
22+
`{ str: s, pos: n }` is interpreted as the substring of `s`
23+
starting at index n.
24+
25+
This allows us to avoid repeatedly finding substrings
26+
every time we match a character.
27+
28+
#### `ParseError`
29+
30+
``` purescript
31+
data ParseError
32+
= ParseError String
33+
```
34+
35+
The type of parsing errors.
36+
37+
##### Instances
38+
``` purescript
39+
instance showParseError :: Show ParseError
40+
```
41+
42+
#### `Parser`
43+
44+
``` purescript
45+
data Parser a
46+
= Parser (forall r. PosString -> (Pos -> ParseError -> r) -> (a -> PosString -> r) -> r)
47+
```
48+
49+
A parser is represented as a function which takes a pair of
50+
continuations for failure and success.
51+
52+
##### Instances
53+
``` purescript
54+
instance functorParser :: Functor Parser
55+
instance applyParser :: Apply Parser
56+
instance applicativeParser :: Applicative Parser
57+
instance altParser :: Alt Parser
58+
instance plusParser :: Plus Parser
59+
instance alternativeParser :: Alternative Parser
60+
instance bindParser :: Bind Parser
61+
instance monadParser :: Monad Parser
62+
instance monadPlusParser :: MonadPlus Parser
63+
```
64+
65+
#### `unParser`
66+
67+
``` purescript
68+
unParser :: forall a r. Parser a -> PosString -> (Pos -> ParseError -> r) -> (a -> PosString -> r) -> r
69+
```
70+
71+
Run a parser by providing success and failure continuations.
72+
73+
#### `runParser`
74+
75+
``` purescript
76+
runParser :: forall a. Parser a -> String -> Either ParseError a
77+
```
78+
79+
Run a parser for an input string, returning either an error or a result.
80+
81+
#### `fail`
82+
83+
``` purescript
84+
fail :: forall a. String -> Parser a
85+
```
86+
87+
Fail with the specified message.
88+
89+
#### `try`
90+
91+
``` purescript
92+
try :: forall a. Parser a -> Parser a
93+
```
94+
95+
In case of error, the default behavior is to backtrack if no input was consumed.
96+
97+
`try p` backtracks even if input was consumed.
98+
99+
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
## Module Text.Parsing.StringParser.Combinators
2+
3+
This module defines combinators for building string parsers.
4+
5+
#### `lookAhead`
6+
7+
``` purescript
8+
lookAhead :: forall a. Parser a -> Parser a
9+
```
10+
11+
Read ahead without consuming input.
12+
13+
#### `many`
14+
15+
``` purescript
16+
many :: forall a. Parser a -> Parser (List a)
17+
```
18+
19+
Match zero or more times.
20+
21+
#### `many1`
22+
23+
``` purescript
24+
many1 :: forall a. Parser a -> Parser (List a)
25+
```
26+
27+
Match one or more times.
28+
29+
#### `(<?>)`
30+
31+
``` purescript
32+
(<?>) :: forall a. Parser a -> String -> Parser a
33+
```
34+
35+
_left-associative / precedence -1_
36+
37+
Provide an error message in case of failure.
38+
39+
#### `fix`
40+
41+
``` purescript
42+
fix :: forall a. (Parser a -> Parser a) -> Parser a
43+
```
44+
45+
Take the fixed point of a parser function. This function is sometimes useful when building recursive parsers.
46+
47+
#### `between`
48+
49+
``` purescript
50+
between :: forall a open close. Parser open -> Parser close -> Parser a -> Parser a
51+
```
52+
53+
Parse a string between opening and closing markers.
54+
55+
#### `option`
56+
57+
``` purescript
58+
option :: forall a. a -> Parser a -> Parser a
59+
```
60+
61+
Parse a value with a default value in case of failure.
62+
63+
#### `optional`
64+
65+
``` purescript
66+
optional :: forall a. Parser a -> Parser Unit
67+
```
68+
69+
Attempt to parse a value.
70+
71+
#### `optionMaybe`
72+
73+
``` purescript
74+
optionMaybe :: forall a. Parser a -> Parser (Maybe a)
75+
```
76+
77+
Attempt to parse a value, returning `Nothing` in case of failure.
78+
79+
#### `sepBy`
80+
81+
``` purescript
82+
sepBy :: forall a sep. Parser a -> Parser sep -> Parser (List a)
83+
```
84+
85+
Parse zero or more separated values.
86+
87+
#### `sepBy1`
88+
89+
``` purescript
90+
sepBy1 :: forall a sep. Parser a -> Parser sep -> Parser (List a)
91+
```
92+
93+
Parse one or more separated values.
94+
95+
#### `sepEndBy`
96+
97+
``` purescript
98+
sepEndBy :: forall a sep. Parser a -> Parser sep -> Parser (List a)
99+
```
100+
101+
Parse zero or more separated values, optionally ending with a separator.
102+
103+
#### `sepEndBy1`
104+
105+
``` purescript
106+
sepEndBy1 :: forall a sep. Parser a -> Parser sep -> Parser (List a)
107+
```
108+
109+
Parse one or more separated values, optionally ending with a separator.
110+
111+
#### `endBy1`
112+
113+
``` purescript
114+
endBy1 :: forall a sep. Parser a -> Parser sep -> Parser (List a)
115+
```
116+
117+
Parse zero or more separated values, ending with a separator.
118+
119+
#### `endBy`
120+
121+
``` purescript
122+
endBy :: forall a sep. Parser a -> Parser sep -> Parser (List a)
123+
```
124+
125+
Parse one or more separated values, ending with a separator.
126+
127+
#### `chainr`
128+
129+
``` purescript
130+
chainr :: forall a. Parser a -> Parser (a -> a -> a) -> a -> Parser a
131+
```
132+
133+
Parse zero or more values separated by a right-associative operator.
134+
135+
#### `chainl`
136+
137+
``` purescript
138+
chainl :: forall a. Parser a -> Parser (a -> a -> a) -> a -> Parser a
139+
```
140+
141+
Parse zero or more values separated by a left-associative operator.
142+
143+
#### `chainl1`
144+
145+
``` purescript
146+
chainl1 :: forall a. Parser a -> Parser (a -> a -> a) -> Parser a
147+
```
148+
149+
Parse one or more values separated by a left-associative operator.
150+
151+
#### `chainl1'`
152+
153+
``` purescript
154+
chainl1' :: forall a. Parser a -> Parser (a -> a -> a) -> a -> Parser a
155+
```
156+
157+
Parse one or more values separated by a left-associative operator.
158+
159+
#### `chainr1`
160+
161+
``` purescript
162+
chainr1 :: forall a. Parser a -> Parser (a -> a -> a) -> Parser a
163+
```
164+
165+
Parse one or more values separated by a right-associative operator.
166+
167+
#### `chainr1'`
168+
169+
``` purescript
170+
chainr1' :: forall a. Parser a -> Parser (a -> a -> a) -> a -> Parser a
171+
```
172+
173+
Parse one or more values separated by a right-associative operator.
174+
175+
#### `choice`
176+
177+
``` purescript
178+
choice :: forall f a. (Foldable f) => f (Parser a) -> Parser a
179+
```
180+
181+
Parse using any of a collection of parsers.
182+
183+
#### `manyTill`
184+
185+
``` purescript
186+
manyTill :: forall a end. Parser a -> Parser end -> Parser (List a)
187+
```
188+
189+
Parse values until a terminator.
190+
191+

0 commit comments

Comments
 (0)