Commit 0419f468 authored by Marcel Gerber's avatar Marcel Gerber
Browse files

Lecture 12

parent 2c09544c
......@@ -10,5 +10,8 @@ object Combinators {
/* Implement many1, which matches at least one element, returning a NonEmptyList.
* If no element is found, the parser should fail. You may use any other parsers and combinators we have defined.
*/
def many1[A](p: Parser[A]): Parser[NonEmptyList[A]] = ???
def many1[A](p: Parser[A]): Parser[NonEmptyList[A]] = for {
one <- p
more <- p.many
} yield NonEmptyList(one, more)
}
......@@ -16,5 +16,14 @@ object ContactParser {
* As a simplification, we only accept street names without spaces and house numbers without letters.
* Each whitespace in the pattern above should be present (one or more whitespace characters).
*/
def address: Parser[Address] = ???
def address: Parser[Address] = for {
street <- word
_ <- whitespace
number <- int
_ <- char(',')
_ <- whitespace
postcode <- int
_ <- whitespace
city <- word
} yield Address(street, number, postcode, city)
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment