fork download
  1. import scala.util.parsing.input._
  2. import scala.util.parsing.combinator._
  3.  
  4. object Main extends App with Parsers with RegexParsers {
  5. override def skipWhitespace = false
  6.  
  7. val pair = for (
  8. name <- """[^:]+""".r;
  9. _ <- """:\s*""".r;
  10. isMoron <- ("true" | "false").map(_.toBoolean)
  11. ) yield (name, isMoron)
  12. val morons = repsep(pair, """\r?\n""".r)
  13.  
  14. val input = """Bartek Banachewicz: false
  15. Ell: false
  16. Puppy: true
  17. rightfold: false"""
  18.  
  19. morons(new CharSequenceReader(input)) match {
  20. case Success(elements, _) =>
  21. elements.foreach { case (name, isMoron) =>
  22. println(name + " is" + (if (isMoron) "" else " not") + " a moron!")
  23. }
  24. }
  25. }
  26.  
Success #stdin #stdout 0.46s 382144KB
stdin
Standard input is empty
stdout
Bartek Banachewicz is not a moron!
Ell is not a moron!
Puppy is a moron!
rightfold is not a moron!