Skip to content

Commit 8d739ee

Browse files
Ajit Pratap SinghAjit Pratap Singh
authored andcommitted
fix: use token.SEMICOLON constant instead of string comparison
The parser was comparing token.Type (which is token.Type alias for string) with string literals "SEMICOLON" and checking non-existent Literal field. Fixed to use proper token.SEMICOLON constant for both Parse() and ParseContext(). This resolves the validation errors on SQL files with trailing semicolons.
1 parent 8b93d9c commit 8d739ee

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

pkg/sql/parser/parser.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ func (p *Parser) Parse(tokens []token.Token) (*ast.AST, error) {
6060
result.Statements = make([]ast.Statement, 0, estimatedStmts)
6161

6262
// Parse statements
63-
for p.currentPos < len(tokens) && p.currentToken.Type != "EOF" {
63+
for p.currentPos < len(tokens) && p.currentToken.Type != token.EOF {
6464
// Skip semicolons between statements
65-
if p.currentToken.Type == "SEMICOLON" || p.currentToken.Literal == ";" {
65+
if p.currentToken.Type == token.SEMICOLON {
6666
p.advance()
6767
continue
6868
}
@@ -76,7 +76,7 @@ func (p *Parser) Parse(tokens []token.Token) (*ast.AST, error) {
7676
result.Statements = append(result.Statements, stmt)
7777

7878
// Optionally consume semicolon after statement
79-
if p.currentToken.Type == "SEMICOLON" || p.currentToken.Literal == ";" {
79+
if p.currentToken.Type == token.SEMICOLON {
8080
p.advance()
8181
}
8282
}
@@ -134,7 +134,7 @@ func (p *Parser) ParseContext(ctx context.Context, tokens []token.Token) (*ast.A
134134
result.Statements = make([]ast.Statement, 0, estimatedStmts)
135135

136136
// Parse statements
137-
for p.currentPos < len(tokens) && p.currentToken.Type != "EOF" {
137+
for p.currentPos < len(tokens) && p.currentToken.Type != token.EOF {
138138
// Check context before each statement
139139
if err := ctx.Err(); err != nil {
140140
// Clean up the AST on error
@@ -143,7 +143,7 @@ func (p *Parser) ParseContext(ctx context.Context, tokens []token.Token) (*ast.A
143143
}
144144

145145
// Skip semicolons between statements
146-
if p.currentToken.Type == "SEMICOLON" || p.currentToken.Literal == ";" {
146+
if p.currentToken.Type == token.SEMICOLON {
147147
p.advance()
148148
continue
149149
}
@@ -157,7 +157,7 @@ func (p *Parser) ParseContext(ctx context.Context, tokens []token.Token) (*ast.A
157157
result.Statements = append(result.Statements, stmt)
158158

159159
// Optionally consume semicolon after statement
160-
if p.currentToken.Type == "SEMICOLON" || p.currentToken.Literal == ";" {
160+
if p.currentToken.Type == token.SEMICOLON {
161161
p.advance()
162162
}
163163
}

0 commit comments

Comments
 (0)