This parses stuff

This commit is contained in:
Miek Gieben 2011-07-11 16:17:53 +02:00
parent 82ff70262b
commit 8c477c5c60
1 changed files with 51 additions and 35 deletions

86
dns.l
View File

@ -1,55 +1,71 @@
package main package main
import "fmt" import "fmt"
CHAR [A-Za-z0-9/+=a.{}] 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}+ { <INITIAL>^{CHAR}+ {
YOUT("qname") YOUT("qname")
BEGIN(qclass) BEGIN(classttl)
} }
WS YOUT(" ") <INITIAL>^{BLANK}+ {
<qclass>WS YOUT(" ") YOUT("qname.")
<qtype>WS YOUT(" ") // Return qname TOK, and fix yytext
<rdata>WS YOUT(" ") BEGIN(classttl)
;.*\n {
YOUT("comment\n")
BEGIN(INITIAL)
} }
<qclass>;.*\n {
YOUT("comment\n") <classttl>{CHAR}+ {
BEGIN(INITIAL) switch yycheckit(yytext) {
case 0:
YOUT("{qtype:" + yytext + "}")
BEGIN(rest)
case 1:
YOUT("qclass")
case 2:
YOUT("ttl")
}
} }
<qtype>;.*\n { <classttl>{BLANK}+ {
YOUT("comment\n") YOUT(".")
BEGIN(INITIAL)
} }
<rdata>;.*\n {
YOUT("comment\n") <rest>{CHAR}+ {
YOUT("str")
}
<rest>{BLANK}+ {
YOUT(".")
}
<rest>\n {
YOUT("NL\n")
BEGIN(INITIAL) BEGIN(INITIAL)
} }
<qclass>{CHAR}+ {
YOUT("qclass/ttl")
BEGIN(qtype)
}
<qtype>{CHAR}+ {
YOUT("qtype")
BEGIN(rdata)
}
<rdata>{CHAR}+ {
YOUT("rdata")
}
<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) { func YOUT(s string) {
fmt.Printf("%s", s) fmt.Printf("%s", s)