progs/re-sulzmann.scala
changeset 95 dbe49327b6c5
parent 94 9ea667baf097
--- a/progs/re-sulzmann.scala	Wed Aug 07 17:31:42 2013 +0100
+++ b/progs/re-sulzmann.scala	Tue Sep 24 01:12:36 2013 +0100
@@ -43,7 +43,7 @@
   case STAR(r) => SEQ(der(c, r), STAR(r))
 }
 
-def down(p: Pat) : Rexp = p match {
+def down (p: Pat) : Rexp = p match {
   case VAR(x: String, w: String, r: Rexp) => r
   case GRP(x: String, w: String, p: Pat) => down(p)
   case PSEQ(p1: Pat, p2: Pat) => SEQ(down(p1), down(p2))
@@ -51,7 +51,7 @@
   case PSTAR(p: Pat) => STAR(down(p))
 }
 
-def empty(p: Pat) : Pat = p match {
+def empty (p: Pat) : Pat = p match {
   case VAR(x: String, w: String, r: Rexp) => 
     if (nullable(r)) VAR(x, w, EMPTY) 
     else VAR(x, w, NULL)
@@ -61,7 +61,7 @@
   case PSTAR(p: Pat) => PSTAR(empty(p))
 }
 
-def patder(c: Char, p: Pat) : Pat = p match {
+def patder (c: Char, p: Pat) : Pat = p match {
   case VAR(x: String, w: String, r: Rexp) => VAR(x, w + c, der(c, r))
   case GRP(x: String, w: String, p: Pat) => GRP(x, w + c, patder(c, p))
   case PSEQ(p1: Pat, p2: Pat) => 
@@ -78,11 +78,10 @@
 
 type Env = Set[List[(String, String)]]
 
-def special(p: Pat, env: Env) : Env = 
+def special (p: Pat, env: Env) : Env = 
   if (env == Set() && nullable(down(p))) Set(Nil) else env
 
-
-def env(p: Pat) : Env = p match {
+def env (p: Pat) : Env = p match {
   case VAR(x: String, w: String, r: Rexp) => 
     if (nullable(r)) Set(List((x, w))) else Set()
   case GRP(x: String, w: String, p1: Pat) => 
@@ -93,24 +92,24 @@
   case PSTAR(p1: Pat) => special(p, env(p1))
 }
 
-def matcher(p: Pat, s: String) = env(empty(patders(s.toList, p)))
+def matcher (p: Pat, s: String) = env(empty(patders(s.toList, p)))
 
 
 // some convenience for typing in regular expressions
-def charlist2rexp(s : List[Char]) : Rexp = s match {
+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)
+implicit def string2rexp (s : String) : Rexp = charlist2rexp(s.toList)
 
-implicit def RexpOps(r: Rexp) = new {
+implicit def RexpOps (r: Rexp) = new {
   def | (s: Rexp) = ALT(r, s)
   def % = STAR(r)
   def ~ (s: Rexp) = SEQ(r, s)
 }
 
-implicit def stringOps(s: String) = new {
+implicit def stringOps (s: String) = new {
   def | (r: Rexp) = ALT(s, r)
   def | (r: String) = ALT(s, r)
   def % = STAR(s)
@@ -118,7 +117,7 @@
   def ~ (r: String) = SEQ(s, r)
 }
 
-implicit def PatOps(p: Pat) = new {
+implicit def PatOps (p: Pat) = new {
   def | (q: Pat) = PALT(p, q)
   def % = PSTAR(p)
   def ~ (q: Pat) = PSEQ(p, q)
@@ -162,3 +161,4 @@
 
 val p7 = (VAR("x", "A") | VAR("y", "AB") | VAR("z", "B")).%
 matcher(p7, "AB")
+