diff --git a/dns.l b/dns.l index 403aa3bd..7b8e94bf 100644 --- a/dns.l +++ b/dns.l @@ -1,55 +1,71 @@ package main import "fmt" - + CHAR [A-Za-z0-9/+=a.{}] -WS [ \t] +BLANK [ \t] -%x qclass qtype rdata +%s classttl rest %% +<*>;.*\n { + // Comments aren't interesting + YOUT("NL\n") + BEGIN(INITIAL) + } +<*>%$ { + // Empty lines + YOUT("\n") + BEGIN(INITIAL) + } -^{CHAR}+ { +^{CHAR}+ { YOUT("qname") - BEGIN(qclass) + BEGIN(classttl) } -WS YOUT(" ") -WS YOUT(" ") -WS YOUT(" ") -WS YOUT(" ") -;.*\n { - YOUT("comment\n") - BEGIN(INITIAL) +^{BLANK}+ { + YOUT("qname.") + // Return qname TOK, and fix yytext + BEGIN(classttl) } -;.*\n { - YOUT("comment\n") - BEGIN(INITIAL) + +{CHAR}+ { + switch yycheckit(yytext) { + case 0: + YOUT("{qtype:" + yytext + "}") + BEGIN(rest) + case 1: + YOUT("qclass") + case 2: + YOUT("ttl") + } } -;.*\n { - YOUT("comment\n") - BEGIN(INITIAL) +{BLANK}+ { + YOUT(".") } -;.*\n { - YOUT("comment\n") + +{CHAR}+ { + YOUT("str") + } +{BLANK}+ { + YOUT(".") + } +\n { + YOUT("NL\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 yycheckit(s string) int { + if s == "IN" { + return 1 + } + if s[0] >= '0' && s[0] <= '9' { + return 2 + } + return 0 +} + func YOUT(s string) { fmt.Printf("%s", s)