nothing variable (#527)

* nothing variable

* corrected comments

* added color to nothing like bool

* compare nothing with values

* comparison tests
This commit is contained in:
Fernando Herrera
2021-12-20 01:05:33 +00:00
committed by GitHub
parent ff5b7e5ad2
commit e949658381
11 changed files with 167 additions and 152 deletions

View File

@ -33,5 +33,6 @@ pub enum Expr {
FullCellPath(Box<FullCellPath>),
ImportPattern(ImportPattern),
Signature(Box<Signature>),
Nothing,
Garbage,
}

View File

@ -148,6 +148,7 @@ impl Expression {
false
}
Expr::Garbage => false,
Expr::Nothing => false,
Expr::GlobPattern(_) => false,
Expr::Int(_) => false,
Expr::Keyword(_, _, expr) => expr.has_in_variable(working_set),
@ -291,6 +292,7 @@ impl Expression {
}
Expr::ImportPattern(_) => {}
Expr::Garbage => {}
Expr::Nothing => {}
Expr::GlobPattern(_) => {}
Expr::Int(_) => {}
Expr::Keyword(_, _, expr) => expr.replace_in_variable(working_set, new_var_id),

View File

@ -1141,13 +1141,18 @@ impl Value {
val: matches!(ordering, Ordering::Equal),
span,
}),
None => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_span: rhs.span()?,
}),
None => match (self, rhs) {
(Value::Nothing { .. }, _) | (_, Value::Nothing { .. }) => {
Ok(Value::Bool { val: false, span })
}
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_span: rhs.span()?,
}),
},
}
}
pub fn ne(&self, op: Span, rhs: &Value) -> Result<Value, ShellError> {
@ -1162,13 +1167,18 @@ impl Value {
val: !matches!(ordering, Ordering::Equal),
span,
}),
None => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_span: rhs.span()?,
}),
None => match (self, rhs) {
(Value::Nothing { .. }, _) | (_, Value::Nothing { .. }) => {
Ok(Value::Bool { val: true, span })
}
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_span: rhs.span()?,
}),
},
}
}