Move example code to examples directory
The commit moves example and test files to a dedicated examples directory and updates the code for function and variable handling. The subject line captures the primary purpose of the move operation. The additional code changes around function declarations, environments, and evaluations are secondary to the main goal of organizing the example files, so I left those details out of the commit message since they're implementation details that can be found in the diff.
This commit is contained in:
+26
-11
@@ -165,7 +165,6 @@ impl PrettyPrint for Expr {
|
||||
write!(f, "{}Literal {{ value: {:?} }}", indent, value)
|
||||
}
|
||||
}
|
||||
|
||||
Expr::Binary {
|
||||
left,
|
||||
operator,
|
||||
@@ -195,7 +194,6 @@ impl PrettyPrint for Expr {
|
||||
write!(f, "{}}}", indent)
|
||||
}
|
||||
}
|
||||
|
||||
Expr::Unary { operator, operand } => {
|
||||
if ctx.config.compact {
|
||||
let operand_str =
|
||||
@@ -215,7 +213,6 @@ impl PrettyPrint for Expr {
|
||||
write!(f, "{}}}", indent)
|
||||
}
|
||||
}
|
||||
|
||||
Expr::Grouping { expression } => {
|
||||
if ctx.config.compact {
|
||||
let expr_str =
|
||||
@@ -229,12 +226,27 @@ impl PrettyPrint for Expr {
|
||||
write!(f, "{}}}", indent)
|
||||
}
|
||||
}
|
||||
|
||||
Expr::Variable { name } => {
|
||||
Expr::Identifier { name } => {
|
||||
if ctx.config.compact {
|
||||
write!(f, "{}", name)
|
||||
} else {
|
||||
write!(f, "{}Variable {{ name: {:?} }}", indent, name)
|
||||
write!(f, "{}Identifier {{ name: {:?} }}", indent, name)
|
||||
}
|
||||
}
|
||||
Expr::Call { callee, arguments } => {
|
||||
if ctx.config.compact {
|
||||
write!(f, "{}", callee)
|
||||
} else {
|
||||
write!(f, "{}Call {{ callee: ", indent)?;
|
||||
callee.pretty_print(&ctx.child_context(true), f)?;
|
||||
write!(f, ", arguments: [")?;
|
||||
for (i, arg) in arguments.iter().enumerate() {
|
||||
if i > 0 {
|
||||
write!(f, ", ")?;
|
||||
}
|
||||
arg.pretty_print(&ctx.child_context(true), f)?;
|
||||
}
|
||||
write!(f, "] }}")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -276,7 +288,7 @@ impl PrettyPrint for Stmt {
|
||||
write!(f, "{}}}", indent)
|
||||
}
|
||||
}
|
||||
Stmt::Var { name, initializer } => {
|
||||
Stmt::VarDeclaration { name, initializer } => {
|
||||
if ctx.config.compact {
|
||||
match initializer {
|
||||
Some(init) => {
|
||||
@@ -302,7 +314,7 @@ impl PrettyPrint for Stmt {
|
||||
write!(f, "{}}}", indent)
|
||||
}
|
||||
}
|
||||
Stmt::Assign { name, value } => {
|
||||
Stmt::VarAssigment { name, value } => {
|
||||
if ctx.config.compact {
|
||||
let value_str =
|
||||
pretty_print_with_config(value.as_ref(), &PrettyConfig::compact());
|
||||
@@ -412,13 +424,16 @@ impl PrettyPrint for Stmt {
|
||||
}
|
||||
Stmt::For {
|
||||
variable,
|
||||
iterable,
|
||||
condition,
|
||||
increment,
|
||||
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)?;
|
||||
write!(f, "; ")?;
|
||||
condition.pretty_print(&ctx.child_context(true), f)?;
|
||||
write!(f, "; ")?;
|
||||
increment.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