Skip to content

Commit 8bd61bf

Browse files
kyleconroyclaude
andcommitted
Fix TTL SET clause lookahead to use peekPeek instead of consuming tokens (#119)
When detecting SET continuation vs new TTL after comma, use peek/peekPeek to check the pattern (IDENT EQ) without consuming tokens. This avoids losing lexer state when restoring position. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 8790477 commit 8bd61bf

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

parser/parser.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8444,25 +8444,22 @@ func (p *Parser) parseTTLElement() *ast.TTLElement {
84448444
p.parseExpression(ALIAS_PREC)
84458445
// Check for comma
84468446
if p.currentIs(token.COMMA) {
8447-
// Look ahead to check pattern. We need to see: COMMA IDENT EQ
8448-
// Save state to peek ahead
8449-
savedCurrent := p.current
8450-
savedPeek := p.peek
8451-
p.nextToken() // skip comma to see what follows
8447+
// Check if this is a SET continuation (COMMA IDENT EQ pattern)
8448+
// We can check using peek (what follows comma) and peekPeek (what follows that)
8449+
// without consuming any tokens
84528450
isSetContinuation := false
8453-
if p.currentIs(token.IDENT) || p.current.Token.IsKeyword() {
8454-
if p.peekIs(token.EQ) {
8451+
if p.peekIs(token.IDENT) || p.peek.Token.IsKeyword() {
8452+
if p.peekPeekIs(token.EQ) {
84558453
// It's another SET assignment (id = expr)
84568454
isSetContinuation = true
84578455
}
84588456
}
84598457
if isSetContinuation {
8460-
// Continue parsing SET assignments (already consumed comma)
8458+
// Consume comma and continue parsing SET assignments
8459+
p.nextToken()
84618460
continue
84628461
}
8463-
// Not a SET assignment - restore state so caller sees the comma
8464-
p.current = savedCurrent
8465-
p.peek = savedPeek
8462+
// Not a SET assignment - break and let caller handle the comma
84668463
break
84678464
}
84688465
// No comma, end of SET clause
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt11": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)