Skip to content

Commit 06f016f

Browse files
committed
Add hex and binary string literal support in lexer
- Support x'...' and X'...' hex string literals - Support b'...' and B'...' binary string literals - These are converted to regular string tokens Test count: 5549 -> 5550 (+1 test)
1 parent 151dbbd commit 06f016f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lexer/lexer.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,18 @@ func (l *Lexer) readIdentifier() Item {
432432
pos := l.pos
433433
var sb strings.Builder
434434

435+
// Check for hex string literal: x'...' or X'...'
436+
if (l.ch == 'x' || l.ch == 'X') && l.peekChar() == '\'' {
437+
l.readChar() // skip x
438+
return l.readString('\'') // read as regular string
439+
}
440+
441+
// Check for binary string literal: b'...' or B'...'
442+
if (l.ch == 'b' || l.ch == 'B') && l.peekChar() == '\'' {
443+
l.readChar() // skip b
444+
return l.readString('\'') // read as regular string
445+
}
446+
435447
for isIdentChar(l.ch) {
436448
sb.WriteRune(l.ch)
437449
l.readChar()

0 commit comments

Comments
 (0)