add more fancy_string

This commit is contained in:
SimonFJ20 2023-03-19 04:40:25 +01:00
parent ae5ead91da
commit 663bf954f6
2 changed files with 32 additions and 17 deletions

View File

@ -223,9 +223,18 @@ impl AstNode for Expr {
None => "None".to_string(),
},
),
Expr::FunctionValue { parameters, body } => format!("FunctionValue <...>"),
Expr::Member { subject, value } => format!("Member <...>"),
Expr::Index { subject, value } => format!("Index <...>"),
Expr::FunctionValue {
parameters: _,
body: _,
} => format!("FunctionValue <...>"),
Expr::Member {
subject: _,
value: _,
} => format!("Member <...>"),
Expr::Index {
subject: _,
value: _,
} => format!("Index <...>"),
Expr::Call { subject, arguments } => format!(
"Call\n{}subject: {}\n{}arguments:\n{}",
indent(depth + 1),
@ -242,6 +251,7 @@ impl AstNode for Expr {
acc.push_str(&v);
acc
})
.map(|s| s.trim_end().to_string())
.unwrap_or("".to_string()),
),
Expr::Unary {
@ -267,12 +277,12 @@ impl AstNode for Expr {
indent(depth + 1),
right.fancy_string(depth + 1),
),
Expr::RangeExclusive { begin, end } => format!("RangeExclusive <...>"),
Expr::RangeInclusive { begin, end } => format!("RangeInclusive <...>"),
Expr::RangeExclusive { begin: _, end: _ } => format!("RangeExclusive <...>"),
Expr::RangeInclusive { begin: _, end: _ } => format!("RangeInclusive <...>"),
Expr::Assign {
assign_type,
subject,
value,
assign_type: _,
subject: _,
value: _,
} => format!("Assign <...>"),
Expr::Let { subject, value } => format!(
"Let {{\n{}subject: {}\n{}value: {}\n{}}}",
@ -287,11 +297,14 @@ impl AstNode for Expr {
),
Expr::Continue => format!("Continue"),
Expr::Break => format!("Break"),
Expr::While { condition, body } => format!("While <...>"),
Expr::While {
condition: _,
body: _,
} => format!("While <...>"),
Expr::For {
subject,
value,
body,
subject: _,
value: _,
body: _,
} => format!("For <...>"),
Expr::Return(value) => format!(
"Return{}",
@ -329,7 +342,7 @@ impl AstNode for Expr {
body.fancy_string(depth + 1)
),
Expr::Block { statements, value } => format!(
"Block\n{}statements:\n{}{}value: {}",
"Block\n{}statements:\n{}{}value: \n{}{}",
indent(depth + 1),
statements
.iter()
@ -344,8 +357,9 @@ impl AstNode for Expr {
})
.unwrap_or("".to_string()),
indent(depth + 1),
indent(depth + 2),
match value {
Some(expr) => expr.fancy_string(depth + 1),
Some(expr) => expr.fancy_string(depth + 2),
None => "None".to_string(),
},
),
@ -355,17 +369,17 @@ impl AstNode for Expr {
}
impl AstNode for ObjectEntry {
fn fancy_string(&self, depth: usize) -> String {
fn fancy_string(&self, _depth: usize) -> String {
match self {
ObjectEntry::Error(message) => format!("Error({message})"),
ObjectEntry::Pair { key, value } => format!("Pair <...>"),
ObjectEntry::Pair { key: _, value: _ } => format!("Pair <...>"),
ObjectEntry::Spread(_) => format!("Spread <...>"),
}
}
}
impl AstNode for Parameter {
fn fancy_string(&self, depth: usize) -> String {
fn fancy_string(&self, _depth: usize) -> String {
match self {
Parameter::Error(message) => format!("Error({message})"),
Parameter::Id { name, mutable } => {

View File

@ -20,6 +20,7 @@ fn main() {
{
fn myfunc(a, b) {
let c = a;
return a + b;
}
myfunc(1, 2);