Going to use Ragel (not lex/yacc)
This commit is contained in:
parent
1f974dd012
commit
31c9cf6548
98
dns.l
98
dns.l
|
@ -1,98 +0,0 @@
|
|||
package main
|
||||
import "fmt"
|
||||
|
||||
var debug = true
|
||||
var lastOwner string
|
||||
|
||||
CHAR [A-Za-z0-9/+=a.{}]
|
||||
BLANK [ \t]
|
||||
|
||||
%s classttl rest
|
||||
%%
|
||||
<*>;.*\n {
|
||||
// Comments aren't interesting
|
||||
YOUT("NL\n")
|
||||
BEGIN(INITIAL)
|
||||
}
|
||||
<*>%$ {
|
||||
// Empty lines
|
||||
YOUT("\n")
|
||||
BEGIN(INITIAL)
|
||||
}
|
||||
|
||||
<INITIAL>^{CHAR}+ {
|
||||
YOUT("qname")
|
||||
yylval.val = yytext
|
||||
lastOwner = yylval.val
|
||||
BEGIN(classttl)
|
||||
return QNAME
|
||||
}
|
||||
<INITIAL>^{BLANK}+ {
|
||||
YOUT("qname.")
|
||||
// Return qname TOK, and fix yytext
|
||||
yylval.val = lastOwner
|
||||
BEGIN(classttl)
|
||||
return QNAME
|
||||
}
|
||||
|
||||
<classttl>{CHAR}+ {
|
||||
yylval.val = yytext
|
||||
switch yycheckit(yytext) {
|
||||
case 0:
|
||||
YOUT("{qtype:" + yytext + "}")
|
||||
BEGIN(rest)
|
||||
return QTYPE
|
||||
case 1:
|
||||
YOUT("qclass")
|
||||
return QCLASS
|
||||
case 2:
|
||||
YOUT("ttl")
|
||||
return TTL
|
||||
}
|
||||
}
|
||||
<classttl>{BLANK}+ {
|
||||
YOUT(".")
|
||||
}
|
||||
|
||||
<rest>{CHAR}+ {
|
||||
YOUT("str")
|
||||
yylval.val = yytext
|
||||
return STR
|
||||
}
|
||||
<rest>{BLANK}+ {
|
||||
YOUT(".")
|
||||
}
|
||||
<rest>\n {
|
||||
YOUT("NL\n")
|
||||
BEGIN(INITIAL)
|
||||
return NL
|
||||
}
|
||||
|
||||
%%
|
||||
|
||||
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) {
|
||||
if debug {
|
||||
fmt.Printf("%s", s)
|
||||
}
|
||||
}
|
||||
|
||||
type yyLex int
|
||||
|
||||
func (yyLex) Lex(yylval *yySymType) int {
|
||||
return yylex()
|
||||
}
|
||||
|
||||
func (yyLex) Error(s string) {
|
||||
println(s)
|
||||
}
|
54
dns.y
54
dns.y
|
@ -1,54 +0,0 @@
|
|||
%{
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
var yylval *yySymType
|
||||
|
||||
%}
|
||||
|
||||
%union
|
||||
{
|
||||
val string;
|
||||
|
||||
}
|
||||
|
||||
|
||||
%type <val> rr rdata
|
||||
|
||||
%token <val> QNAME TTL QCLASS QTYPE STR NL
|
||||
|
||||
%%
|
||||
rr:
|
||||
QNAME TTL QCLASS QTYPE rdata
|
||||
{
|
||||
fmt.Fprintf(os.Stderr, "{%v}\n", $$)
|
||||
}
|
||||
| QNAME QCLASS TTL QTYPE rdata
|
||||
| QNAME TTL QTYPE rdata
|
||||
| QNAME QCLASS QTYPE rdata
|
||||
| QNAME QTYPE rdata
|
||||
{
|
||||
fmt.Fprintf(os.Stderr, "%v\n", $1)
|
||||
}
|
||||
|
||||
rdata:
|
||||
rdata STR
|
||||
| rdata NL
|
||||
| STR
|
||||
| NL
|
||||
{
|
||||
fmt.Fprintf(os.Stderr, "%v\n", $1)
|
||||
}
|
||||
|
||||
%%
|
||||
|
||||
func main() {
|
||||
yylval = new(yySymType)
|
||||
yyin = os.Stdin
|
||||
yyParse(yyLex(0))
|
||||
}
|
Loading…
Reference in New Issue