Make Lex a private type: lex

This commit is contained in:
Miek Gieben 2011-12-16 19:34:30 +01:00
parent a03ef6df73
commit 3500e0f4aa
3 changed files with 28 additions and 28 deletions

View File

@ -94,7 +94,7 @@ func readPrivateKeyECDSA(m map[string]string) (PrivateKey, error) {
func ParseKey(r io.Reader) (map[string]string, error) { func ParseKey(r io.Reader) (map[string]string, error) {
var s scanner.Scanner var s scanner.Scanner
m := make(map[string]string) m := make(map[string]string)
c := make(chan Lex) c := make(chan lex)
k := "" k := ""
s.Init(r) s.Init(r)
s.Mode = 0 s.Mode = 0
@ -119,8 +119,8 @@ func ParseKey(r io.Reader) (map[string]string, error) {
} }
// klexer scans the sourcefile and returns tokens on the channel c. // klexer scans the sourcefile and returns tokens on the channel c.
func klexer(s scanner.Scanner, c chan Lex) { func klexer(s scanner.Scanner, c chan lex) {
var l Lex var l lex
str := "" // Hold the current read text str := "" // Hold the current read text
commt := false commt := false
key := true key := true

View File

@ -45,7 +45,7 @@ const (
type ParseError struct { type ParseError struct {
err string err string
lex Lex lex lex
} }
func (e *ParseError) Error() string { func (e *ParseError) Error() string {
@ -56,7 +56,7 @@ func (e *ParseError) Error() string {
return s return s
} }
type Lex struct { type lex struct {
token string // text of the token token string // text of the token
value int // value: _STRING, _BLANK, etc. value int // value: _STRING, _BLANK, etc.
line int // line in the file line int // line in the file
@ -94,7 +94,7 @@ func NewRR(s string) (RR, error) {
func ParseZone(r io.Reader, t chan Token) { func ParseZone(r io.Reader, t chan Token) {
defer close(t) defer close(t)
var s scanner.Scanner var s scanner.Scanner
c := make(chan Lex) c := make(chan lex)
s.Init(r) s.Init(r)
s.Mode = 0 s.Mode = 0
s.Whitespace = 0 s.Whitespace = 0
@ -222,8 +222,8 @@ func ParseZone(r io.Reader, t chan Token) {
// I could save my token here...? l // I could save my token here...? l
r, e := setRR(h, c) r, e := setRR(h, c)
if e != nil { if e != nil {
// If e.Lex is nil than we have encounter a unknown RR type // If e.lex is nil than we have encounter a unknown RR type
// in that case we substitute our current Lex token // in that case we substitute our current lex token
if e.lex.token == "" && e.lex.value == 0 { if e.lex.token == "" && e.lex.value == 0 {
e.lex = l // Uh, dirty e.lex = l // Uh, dirty
} }
@ -236,7 +236,7 @@ func ParseZone(r io.Reader, t chan Token) {
} }
} }
func (l Lex) String() string { func (l lex) String() string {
switch l.value { switch l.value {
case _STRING: case _STRING:
return l.token return l.token
@ -255,8 +255,8 @@ func (l Lex) String() string {
} }
// zlexer scans the sourcefile and returns tokens on the channel c. // zlexer scans the sourcefile and returns tokens on the channel c.
func zlexer(s scanner.Scanner, c chan Lex) { func zlexer(s scanner.Scanner, c chan lex) {
var l Lex var l lex
str := "" // Hold the current read text str := "" // Hold the current read text
quote := false quote := false
space := false space := false

View File

@ -13,7 +13,7 @@ import (
// or immediately a _NEWLINE. If this is not the case we flag // or immediately a _NEWLINE. If this is not the case we flag
// an *ParseError: garbage after rdata. // an *ParseError: garbage after rdata.
func setRR(h RR_Header, c chan Lex) (RR, *ParseError) { func setRR(h RR_Header, c chan lex) (RR, *ParseError) {
var r RR var r RR
e := new(ParseError) e := new(ParseError)
switch h.Rrtype { switch h.Rrtype {
@ -92,12 +92,12 @@ func setRR(h RR_Header, c chan Lex) (RR, *ParseError) {
default: default:
// Don't the have the token the holds the RRtype, but we substitute that in the // Don't the have the token the holds the RRtype, but we substitute that in the
// calling function when lex is empty. // calling function when lex is empty.
return nil, &ParseError{"Unknown RR type", Lex{}} return nil, &ParseError{"Unknown RR type", lex{}}
} }
return r, e return r, e
} }
func slurpRemainder(c chan Lex) *ParseError { func slurpRemainder(c chan lex) *ParseError {
l := <-c l := <-c
if _DEBUG { if _DEBUG {
fmt.Printf("%v\n", l) fmt.Printf("%v\n", l)
@ -122,7 +122,7 @@ func slurpRemainder(c chan Lex) *ParseError {
return nil return nil
} }
func setA(h RR_Header, c chan Lex) (RR, *ParseError) { func setA(h RR_Header, c chan lex) (RR, *ParseError) {
rr := new(RR_A) rr := new(RR_A)
rr.Hdr = h rr.Hdr = h
@ -134,7 +134,7 @@ func setA(h RR_Header, c chan Lex) (RR, *ParseError) {
return rr, nil return rr, nil
} }
func setAAAA(h RR_Header, c chan Lex) (RR, *ParseError) { func setAAAA(h RR_Header, c chan lex) (RR, *ParseError) {
rr := new(RR_AAAA) rr := new(RR_AAAA)
rr.Hdr = h rr.Hdr = h
@ -146,7 +146,7 @@ func setAAAA(h RR_Header, c chan Lex) (RR, *ParseError) {
return rr, nil return rr, nil
} }
func setNS(h RR_Header, c chan Lex) (RR, *ParseError) { func setNS(h RR_Header, c chan lex) (RR, *ParseError) {
rr := new(RR_NS) rr := new(RR_NS)
rr.Hdr = h rr.Hdr = h
@ -158,7 +158,7 @@ func setNS(h RR_Header, c chan Lex) (RR, *ParseError) {
return rr, nil return rr, nil
} }
func setMX(h RR_Header, c chan Lex) (RR, *ParseError) { func setMX(h RR_Header, c chan lex) (RR, *ParseError) {
rr := new(RR_MX) rr := new(RR_MX)
rr.Hdr = h rr.Hdr = h
@ -177,7 +177,7 @@ func setMX(h RR_Header, c chan Lex) (RR, *ParseError) {
return rr, nil return rr, nil
} }
func setCNAME(h RR_Header, c chan Lex) (RR, *ParseError) { func setCNAME(h RR_Header, c chan lex) (RR, *ParseError) {
rr := new(RR_CNAME) rr := new(RR_CNAME)
rr.Hdr = h rr.Hdr = h
@ -189,7 +189,7 @@ func setCNAME(h RR_Header, c chan Lex) (RR, *ParseError) {
return rr, nil return rr, nil
} }
func setSOA(h RR_Header, c chan Lex) (RR, *ParseError) { func setSOA(h RR_Header, c chan lex) (RR, *ParseError) {
rr := new(RR_SOA) rr := new(RR_SOA)
rr.Hdr = h rr.Hdr = h
@ -234,7 +234,7 @@ func setSOA(h RR_Header, c chan Lex) (RR, *ParseError) {
return rr, nil return rr, nil
} }
func setRRSIG(h RR_Header, c chan Lex) (RR, *ParseError) { func setRRSIG(h RR_Header, c chan lex) (RR, *ParseError) {
rr := new(RR_RRSIG) rr := new(RR_RRSIG)
rr.Hdr = h rr.Hdr = h
l := <-c l := <-c
@ -310,7 +310,7 @@ func setRRSIG(h RR_Header, c chan Lex) (RR, *ParseError) {
return rr, nil return rr, nil
} }
func setNSEC(h RR_Header, c chan Lex) (RR, *ParseError) { func setNSEC(h RR_Header, c chan lex) (RR, *ParseError) {
rr := new(RR_NSEC) rr := new(RR_NSEC)
rr.Hdr = h rr.Hdr = h
@ -341,7 +341,7 @@ func setNSEC(h RR_Header, c chan Lex) (RR, *ParseError) {
return rr, nil return rr, nil
} }
func setNSEC3(h RR_Header, c chan Lex) (RR, *ParseError) { func setNSEC3(h RR_Header, c chan lex) (RR, *ParseError) {
rr := new(RR_NSEC3) rr := new(RR_NSEC3)
rr.Hdr = h rr.Hdr = h
@ -396,7 +396,7 @@ func setNSEC3(h RR_Header, c chan Lex) (RR, *ParseError) {
} }
/* /*
func setNSEC3PARAM(h RR_Header, c chan Lex) (RR, *ParseError) { func setNSEC3PARAM(h RR_Header, c chan lex) (RR, *ParseError) {
rr := new(RR_NSEC3PARAM) rr := new(RR_NSEC3PARAM)
rr.Hdr = h rr.Hdr = h
l := <-c l := <-c
@ -421,7 +421,7 @@ func setNSEC3PARAM(h RR_Header, c chan Lex) (RR, *ParseError) {
} }
*/ */
func setSSHFP(h RR_Header, c chan Lex) (RR, *ParseError) { func setSSHFP(h RR_Header, c chan lex) (RR, *ParseError) {
rr := new(RR_SSHFP) rr := new(RR_SSHFP)
rr.Hdr = h rr.Hdr = h
@ -444,7 +444,7 @@ func setSSHFP(h RR_Header, c chan Lex) (RR, *ParseError) {
return rr, nil return rr, nil
} }
func setDNSKEY(h RR_Header, c chan Lex) (RR, *ParseError) { func setDNSKEY(h RR_Header, c chan lex) (RR, *ParseError) {
rr := new(RR_DNSKEY) rr := new(RR_DNSKEY)
rr.Hdr = h rr.Hdr = h
@ -486,7 +486,7 @@ func setDNSKEY(h RR_Header, c chan Lex) (RR, *ParseError) {
} }
// DLV and TA are the same // DLV and TA are the same
func setDS(h RR_Header, c chan Lex) (RR, *ParseError) { func setDS(h RR_Header, c chan lex) (RR, *ParseError) {
rr := new(RR_DS) rr := new(RR_DS)
rr.Hdr = h rr.Hdr = h
l := <-c l := <-c
@ -527,7 +527,7 @@ func setDS(h RR_Header, c chan Lex) (RR, *ParseError) {
return rr, nil return rr, nil
} }
func setTXT(h RR_Header, c chan Lex) (RR, *ParseError) { func setTXT(h RR_Header, c chan lex) (RR, *ParseError) {
rr := new(RR_TXT) rr := new(RR_TXT)
rr.Hdr = h rr.Hdr = h