diff --git a/parser/lexer.go b/parser/lexer.go index c82d3bbb574bb..70ff48c7fa368 100644 --- a/parser/lexer.go +++ b/parser/lexer.go @@ -335,16 +335,24 @@ func startWithSlash(s *Scanner) (tok int, pos Pos, lit string) { ch0 := s.r.peek() if ch0 == '*' { s.r.inc() + startWithAsterisk := false for { ch0 = s.r.readByte() + if startWithAsterisk && ch0 == '/' { + // Meets */, means comment end. + break + } else if ch0 == '*' { + startWithAsterisk = true + } else { + startWithAsterisk = false + } + if ch0 == unicode.ReplacementChar && s.r.eof() { // unclosed comment s.errs = append(s.errs, ParseErrorWith(s.r.data(&pos), s.r.p.Line)) return } - if ch0 == '*' && s.r.readByte() == '/' { - break - } + } comment := s.r.data(&pos) diff --git a/parser/parser_test.go b/parser/parser_test.go index a0548895ae859..ce06c0a8fa39f 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -462,6 +462,12 @@ func (s *testParserSuite) TestDMLStmt(c *C) { {`ANALYZE TABLE t`, true}, + // for comments + {`/** 20180417 **/ show databases;`, true}, + {`/* 20180417 **/ show databases;`, true}, + {`/** 20180417 */ show databases;`, true}, + {`/** 20180417 ******/ show databases;`, true}, + // for Binlog stmt {`BINLOG ' BxSFVw8JAAAA8QAAAPUAAAAAAAQANS41LjQ0LU1hcmlhREItbG9nAAAAAAAAAAAAAAAAAAAAAAAA