progs/lexer/lexer.sc
changeset 793 46cc69622a56
parent 792 34132a854d03
child 800 9eea6a801e10
equal deleted inserted replaced
792:34132a854d03 793:46cc69622a56
     4 // Call the test cases with 
     4 // Call the test cases with 
     5 //
     5 //
     6 //   amm lexer.sc small
     6 //   amm lexer.sc small
     7 //   amm lexer.sc fib
     7 //   amm lexer.sc fib
     8 //   amm lexer.sc loops
     8 //   amm lexer.sc loops
       
     9 //   amm lexer.sc email
     9 //
    10 //
    10 //   amm lexer.sc all
    11 //   amm lexer.sc all
    11 
    12 
    12 
    13 
    13 // regular expressions including records
    14 // regular expressions including records
   296 def loops() = {
   297 def loops() = {
   297   println("lexing Loops")
   298   println("lexing Loops")
   298   println(escape(lexing_simp(WHILE_REGS, prog3)).mkString("\n"))
   299   println(escape(lexing_simp(WHILE_REGS, prog3)).mkString("\n"))
   299 }
   300 }
   300 
   301 
   301 
   302 @doc("Email Test")
       
   303 @main
       
   304 def email() = {
       
   305   val lower = "abcdefghijklmnopqrstuvwxyz"
       
   306 
       
   307   val NAME = RECD("name", PLUS(RANGE(lower ++ "_.-")))
       
   308   val DOMAIN = RECD("domain", PLUS(RANGE(lower ++ "-")))
       
   309   val RE = RANGE(lower ++ ".")
       
   310   val TOPLEVEL = RECD("top", (RE ~ RE) |
       
   311                              (RE ~ RE ~ RE) | 
       
   312                              (RE ~ RE ~ RE ~ RE) | 
       
   313                              (RE ~ RE ~ RE ~ RE ~ RE) |
       
   314                              (RE ~ RE ~ RE ~ RE ~ RE ~ RE))
       
   315 
       
   316   val EMAIL = NAME ~ "@" ~ DOMAIN ~ "." ~ TOPLEVEL
       
   317 
       
   318   println(lexing_simp(EMAIL, "christian.urban@kcl.ac.uk"))
       
   319 }
   302 
   320 
   303 
   321 
   304 @doc("All tests.")
   322 @doc("All tests.")
   305 @main
   323 @main
   306 def all() = { small(); fib() ; loops() } 
   324 def all() = { small(); fib() ; loops() ; email() } 
   307 
   325 
   308 
   326 
   309 val SYM1 = RANGE("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz_.-")
   327 
   310 val NAME = RECD("name", PLUS(SYM1))
   328 
   311 
       
   312 val SYM2 = RANGE("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-")
       
   313 val DOMAIN = RECD("domain", PLUS(SYM2))
       
   314 
       
   315 val RE = RANGE("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz.")
       
   316 val TOPLEVEL = RECD("tl", (RE ~ RE) |
       
   317                           (RE ~ RE ~ RE) | 
       
   318                           (RE ~ RE ~ RE ~ RE) | 
       
   319                           (RE ~ RE ~ RE ~ RE ~ RE) |
       
   320                           (RE ~ RE ~ RE ~ RE ~ RE ~ RE))
       
   321 
       
   322 val EMAIL = NAME ~ "@" ~ DOMAIN ~ "." ~ TOPLEVEL
       
   323 
       
   324 println(lexing_simp(EMAIL, "christian.urban@kcl.ac.uk"))