Skip to content

Commit

Permalink
parser: fix .1_t_1_x parsed as .1 _t_1_x (pingcap#2210)
Browse files Browse the repository at this point in the history
it should not be parsed as a .1(float) and _t_1_x(identifier)
instead, it should be .(dot) 1_t_1_x(identifier)
  • Loading branch information
tiancaiamao authored and coocood committed Dec 9, 2016
1 parent 1e8d970 commit 5917a78
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion parser/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,14 @@ func startWithNumber(s *Scanner) (tok int, pos Pos, lit string) {
func startWithDot(s *Scanner) (tok int, pos Pos, lit string) {
pos = s.r.pos()
s.r.inc()
save := s.r.pos()
if isDigit(s.r.peek()) {
return s.scanFloat(&pos)
tok, _, lit = s.scanFloat(&pos)
if s.r.eof() || unicode.IsSpace(s.r.peek()) {
return
}
// Fail to parse a float, reset to dot.
s.r.p = save
}
tok, lit = int('.'), "."
return
Expand Down
1 change: 1 addition & 0 deletions parser/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (s *testLexerSuite) TestLiteral(c *C) {
{fmt.Sprintf("%c", 0), invalid},
{fmt.Sprintf("t1%c", 0), identifier},
{".*", int('.')},
{".1_t_1_x", int('.')},
}
runTest(c, table)
}
Expand Down
1 change: 1 addition & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ func (s *testParserSuite) TestDBAStmt(c *C) {
{`SHOW GRANTS`, true},
{`SHOW GRANTS FOR 'test'@'localhost'`, true},
{`SHOW COLUMNS FROM City;`, true},
{`SHOW COLUMNS FROM tv189.1_t_1_x;`, true},
{`SHOW FIELDS FROM City;`, true},
{`SHOW TRIGGERS LIKE 't'`, true},
{`SHOW DATABASES LIKE 'test2'`, true},
Expand Down

0 comments on commit 5917a78

Please sign in to comment.