Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser: fix single line comment end with newline error #7612

Merged
merged 1 commit into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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