Skip to content

Commit

Permalink
parser: fix single line comment end with newline (#7612)
Browse files Browse the repository at this point in the history
  • Loading branch information
lysu authored and ngaut committed Sep 5, 2018
1 parent 55ca851 commit a18d27e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 8 additions & 6 deletions parser/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,14 @@ func startWithSharp(s *Scanner) (tok int, pos Pos, lit string) {

func startWithDash(s *Scanner) (tok int, pos Pos, lit string) {
pos = s.r.pos()
if strings.HasPrefix(s.r.s[pos.Offset:], "-- ") {
s.r.incN(3)
s.r.incAsLongAs(func(ch rune) bool {
return ch != '\n'
})
return s.scan()
if strings.HasPrefix(s.r.s[pos.Offset:], "--") {
remainLen := len(s.r.s[pos.Offset:])
if remainLen == 2 || (remainLen > 2 && unicode.IsSpace(rune(s.r.s[pos.Offset+2]))) {
s.r.incAsLongAs(func(ch rune) bool {
return ch != '\n'
})
return s.scan()
}
}
if strings.HasPrefix(s.r.s[pos.Offset:], "->>") {
tok = juss
Expand Down
4 changes: 4 additions & 0 deletions parser/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ SELECT`, selectKwd},
SELECT`, selectKwd},
{"#comment\n123", intLit},
{"--5", int('-')},
{"--\nSELECT", selectKwd},
{"--\tSELECT", 0},
{"--\r\nSELECT", selectKwd},
{"--", 0},
}
runTest(c, table)
}
Expand Down

0 comments on commit a18d27e

Please sign in to comment.