From 915d1c8c92c01c118dc469b0a05467cf9b9c7ced Mon Sep 17 00:00:00 2001 From: winkyao Date: Mon, 18 Jun 2018 15:02:36 +0800 Subject: [PATCH] parser: allow comments end with multi asterisk (#6847) --- parser/lexer.go | 14 +++++++++++--- parser/parser_test.go | 6 ++++++ 2 files changed, 17 insertions(+), 3 deletions(-) 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