progs/parser-combinators/comb1.sc
changeset 849 3d5ecb8f1f2f
parent 828 bdcaecdee9eb
child 850 ea320c9427d2
equal deleted inserted replaced
848:2e868b5867d8 849:3d5ecb8f1f2f
   101 val NumParserInt2 = NumParser.map(_.toInt)
   101 val NumParserInt2 = NumParser.map(_.toInt)
   102 
   102 
   103 
   103 
   104 // A parser for palindromes (just returns them as string)
   104 // A parser for palindromes (just returns them as string)
   105 lazy val Pal : Parser[String, String] = {
   105 lazy val Pal : Parser[String, String] = {
   106   (p"a" ~ Pal ~ p"a").map{ case ((x, y), z) => s"$x$y$z" } || 
   106   ((p"a" ~ Pal) ~ p"a").map{ case ((x, y), z) => s"$x$y$z" } || 
   107   (p"b" ~ Pal ~ p"b").map{ case ((x, y), z) => s"$x$y$z" } || 
   107   (p"b" ~ Pal ~ p"b").map{ case ((x, y), z) => s"$x$y$z" } || 
   108   p"a" || p"b" || p""
   108   p"a" || p"b" || p""
   109 }  
   109 }  
       
   110 
       
   111 def foo(x: Int) = 
       
   112    println(s"$x + $x = ${x + x}")
   110 
   113 
   111 // examples
   114 // examples
   112 Pal.parse_all("abaaaba")
   115 Pal.parse_all("abaaaba")
   113 Pal.parse("abaaaba")
   116 Pal.parse("abaaaba")
   114 
   117