less lexer recursion
This commit is contained in:
parent
586ddd1aec
commit
706f4b3763
20
src/lexer.rs
20
src/lexer.rs
|
@ -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))),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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),
|
||||||
|
|
Loading…
Reference in New Issue