diff -r f63ba92a7d78 -r 774007c4b1b3 regexp.scala --- a/regexp.scala Wed Oct 10 14:08:49 2012 +0100 +++ b/regexp.scala Thu Oct 11 10:58:18 2012 +0100 @@ -9,9 +9,13 @@ case class STAR(r: Rexp) extends Rexp // some convenience for typing in regular expressions -implicit def string2rexp(s : String) : Rexp = { - s.foldRight (EMPTY: Rexp) ( (c, r) => SEQ(CHAR(c), r) ) +def charlist2rexp(s : List[Char]) : Rexp = s match { + case Nil => EMPTY + case c::Nil => CHAR(c) + case c::s => SEQ(CHAR(c), charlist2rexp(s)) } +implicit def string2rexp(s : String) : Rexp = charlist2rexp(s.toList) + // for example println(STAR("abc")) @@ -99,3 +103,4 @@ println(matcher("cab" ,"cab")) println(matcher(STAR("a"),"aaa")) +