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:
@@ -265,7 +265,6 @@ impl PrettyPrint for Stmt {
|
||||
write!(f, "{}}}", indent)
|
||||
}
|
||||
}
|
||||
|
||||
Stmt::Print { expression } => {
|
||||
if ctx.config.compact {
|
||||
let expr_str =
|
||||
@@ -279,7 +278,6 @@ impl PrettyPrint for Stmt {
|
||||
write!(f, "{}}}", indent)
|
||||
}
|
||||
}
|
||||
|
||||
Stmt::Var { name, initializer } => {
|
||||
if ctx.config.compact {
|
||||
match initializer {
|
||||
@@ -306,7 +304,6 @@ impl PrettyPrint for Stmt {
|
||||
write!(f, "{}}}", indent)
|
||||
}
|
||||
}
|
||||
|
||||
Stmt::Assign { name, value } => {
|
||||
if ctx.config.compact {
|
||||
let value_str =
|
||||
@@ -321,7 +318,6 @@ impl PrettyPrint for Stmt {
|
||||
write!(f, "{}}}", indent)
|
||||
}
|
||||
}
|
||||
|
||||
Stmt::Return { expression } => {
|
||||
if ctx.config.compact {
|
||||
let expr_str =
|
||||
@@ -335,7 +331,6 @@ impl PrettyPrint for Stmt {
|
||||
write!(f, "{}}}", indent)
|
||||
}
|
||||
}
|
||||
|
||||
Stmt::Block { statements } => {
|
||||
if ctx.config.compact {
|
||||
write!(f, "{{ ... ({} statements) }}", statements.len())
|
||||
@@ -355,7 +350,6 @@ impl PrettyPrint for Stmt {
|
||||
write!(f, "{}}}", indent)
|
||||
}
|
||||
}
|
||||
|
||||
Stmt::If {
|
||||
condition,
|
||||
then_branch,
|
||||
@@ -410,8 +404,27 @@ impl PrettyPrint for Stmt {
|
||||
write!(f, "{}}}", indent)
|
||||
}
|
||||
}
|
||||
|
||||
Stmt::Stmt { expression } => expression.pretty_print(ctx, f),
|
||||
Stmt::While { condition, body } => {
|
||||
write!(f, "{}while (", ctx.child_context(true).indent())?;
|
||||
condition.pretty_print(&ctx.child_context(true), f)?;
|
||||
writeln!(f, ") {{")?;
|
||||
body.pretty_print(&ctx.child_context(true), f)?;
|
||||
writeln!(f, "{}}}", ctx.child_context(true).indent())
|
||||
}
|
||||
Stmt::For {
|
||||
variable,
|
||||
iterable,
|
||||
body,
|
||||
} => {
|
||||
write!(f, "{}for (", ctx.child_context(true).indent())?;
|
||||
variable.pretty_print(&ctx.child_context(true), f)?;
|
||||
write!(f, " in ")?;
|
||||
iterable.pretty_print(&ctx.child_context(true), f)?;
|
||||
writeln!(f, ") {{")?;
|
||||
body.pretty_print(&ctx.child_context(true), f)?;
|
||||
writeln!(f, "{}}}", ctx.child_context(true).indent())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user