Skip to content

Commit 078ce71

Browse files
authored
Support identifiers starting with digits in lexer (#70)
1 parent f8d2efd commit 078ce71

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

lexer/lexer.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,22 @@ func (l *Lexer) readNumberOrIdent() Item {
766766
}
767767
}
768768

769+
// Check if directly followed by letter (identifier like 1alias1name1)
770+
// Exclude exponent (e/E followed by digit/+/-) and base prefixes (0x, 0b, 0o)
771+
if unicode.IsLetter(l.ch) {
772+
val := sb.String()
773+
isExponent := (l.ch == 'e' || l.ch == 'E') && (unicode.IsDigit(l.peekChar()) || l.peekChar() == '+' || l.peekChar() == '-')
774+
isBasePrefix := val == "0" && (l.ch == 'x' || l.ch == 'X' || l.ch == 'b' || l.ch == 'B' || l.ch == 'o' || l.ch == 'O')
775+
if !isExponent && !isBasePrefix {
776+
// This is an identifier that starts with digits (e.g., 1alias1name1)
777+
for isIdentChar(l.ch) {
778+
sb.WriteRune(l.ch)
779+
l.readChar()
780+
}
781+
return Item{Token: token.IDENT, Value: sb.String(), Pos: pos}
782+
}
783+
}
784+
769785
// Not an identifier, continue as number
770786
// But we already consumed the digits, so continue from here
771787
// Handle underscore separators in numbers (only if followed by a digit)
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt2": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)