Skip to content

Commit

Permalink
Fix Lexer Peek Bounding
Browse files Browse the repository at this point in the history
Fixed an issue with lexer.peek() method that caused an unexpected panic caused from not checking for the condition that lex cursor is at the penultimate symbol
  • Loading branch information
manishmeganathan committed Apr 18, 2023
1 parent 94c785b commit e6f2aa1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func (lexer *lexer) char() rune {
// This look ahead is performed without moving the Lexer's cursor.
// If the Lexer tap is exhausted, an EoF rune is returned.
func (lexer *lexer) peek() rune {
if lexer.done() {
// If lexer is done or cannot peek, return EoF
if lexer.done() || lexer.cursor+1 == len(lexer.symbols) {
return rune(TokenEoF)
}

Expand Down

0 comments on commit e6f2aa1

Please sign in to comment.