equal
deleted
inserted
replaced
31 case class Right(v: Val) extends Val |
31 case class Right(v: Val) extends Val |
32 case class Stars(vs: List[Val]) extends Val |
32 case class Stars(vs: List[Val]) extends Val |
33 case class Rec(x: String, v: Val) extends Val |
33 case class Rec(x: String, v: Val) extends Val |
34 |
34 |
35 // some convenience for typing in regular expressions |
35 // some convenience for typing in regular expressions |
|
36 import scala.language.implicitConversions |
36 |
37 |
37 def charlist2rexp(s : List[Char]): Rexp = s match { |
38 def charlist2rexp(s : List[Char]): Rexp = s match { |
38 case Nil => ONE |
39 case Nil => ONE |
39 case c::Nil => CHAR(c) |
40 case c::Nil => CHAR(c) |
40 case c::s => SEQ(CHAR(c), charlist2rexp(s)) |
41 case c::s => SEQ(CHAR(c), charlist2rexp(s)) |
41 } |
42 } |
42 |
43 |
43 implicit def string2rexp(s : String) : Rexp = |
44 given Conversion[String, Rexp] = (s => charlist2rexp(s.toList)) |
44 charlist2rexp(s.toList) |
|
45 |
|
46 |
45 |
47 extension (s: String) { |
46 extension (s: String) { |
48 def $ (r: Rexp) = RECD(s, r) |
47 def $ (r: Rexp) = RECD(s, r) |
49 } |
48 } |
50 |
49 |
237 // Bigger Tests |
236 // Bigger Tests |
238 //============== |
237 //============== |
239 |
238 |
240 // escapes strings and prints them out as "", "\n" and so on |
239 // escapes strings and prints them out as "", "\n" and so on |
241 def esc(raw: String): String = { |
240 def esc(raw: String): String = { |
242 import scala.reflect.runtime.universe._ |
241 raw |
243 Literal(Constant(raw)).toString |
242 //import scala.reflect.runtime.universe._ |
|
243 //Literal(Constant(raw)).toString |
244 } |
244 } |
245 |
245 |
246 def escape(tks: List[(String, String)]) = |
246 def escape(tks: List[(String, String)]) = |
247 tks.map{ case (s1, s2) => (s1, esc(s2))} |
247 tks.map{ case (s1, s2) => (s1, esc(s2))} |
248 |
248 |