equal
deleted
inserted
replaced
22 def parse(sb: I) = |
22 def parse(sb: I) = |
23 for ((head, tail) <- p.parse(sb)) yield (f(head), tail) |
23 for ((head, tail) <- p.parse(sb)) yield (f(head), tail) |
24 } |
24 } |
25 |
25 |
26 // atomic parsers |
26 // atomic parsers |
|
27 case class CharParser(c: Char) extends Parser[String, Char] { |
|
28 def parse(sb: String) = |
|
29 if (sb.head == c) Set((c, sb.tail)) else Set() |
|
30 } |
|
31 |
27 case class StringParser(s: String) extends Parser[String, String] { |
32 case class StringParser(s: String) extends Parser[String, String] { |
28 def parse(sb: String) = { |
33 def parse(sb: String) = { |
29 val (prefix, suffix) = sb.splitAt(s.length) |
34 val (prefix, suffix) = sb.splitAt(s.length) |
30 if (prefix == s) Set((prefix, suffix)) else Set() |
35 if (prefix == s) Set((prefix, suffix)) else Set() |
31 } |
36 } |