forked from charleso/introduction-to-fp-in-scala
-
Notifications
You must be signed in to change notification settings - Fork 2
/
MoreParser.scala
46 lines (40 loc) · 1.21 KB
/
MoreParser.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package challenge
import intro.Applicative
object MoreParser {
/**
* Write a parser that will parse zero or more spaces, tabs and newlines.
*
* scala> MoreParser.whitespace.run(" \n\t a")
* = Ok(ParseState(a,())
*/
def whitespace: Parser[Unit] =
???
/**
* Write a function that parses the given string (fails otherwise).
*
* Tip: Use `is` and `traverse`.
*
* scala> MoreParser.string("test").run("testing")
* = Ok(ParseState(ing,test))
*/
def string(s: String): Parser[String] =
???
/**
* Write a function that produces a non-empty list of values coming off the given parser (which must succeed at least
* once), separated by the second given parser.
*/
def sepBy1[A, B](ap: Parser[A], bp: Parser[B]): Parser[List[A]] =
???
/**
* Write a function that produces a list of values coming off the given parser,
* separated by the second given parser.
*
* scala> MoreParser.sepBy(Parser.alpha, Parser.is(' ')).run("1 2 10!")
* = Ok(ParseState(!,List(1,2,10))
*
* scala> MoreParser.sepBy(Parser.alpha, Parser.is(' ')).run("!")
* = Ok(ParseState(!,List())
*/
def sepBy[A, B](ap: Parser[A], bp: Parser[B]): Parser[List[A]] =
???
}