author | Christian Urban <urbanc@in.tum.de> |
Wed, 14 Nov 2012 08:46:00 +0000 | |
changeset 63 | dff4b062a8a9 |
parent 7 | 73cf4406b773 |
child 66 | 9215b9fb8852 |
permissions | -rw-r--r-- |
def matches(r: Rexp, s: String) : Boolean = nullable(derivs(r, s.toList)) /* Examples */ println(matches(SEQ(SEQ(CHAR('c'), CHAR('a')), CHAR('b')),"cab")) println(matches(STAR(CHAR('a')),"aaa")) /* Convenience using implicits */ implicit def string2rexp(s : String) : Rexp = { s.foldRight (EMPTY: Rexp) ( (c, r) => SEQ(CHAR(c), r) ) } println(matches("cab" ,"cab")) println(matches(STAR("a"),"aaa")) println(matches(STAR("a"),"aaab"))