more parser updates

This commit is contained in:
Miek Gieben 2011-07-11 21:44:07 +02:00
parent 8c477c5c60
commit afa896ff14
1 changed files with 29 additions and 6 deletions

35
dns.l
View File

@ -1,6 +1,8 @@
package main package main
import "fmt"
import "fmt" var debug = true
var lastOwner = string
CHAR [A-Za-z0-9/+=a.{}] CHAR [A-Za-z0-9/+=a.{}]
BLANK [ \t] BLANK [ \t]
@ -18,25 +20,34 @@ BLANK [ \t]
BEGIN(INITIAL) BEGIN(INITIAL)
} }
<INITIAL>^{CHAR}+ { <INITIAL>^{CHAR}+ {
YOUT("qname") YOUT("qname")
yylval = yytext
lastOwner = yylval
BEGIN(classttl) BEGIN(classttl)
return QNAME
} }
<INITIAL>^{BLANK}+ { <INITIAL>^{BLANK}+ {
YOUT("qname.") YOUT("qname.")
// Return qname TOK, and fix yytext // Return qname TOK, and fix yytext
yylval = lastOwner
BEGIN(classttl) BEGIN(classttl)
return QNAME
} }
<classttl>{CHAR}+ { <classttl>{CHAR}+ {
yylval = yytext
switch yycheckit(yytext) { switch yycheckit(yytext) {
case 0: case 0:
YOUT("{qtype:" + yytext + "}") YOUT("{qtype:" + yytext + "}")
BEGIN(rest) BEGIN(rest)
return QTYPE
case 1: case 1:
YOUT("qclass") YOUT("qclass")
return QCLASS
case 2: case 2:
YOUT("ttl") YOUT("ttl")
return TTL
} }
} }
<classttl>{BLANK}+ { <classttl>{BLANK}+ {
@ -45,6 +56,8 @@ BLANK [ \t]
<rest>{CHAR}+ { <rest>{CHAR}+ {
YOUT("str") YOUT("str")
yylval = yytext
return STR
} }
<rest>{BLANK}+ { <rest>{BLANK}+ {
YOUT(".") YOUT(".")
@ -52,6 +65,7 @@ BLANK [ \t]
<rest>\n { <rest>\n {
YOUT("NL\n") YOUT("NL\n")
BEGIN(INITIAL) BEGIN(INITIAL)
return NL
} }
%% %%
@ -68,9 +82,18 @@ func yycheckit(s string) int {
func YOUT(s string) { func YOUT(s string) {
fmt.Printf("%s", s) if debug {
fmt.Printf("%s", s)
}
} }
func main() { type yyLex int
yylex()
func (yyLex) Lex(yylval *yySymType) int {
yylex()
return 0
}
func (yyLex) Error(s string) {
println(s)
} }