less lexer recursion

This commit is contained in:
minish 2025-06-28 18:15:21 -04:00
parent 586ddd1aec
commit 706f4b3763
Signed by: min
SSH Key Fingerprint: SHA256:h4k7JNrfe1dzv1WE3oGVeAY9DPSZXIu3/j89+6DtHWE
2 changed files with 67 additions and 65 deletions

View File

@ -227,15 +227,9 @@ where
} }
} }
fn lex_comment(&mut self) -> Option<Result<Token>> {
while self.peek() != Some('\n') {
self.eat();
}
self.lex()
}
fn lex(&mut self) -> Option<Result<Token>> { fn lex(&mut self) -> Option<Result<Token>> {
match self.lex_whitespace()? { loop {
break match self.lex_whitespace()? {
// { and } start/end of code block // { and } start/end of code block
'{' => self.eat_to(Token::CurlyOpen), '{' => self.eat_to(Token::CurlyOpen),
'}' => self.eat_to(Token::CurlyClose), '}' => self.eat_to(Token::CurlyClose),
@ -306,10 +300,18 @@ where
'"' => Some(self.lex_string()), '"' => Some(self.lex_string()),
// # comments // # comments
'#' => self.lex_comment(), '#' => {
// skip the rest of the line
// this leaves the newline btw
while !matches!(self.peek(), Some('\n') | None) {
self.eat();
}
continue;
}
// unexpected character // unexpected character
c => Some(Err(LexError::UnexpectedCharacter(c))), c => Some(Err(LexError::UnexpectedCharacter(c))),
};
} }
} }
} }

View File

@ -1,6 +1,6 @@
use crate::parser::{Block, Expr}; use crate::parser::{Block, Expr};
enum Value { pub enum Value {
String(String), String(String),
Integer(i64), Integer(i64),
Boolean(bool), Boolean(bool),