From 95e5b3062da51cf588d010ddf402212b06f95fe1 Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 18 Oct 2024 19:31:46 -0400 Subject: [PATCH] Fix lexing bug --- dust-lang/src/lexer.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dust-lang/src/lexer.rs b/dust-lang/src/lexer.rs index a7f6ce4..7d027eb 100644 --- a/dust-lang/src/lexer.rs +++ b/dust-lang/src/lexer.rs @@ -36,13 +36,17 @@ pub fn lex<'tokens, 'src: 'tokens>( let mut lexer = Lexer::new(source); let mut tokens = Vec::new(); - while !lexer.is_eof() { + loop { let (token, span) = lexer .next_token() .map_err(|error| DustError::Lex { error, source })?; - let length = tokens.len(); + let is_eof = matches!(token, Token::Eof); - tokens[length] = (token, span); + tokens.push((token, span)); + + if is_eof { + break; + } } Ok(tokens)