--- a/progs/lexer/lexer.sc Tue Oct 27 13:46:01 2020 +0000
+++ b/progs/lexer/lexer.sc Tue Oct 27 13:51:34 2020 +0000
@@ -6,6 +6,7 @@
// amm lexer.sc small
// amm lexer.sc fib
// amm lexer.sc loops
+// amm lexer.sc email
//
// amm lexer.sc all
@@ -298,27 +299,30 @@
println(escape(lexing_simp(WHILE_REGS, prog3)).mkString("\n"))
}
+@doc("Email Test")
+@main
+def email() = {
+ val lower = "abcdefghijklmnopqrstuvwxyz"
+ val NAME = RECD("name", PLUS(RANGE(lower ++ "_.-")))
+ val DOMAIN = RECD("domain", PLUS(RANGE(lower ++ "-")))
+ val RE = RANGE(lower ++ ".")
+ val TOPLEVEL = RECD("top", (RE ~ RE) |
+ (RE ~ RE ~ RE) |
+ (RE ~ RE ~ RE ~ RE) |
+ (RE ~ RE ~ RE ~ RE ~ RE) |
+ (RE ~ RE ~ RE ~ RE ~ RE ~ RE))
+
+ val EMAIL = NAME ~ "@" ~ DOMAIN ~ "." ~ TOPLEVEL
+
+ println(lexing_simp(EMAIL, "christian.urban@kcl.ac.uk"))
+}
@doc("All tests.")
@main
-def all() = { small(); fib() ; loops() }
+def all() = { small(); fib() ; loops() ; email() }
-val SYM1 = RANGE("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz_.-")
-val NAME = RECD("name", PLUS(SYM1))
-
-val SYM2 = RANGE("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-")
-val DOMAIN = RECD("domain", PLUS(SYM2))
-val RE = RANGE("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz.")
-val TOPLEVEL = RECD("tl", (RE ~ RE) |
- (RE ~ RE ~ RE) |
- (RE ~ RE ~ RE ~ RE) |
- (RE ~ RE ~ RE ~ RE ~ RE) |
- (RE ~ RE ~ RE ~ RE ~ RE ~ RE))
-val EMAIL = NAME ~ "@" ~ DOMAIN ~ "." ~ TOPLEVEL
-
-println(lexing_simp(EMAIL, "christian.urban@kcl.ac.uk"))