mirror of
https://github.com/nushell/nushell.git
synced 2025-07-01 07:00:37 +02:00
Split blocks and closures (#7075)
* Split closures and blocks * Tests mostly working * finish last fixes, passes all tests * fmt
This commit is contained in:
@ -125,7 +125,7 @@ pub fn value_to_json_value(v: &Value) -> Result<nu_json::Value, ShellError> {
|
||||
|
||||
Value::List { vals, .. } => nu_json::Value::Array(json_list(vals)?),
|
||||
Value::Error { error } => return Err(error.clone()),
|
||||
Value::Block { .. } | Value::Range { .. } => nu_json::Value::Null,
|
||||
Value::Closure { .. } | Value::Block { .. } | Value::Range { .. } => nu_json::Value::Null,
|
||||
Value::Binary { val, .. } => {
|
||||
nu_json::Value::Array(val.iter().map(|x| nu_json::Value::U64(*x as u64)).collect())
|
||||
}
|
||||
|
@ -66,6 +66,10 @@ fn value_to_string(v: &Value, span: Span) -> Result<String, ShellError> {
|
||||
"block not supported".into(),
|
||||
span,
|
||||
)),
|
||||
Value::Closure { .. } => Err(ShellError::UnsupportedInput(
|
||||
"closure not supported".into(),
|
||||
span,
|
||||
)),
|
||||
Value::Bool { val, .. } => {
|
||||
if *val {
|
||||
Ok("true".to_string())
|
||||
|
@ -100,6 +100,7 @@ fn local_into_string(value: Value, separator: &str, config: &Config) -> String {
|
||||
.collect::<Vec<_>>()
|
||||
.join(separator),
|
||||
Value::Block { val, .. } => format!("<Block {}>", val),
|
||||
Value::Closure { val, .. } => format!("<Closure {}>", val),
|
||||
Value::Nothing { .. } => String::new(),
|
||||
Value::Error { error } => format!("{:?}", error),
|
||||
Value::Binary { val, .. } => format!("{:?}", val),
|
||||
|
@ -67,6 +67,11 @@ fn helper(engine_state: &EngineState, v: &Value) -> Result<toml::Value, ShellErr
|
||||
let code = String::from_utf8_lossy(code).to_string();
|
||||
toml::Value::String(code)
|
||||
}
|
||||
Value::Closure { span, .. } => {
|
||||
let code = engine_state.get_span_contents(span);
|
||||
let code = String::from_utf8_lossy(code).to_string();
|
||||
toml::Value::String(code)
|
||||
}
|
||||
Value::Nothing { .. } => toml::Value::String("<Nothing>".to_string()),
|
||||
Value::Error { error } => return Err(error.clone()),
|
||||
Value::Binary { val, .. } => toml::Value::Array(
|
||||
|
@ -72,6 +72,7 @@ pub fn value_to_yaml_value(v: &Value) -> Result<serde_yaml::Value, ShellError> {
|
||||
serde_yaml::Value::Sequence(out)
|
||||
}
|
||||
Value::Block { .. } => serde_yaml::Value::Null,
|
||||
Value::Closure { .. } => serde_yaml::Value::Null,
|
||||
Value::Nothing { .. } => serde_yaml::Value::Null,
|
||||
Value::Error { error } => return Err(error.clone()),
|
||||
Value::Binary { val, .. } => serde_yaml::Value::Sequence(
|
||||
|
Reference in New Issue
Block a user