- allow " for strings
- allow ` for identifiers
- allow @ for identifiers
This commit is contained in:
Sugu Sougoumarane 2012-05-29 14:24:43 -07:00
Родитель ba7248ed40
Коммит 1d55407ced
3 изменённых файлов: 23 добавлений и 7 удалений

Просмотреть файл

@ -213,8 +213,14 @@ func (self *Node) Format(buf *TrackedBuffer) {
if self.Len() != 0 {
Fprintf(buf, " on duplicate key update %v", self.At(0))
}
case NUMBER, NULL, ID, SELECT_STAR, NO_DISTINCT, COMMENT, FOR_UPDATE, NOT_FOR_UPDATE, TABLE:
case NUMBER, NULL, SELECT_STAR, NO_DISTINCT, COMMENT, FOR_UPDATE, NOT_FOR_UPDATE, TABLE:
Fprintf(buf, "%s", self.Value)
case ID:
if _, ok := keywords[string(self.Value)]; ok {
Fprintf(buf, "`%s`", self.Value)
} else {
Fprintf(buf, "%s", self.Value)
}
case VALUE_ARG:
buf.bind_locations = append(buf.bind_locations, BindLocation{buf.Len(), len(self.Value)})
Fprintf(buf, "%s", self.Value)

Просмотреть файл

@ -1,6 +1,9 @@
select 1 from t
select -1 from t where b = -2
select /* simplest */ 1 from t
select /* back-quote */ 1 from `t`#select /* back-quote */ 1 from t
select /* back-quote keyword */ 1 from `from`#select /* back-quote keyword */ 1 from `from`
select /* @ */ @@a from b
select 1 /* drop this comment */ from t#select 1 from t
select /* union */ 1 from t union select 1 from t
select /* union all */ 1 from t union all select 1 from t
@ -77,7 +80,10 @@ select /* function with distinct */ count(distinct a) from t
select /* a */ a from t
select /* a.b */ a.b from t
select /* string */ 'a' from t
select /* double quoted string */ "a" from t#select /* double quoted string */ 'a' from t
select /* quote quote in string */ 'a''a' from t#select /* quote quote in string */ 'a\'a' from t
select /* double quote quote in string */ "a""a" from t#select /* double quote quote in string */ 'a\"a' from t
select /* quote in double quoted string */ "a'a" from t#select /* quote in double quoted string */ 'a\'a' from t
select /* backslash quote in string */ 'a\'a' from t
select /* literal backslash in string */ 'a\\na' from t
select /* all escapes */ '\0\'\"\b\n\r\t\Z\\' from t

Просмотреть файл

@ -247,8 +247,12 @@ func (self *Tokenizer) Scan() (parseNode *Node) {
} else {
return NewSimpleParseNode(LEX_ERROR, "Unexpected character '!'")
}
case '\'':
return self.scanString()
case '\'', '"':
return self.scanString(ch)
case '`':
tok := self.scanString(ch)
tok.Type = ID
return tok
default:
return NewSimpleParseNode(LEX_ERROR, fmt.Sprintf("Unexpected character '%c'", ch))
}
@ -353,13 +357,13 @@ exit:
return NewParseNode(NUMBER, buffer.Bytes())
}
func (self *Tokenizer) scanString() *Node {
func (self *Tokenizer) scanString(delim uint16) *Node {
buffer := bytes.NewBuffer(make([]byte, 0, 8))
for {
ch := self.lastChar
self.Next()
if ch == '\'' {
if self.lastChar == '\'' {
if ch == delim {
if self.lastChar == delim {
self.Next()
} else {
break
@ -436,7 +440,7 @@ func (self *Tokenizer) Next() {
}
func isLetter(ch uint16) bool {
return 'a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch == '_'
return 'a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch == '_' || ch == '@'
}
func digitVal(ch uint16) int {