From 82ff70262b64f04db92f5ed105173a20b0daefa9 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Mon, 11 Jul 2011 11:44:35 +0200 Subject: [PATCH] start of a lexer for dns zone files --- dns.l | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 dns.l diff --git a/dns.l b/dns.l new file mode 100644 index 00000000..403aa3bd --- /dev/null +++ b/dns.l @@ -0,0 +1,60 @@ + package main + + import "fmt" + +CHAR [A-Za-z0-9/+=a.{}] +WS [ \t] + +%x qclass qtype rdata +%% + +^{CHAR}+ { + YOUT("qname") + BEGIN(qclass) + } +WS YOUT(" ") +WS YOUT(" ") +WS YOUT(" ") +WS YOUT(" ") +;.*\n { + YOUT("comment\n") + BEGIN(INITIAL) + } +;.*\n { + YOUT("comment\n") + BEGIN(INITIAL) + } +;.*\n { + YOUT("comment\n") + BEGIN(INITIAL) + } +;.*\n { + YOUT("comment\n") + BEGIN(INITIAL) + } + +{CHAR}+ { + YOUT("qclass/ttl") + BEGIN(qtype) + } +{CHAR}+ { + YOUT("qtype") + BEGIN(rdata) + } +{CHAR}+ { + YOUT("rdata") + } +\n { + YOUT("END\n\n") + BEGIN(INITIAL) + } +%% + + +func YOUT(s string) { + fmt.Printf("%s", s) +} + +func main() { + yylex() +}