mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 00:55:55 +00:00
Merge pull request #1708 from molecula/sql-comment
CORE-860: Handle SQL comments during scan
This commit is contained in:
commit
14fdfe478b
2 changed files with 15 additions and 0 deletions
|
|
@ -104,6 +104,11 @@ func (s *Scanner) Scan() (pos Pos, token Token, lit string) {
|
|||
case '+':
|
||||
return pos, PLUS, "+"
|
||||
case '-':
|
||||
if s.peek() == '-' {
|
||||
s.read()
|
||||
s.skipComment()
|
||||
continue
|
||||
}
|
||||
return pos, MINUS, "-"
|
||||
case '*':
|
||||
return pos, STAR, "*"
|
||||
|
|
@ -117,6 +122,13 @@ func (s *Scanner) Scan() (pos Pos, token Token, lit string) {
|
|||
}
|
||||
}
|
||||
|
||||
// skipComment reads all characters until the end of the line or EOF.
|
||||
func (s *Scanner) skipComment() {
|
||||
for ch := s.peek(); ch != '\n' && ch != -1; ch = s.peek() {
|
||||
s.read()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Scanner) scanUnquotedIdent(pos Pos, prefix string) (Pos, Token, string) {
|
||||
assert(isUnquotedIdent(s.peek()))
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,9 @@ func TestScanner_Scan(t *testing.T) {
|
|||
t.Run("StartingX", func(t *testing.T) {
|
||||
AssertScan(t, `xyz`, sql.IDENT, `xyz`)
|
||||
})
|
||||
t.Run("WithComment", func(t *testing.T) {
|
||||
AssertScan(t, "-- this is a comment\n\n-- more comments\nfoo", sql.IDENT, `foo`)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("KEYWORD", func(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue