progs/scala/re-ext.scala
changeset 234 18d19d039ac9
parent 231 02fd56e2019e
child 235 f476c98cad28
--- a/progs/scala/re-ext.scala	Wed Mar 08 10:32:51 2017 +0000
+++ b/progs/scala/re-ext.scala	Sat Mar 11 12:50:01 2017 +0000
@@ -157,7 +157,8 @@
   case c::cs => inj(r, c, lex(der(c, r), cs))
 }
 
-def lexing(r: Rexp, s: String) : Val = lex(r, s.toList)
+import scala.util._
+def lexing(r: Rexp, s: String) : Try[Val] = Try(lex(r, s.toList))
 
 
 // some "rectification" functions for simplification
@@ -243,6 +244,18 @@
 println(lexing_simp((("" | "a") ~ ("c" | "ab")), "ab"))
 
 
+// Some more Tests
+//=================
+val ALL = CHARS((c) => true)
+val reg = ALL.% ~ "a" ~ NTIMES(ALL, 3) ~ "bc"
+
+println(lexing(reg, "axaybzbc"))     // true
+println(lexing(reg, "aaaaxaybzbc"))  // true
+println(nullable(ders("axaybzbd".toList, reg)))     // false
+println(lexing(reg, "axaybzbd"))     // false
+
+
+
 
 // Two Simple Tests for the While Language
 //========================================