author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Mon, 19 Nov 2012 14:18:42 +0000 | |
changeset 64 | 2d625418c011 |
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"))