Implement escaping
This commit is contained in:
parent
ec69d5aced
commit
1bd1784403
6
kscan.go
6
kscan.go
|
@ -166,4 +166,10 @@ func klexer(s scanner.Scanner, c chan lex) {
|
||||||
}
|
}
|
||||||
tok = s.Scan()
|
tok = s.Scan()
|
||||||
}
|
}
|
||||||
|
if len(str) > 0 {
|
||||||
|
// Send remainder
|
||||||
|
l.token = str
|
||||||
|
l.value = _VALUE
|
||||||
|
c <- l
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
62
zscan.go
62
zscan.go
|
@ -291,6 +291,7 @@ 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
|
||||||
|
escape := false
|
||||||
space := false
|
space := false
|
||||||
commt := false
|
commt := false
|
||||||
rrtype := false
|
rrtype := false
|
||||||
|
@ -303,6 +304,7 @@ func zlexer(s scanner.Scanner, c chan lex) {
|
||||||
l.line = s.Position.Line
|
l.line = s.Position.Line
|
||||||
switch x := s.TokenText(); x {
|
switch x := s.TokenText(); x {
|
||||||
case " ", "\t":
|
case " ", "\t":
|
||||||
|
escape = false
|
||||||
if commt {
|
if commt {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -313,12 +315,13 @@ func zlexer(s scanner.Scanner, c chan lex) {
|
||||||
// If we have a string and its the first, make it an owner
|
// If we have a string and its the first, make it an owner
|
||||||
l.value = _OWNER
|
l.value = _OWNER
|
||||||
l.token = str
|
l.token = str
|
||||||
if str == "$TTL" {
|
// escape $... start with a \ not a $, so this will work
|
||||||
l.value = _DIRTTL
|
if str == "$TTL" {
|
||||||
}
|
l.value = _DIRTTL
|
||||||
if str == "$ORIGIN" {
|
}
|
||||||
l.value = _DIRORIGIN
|
if str == "$ORIGIN" {
|
||||||
}
|
l.value = _DIRORIGIN
|
||||||
|
}
|
||||||
c <- l
|
c <- l
|
||||||
} else {
|
} else {
|
||||||
l.value = _STRING
|
l.value = _STRING
|
||||||
|
@ -344,6 +347,11 @@ func zlexer(s scanner.Scanner, c chan lex) {
|
||||||
owner = false
|
owner = false
|
||||||
space = true
|
space = true
|
||||||
case ";":
|
case ";":
|
||||||
|
if escape {
|
||||||
|
escape = false
|
||||||
|
str += ";"
|
||||||
|
break
|
||||||
|
}
|
||||||
if quote {
|
if quote {
|
||||||
// Inside quoted text we allow ;
|
// Inside quoted text we allow ;
|
||||||
str += ";"
|
str += ";"
|
||||||
|
@ -351,6 +359,8 @@ func zlexer(s scanner.Scanner, c chan lex) {
|
||||||
}
|
}
|
||||||
commt = true
|
commt = true
|
||||||
case "\n":
|
case "\n":
|
||||||
|
// Hmmm, escape newline
|
||||||
|
escape = false
|
||||||
if commt {
|
if commt {
|
||||||
// Reset a comment
|
// Reset a comment
|
||||||
commt = false
|
commt = false
|
||||||
|
@ -395,21 +405,46 @@ func zlexer(s scanner.Scanner, c chan lex) {
|
||||||
commt = false
|
commt = false
|
||||||
rrtype = false
|
rrtype = false
|
||||||
owner = true
|
owner = true
|
||||||
|
case "\\":
|
||||||
|
if commt {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if escape {
|
||||||
|
str += "\\"
|
||||||
|
escape = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
escape = true
|
||||||
case "\"":
|
case "\"":
|
||||||
if commt {
|
if commt {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
if escape {
|
||||||
|
str += "\""
|
||||||
|
escape = false
|
||||||
|
break
|
||||||
|
}
|
||||||
// str += "\"" don't add quoted quotes
|
// str += "\"" don't add quoted quotes
|
||||||
quote = !quote
|
quote = !quote
|
||||||
case "(":
|
case "(":
|
||||||
if commt {
|
if commt {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
if escape {
|
||||||
|
str += "("
|
||||||
|
escape = false
|
||||||
|
break
|
||||||
|
}
|
||||||
brace++
|
brace++
|
||||||
case ")":
|
case ")":
|
||||||
if commt {
|
if commt {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
if escape {
|
||||||
|
str += ")"
|
||||||
|
escape = false
|
||||||
|
break
|
||||||
|
}
|
||||||
brace--
|
brace--
|
||||||
if brace < 0 {
|
if brace < 0 {
|
||||||
l.err = "Extra closing brace"
|
l.err = "Extra closing brace"
|
||||||
|
@ -420,18 +455,19 @@ func zlexer(s scanner.Scanner, c chan lex) {
|
||||||
if commt {
|
if commt {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
escape = false
|
||||||
str += x
|
str += x
|
||||||
space = false
|
space = false
|
||||||
}
|
}
|
||||||
tok = s.Scan()
|
tok = s.Scan()
|
||||||
}
|
}
|
||||||
// Hmm.
|
// Hmm.
|
||||||
if len(str) > 0 {
|
if len(str) > 0 {
|
||||||
// Send remainder
|
// Send remainder
|
||||||
l.token = str
|
l.token = str
|
||||||
l.value = _STRING
|
l.value = _STRING
|
||||||
c <-l
|
c <- l
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func stringToTtl(l lex, t chan Token) (uint32, bool) {
|
func stringToTtl(l lex, t chan Token) (uint32, bool) {
|
||||||
|
|
Loading…
Reference in New Issue