progs/re0.scala
changeset 499 dfd0f41f8668
parent 490 4fee50f38305
equal deleted inserted replaced
498:ea47c3b8f35f 499:dfd0f41f8668
    15 case class REP(r: Rexp, n: Int) extends Rexp 
    15 case class REP(r: Rexp, n: Int) extends Rexp 
    16 
    16 
    17 // some convenience for typing in regular expressions
    17 // some convenience for typing in regular expressions
    18 implicit def string2rexp(s : String) : Rexp = STR(s)
    18 implicit def string2rexp(s : String) : Rexp = STR(s)
    19 
    19 
    20 implicit def RexpOps(r: Rexp) = new {
    20 implicit def RexpOps(r: Rexp) : Rexp = new {
    21   def | (s: Rexp) = ALT(r, s)
    21   def | (s: Rexp) = ALT(r, s)
    22   def % = STAR(r)
    22   def % = STAR(r)
    23   def %(n: Int) = REP(r, n) 
    23   def %(n: Int) = REP(r, n) 
    24   def %%(n: Int) = SEQ(REP(r, n), STAR(r)) 
    24   def %%(n: Int) = SEQ(REP(r, n), STAR(r)) 
    25   def ? = ALT(EMPTY, r)
    25   def ? = ALT(EMPTY, r)
    26   def unary_! = NOT(r)
    26   def unary_! = NOT(r)
    27   def ~ (s: Rexp) = SEQ(r, s)
    27   def ~ (s: Rexp) = SEQ(r, s)
    28 }
    28 }
    29 
    29 
    30 implicit def stringOps(s: String) = new {
    30 implicit def stringOps(s: String) : Rexp = new {
    31   def | (r: Rexp) = ALT(s, r)
    31   def | (r: Rexp) = ALT(s, r)
    32   def | (r: String) = ALT(s, r)
    32   def | (r: String) = ALT(s, r)
    33   def % = STAR(s)
    33   def % = STAR(s)
    34   def %(n: Int) = REP(s, n)
    34   def %(n: Int) = REP(s, n)
    35   def %%(n: Int) = SEQ(REP(s, n), STAR(s)) 
    35   def %%(n: Int) = SEQ(REP(s, n), STAR(s))