Skip to content

Commit 83ff599

Browse files
committed
Add COMMENT keyword for SQL COMMENT COLUMN clauses
Rename the special COMMENT token (for line comments like -- and /* */) to LINE_COMMENT to avoid collision with the COMMENT SQL keyword needed for ALTER TABLE COMMENT COLUMN and similar statements.
1 parent c890fba commit 83ff599

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

lexer/lexer.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ func (l *Lexer) readLineComment() Item {
306306
}
307307
// Strip trailing semicolon from comment - it's a statement terminator, not part of comment
308308
text := strings.TrimRight(sb.String(), ";")
309-
return Item{Token: token.COMMENT, Value: text, Pos: pos}
309+
return Item{Token: token.LINE_COMMENT, Value: text, Pos: pos}
310310
}
311311

312312
func (l *Lexer) readHashComment() Item {
@@ -322,7 +322,7 @@ func (l *Lexer) readHashComment() Item {
322322
}
323323
// Strip trailing semicolon from comment - it's a statement terminator, not part of comment
324324
text := strings.TrimRight(sb.String(), ";")
325-
return Item{Token: token.COMMENT, Value: text, Pos: pos}
325+
return Item{Token: token.LINE_COMMENT, Value: text, Pos: pos}
326326
}
327327

328328
// readUnicodeMinusComment reads from a unicode minus (U+2212) to the end of line or semicolon.
@@ -338,7 +338,7 @@ func (l *Lexer) readUnicodeMinusComment() Item {
338338
sb.WriteRune(l.ch)
339339
l.readChar()
340340
}
341-
return Item{Token: token.COMMENT, Value: sb.String(), Pos: pos}
341+
return Item{Token: token.LINE_COMMENT, Value: sb.String(), Pos: pos}
342342
}
343343

344344
func (l *Lexer) readBlockComment() Item {
@@ -371,7 +371,7 @@ func (l *Lexer) readBlockComment() Item {
371371
l.readChar()
372372
}
373373
}
374-
return Item{Token: token.COMMENT, Value: sb.String(), Pos: pos}
374+
return Item{Token: token.LINE_COMMENT, Value: sb.String(), Pos: pos}
375375
}
376376

377377
func (l *Lexer) readString(quote rune) Item {

parser/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (p *Parser) nextToken() {
3737
for {
3838
p.peek = p.lexer.NextToken()
3939
// Skip whitespace and comments
40-
if p.peek.Token == token.WHITESPACE || p.peek.Token == token.COMMENT {
40+
if p.peek.Token == token.WHITESPACE || p.peek.Token == token.LINE_COMMENT {
4141
continue
4242
}
4343
break

token/token.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const (
99
ILLEGAL Token = iota
1010
EOF
1111
WHITESPACE
12-
COMMENT
12+
LINE_COMMENT // SQL comments like -- and /* */
1313

1414
// Literals
1515
IDENT // identifiers
@@ -74,6 +74,7 @@ const (
7474
COLLATE
7575
COLUMN
7676
COLUMNS
77+
COMMENT
7778
COMMIT
7879
CONSTRAINT
7980
CREATE
@@ -208,7 +209,7 @@ var tokens = [...]string{
208209
ILLEGAL: "ILLEGAL",
209210
EOF: "EOF",
210211
WHITESPACE: "WHITESPACE",
211-
COMMENT: "COMMENT",
212+
LINE_COMMENT: "LINE_COMMENT",
212213

213214
IDENT: "IDENT",
214215
NUMBER: "NUMBER",
@@ -268,6 +269,7 @@ var tokens = [...]string{
268269
COLLATE: "COLLATE",
269270
COLUMN: "COLUMN",
270271
COLUMNS: "COLUMNS",
272+
COMMENT: "COMMENT",
271273
COMMIT: "COMMIT",
272274
CONSTRAINT: "CONSTRAINT",
273275
CREATE: "CREATE",

0 commit comments

Comments
 (0)