Add while loop support and token pretty printing
The commit adds while loop statements and improves token display formatting: - Implements while loop syntax and evaluation - Adds a new token pretty printing module with configurable formatting - Improves token display with colors and different output modes
This commit is contained in:
@@ -81,6 +81,10 @@ impl Parser {
|
||||
self.if_statement()?,
|
||||
self.peek().source_slice.clone(),
|
||||
)),
|
||||
(TokenType::While, _) => Ok(AstNode::new(
|
||||
self.while_statement()?,
|
||||
self.peek().source_slice.clone(),
|
||||
)),
|
||||
_ => Ok(AstNode::new(
|
||||
self.expression_statement()?,
|
||||
self.peek().source_slice.clone(),
|
||||
@@ -88,6 +92,16 @@ impl Parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn while_statement(&mut self) -> LoxResult<Stmt> {
|
||||
self.advance();
|
||||
let condition = self.expression()?;
|
||||
let body = self.block_statement()?;
|
||||
Ok(Stmt::While {
|
||||
condition: Box::new(condition),
|
||||
body: Box::new(body),
|
||||
})
|
||||
}
|
||||
|
||||
fn if_statement(&mut self) -> LoxResult<Stmt> {
|
||||
self.advance();
|
||||
let condition = self.expression()?;
|
||||
|
||||
Reference in New Issue
Block a user