forked from extern/nushell
Add record literal syntax (#326)
This commit is contained in:
@ -23,6 +23,7 @@ pub enum Expr {
|
||||
Block(BlockId),
|
||||
List(Vec<Expression>),
|
||||
Table(Vec<Expression>, Vec<Vec<Expression>>),
|
||||
Record(Vec<(Expression, Expression)>),
|
||||
Keyword(Vec<u8>, Span, Box<Expression>),
|
||||
ValueWithUnit(Box<Expression>, Spanned<Unit>),
|
||||
Filepath(String),
|
||||
|
@ -170,6 +170,17 @@ impl Expression {
|
||||
}
|
||||
false
|
||||
}
|
||||
Expr::Record(fields) => {
|
||||
for (field_name, field_value) in fields {
|
||||
if field_name.has_in_variable(working_set) {
|
||||
return true;
|
||||
}
|
||||
if field_value.has_in_variable(working_set) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
Expr::RowCondition(_, expr) => expr.has_in_variable(working_set),
|
||||
Expr::Signature(_) => false,
|
||||
Expr::String(_) => false,
|
||||
@ -292,6 +303,12 @@ impl Expression {
|
||||
right.replace_in_variable(working_set, new_var_id)
|
||||
}
|
||||
}
|
||||
Expr::Record(fields) => {
|
||||
for (field_name, field_value) in fields {
|
||||
field_name.replace_in_variable(working_set, new_var_id);
|
||||
field_value.replace_in_variable(working_set, new_var_id);
|
||||
}
|
||||
}
|
||||
Expr::RowCondition(_, expr) => expr.replace_in_variable(working_set, new_var_id),
|
||||
Expr::Signature(_) => {}
|
||||
Expr::String(_) => {}
|
||||
|
@ -95,6 +95,17 @@ impl Value {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_block(&self) -> Result<BlockId, ShellError> {
|
||||
match self {
|
||||
Value::Block { val, .. } => Ok(*val),
|
||||
x => Err(ShellError::CantConvert(
|
||||
"block".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the span for the current value
|
||||
pub fn span(&self) -> Result<Span, ShellError> {
|
||||
match self {
|
||||
|
Reference in New Issue
Block a user