closure
This commit is contained in:
+13
-2
@@ -138,6 +138,7 @@ pub enum Stmt {
|
||||
},
|
||||
Return {
|
||||
expression: Box<AstNode<Expr>>,
|
||||
label: String,
|
||||
return_value: Box<BaseValue>,
|
||||
},
|
||||
Block {
|
||||
@@ -219,7 +220,12 @@ impl Display for Stmt {
|
||||
Stmt::Return {
|
||||
expression,
|
||||
return_value,
|
||||
} => write!(f, "Return({}) -> {:?};", expression.node, return_value),
|
||||
label,
|
||||
} => write!(
|
||||
f,
|
||||
"Return({}, {}) -> {:?};",
|
||||
expression.node, label, return_value
|
||||
),
|
||||
Stmt::Block {
|
||||
statements,
|
||||
label,
|
||||
@@ -327,7 +333,12 @@ impl Debug for Stmt {
|
||||
Stmt::Return {
|
||||
expression,
|
||||
return_value,
|
||||
} => write!(f, "Return({:?}) -> {:?};", expression.node, return_value),
|
||||
label,
|
||||
} => write!(
|
||||
f,
|
||||
"Return({:?}, {}) -> {:?};",
|
||||
expression.node, label, return_value
|
||||
),
|
||||
Stmt::Block {
|
||||
label,
|
||||
statements,
|
||||
|
||||
@@ -26,6 +26,11 @@ pub enum LoxError {
|
||||
expected: String,
|
||||
found: String,
|
||||
},
|
||||
Return {
|
||||
source_slice: SourceSlice,
|
||||
value: BaseValue,
|
||||
return_label: String,
|
||||
},
|
||||
}
|
||||
|
||||
/// Configuration for error display formatting
|
||||
@@ -84,6 +89,13 @@ impl LoxError {
|
||||
} => {
|
||||
format!("expected {}, found {}", expected, found)
|
||||
}
|
||||
LoxError::Return {
|
||||
value,
|
||||
return_label,
|
||||
..
|
||||
} => {
|
||||
format!("return value: {} and label: {}", value, return_label)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +106,11 @@ impl LoxError {
|
||||
LoxError::ParseError { source_slice, .. } => Some(source_slice.clone()),
|
||||
LoxError::IoError { .. } => None,
|
||||
LoxError::TypeMismatch { source_slice, .. } => Some(source_slice.clone()),
|
||||
LoxError::Return {
|
||||
value,
|
||||
return_label,
|
||||
..
|
||||
} => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +121,7 @@ impl LoxError {
|
||||
LoxError::ParseError { .. } => "parse error",
|
||||
LoxError::IoError { .. } => "io error",
|
||||
LoxError::TypeMismatch { .. } => "type error",
|
||||
LoxError::Return { .. } => "return error",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,6 +414,20 @@ impl fmt::Display for LoxError {
|
||||
found
|
||||
)
|
||||
}
|
||||
LoxError::Return {
|
||||
value,
|
||||
return_label,
|
||||
source_slice,
|
||||
} => {
|
||||
write!(
|
||||
f,
|
||||
"Return error at {}:{}: value `{}`, label `{}`",
|
||||
source_slice.start_position.line + 1,
|
||||
source_slice.start_position.column + 1,
|
||||
value,
|
||||
return_label
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user