progs/lexer/lex.sc
changeset 959 64ec1884d860
parent 948 6bb67c2dcfd3
equal deleted inserted replaced
958:fddf099a82f8 959:64ec1884d860
    33 def charlist2rexp(s : List[Char]): Rexp = s match {
    33 def charlist2rexp(s : List[Char]): Rexp = s match {
    34   case Nil => ONE
    34   case Nil => ONE
    35   case c::Nil => CHAR(c)
    35   case c::Nil => CHAR(c)
    36   case c::s => SEQ(CHAR(c), charlist2rexp(s))
    36   case c::s => SEQ(CHAR(c), charlist2rexp(s))
    37 }
    37 }
    38 implicit def string2rexp(s : String) : Rexp = 
    38 
    39   charlist2rexp(s.toList)
    39 given Conversion[String, Rexp] = (s => charlist2rexp(s.toList))
    40 
    40 
    41 val HELLO : Rexp = "hello"
    41 val HELLO : Rexp = "hello"
    42 
    42 
    43 extension (r: Rexp) {
    43 extension (r: Rexp) {
    44   def | (s: Rexp) = ALT(r, s)
    44   def | (s: Rexp) = ALT(r, s)
   179                   ("w" & WHITESPACE)).%
   179                   ("w" & WHITESPACE)).%
   180 
   180 
   181 // Two Simple While Tests
   181 // Two Simple While Tests
   182 //========================
   182 //========================
   183 
   183 
   184 @arg(doc = "small tests")
   184 //@arg(doc = "small tests")
   185 @main
   185 @main
   186 def small() = {
   186 def small() = {
   187 
   187 
   188   val prog0 = """if"""
   188   val prog0 = """if"""
   189   println(s"test: $prog0")
   189   println(s"test: $prog0")