mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 01:45:03 +02:00
WIP
This commit is contained in:
@ -10,15 +10,15 @@ use indexmap::IndexMap;
|
||||
|
||||
#[derive(new)]
|
||||
crate struct Scope {
|
||||
it: Value,
|
||||
it: Spanned<Value>,
|
||||
#[new(default)]
|
||||
vars: IndexMap<String, Value>,
|
||||
vars: IndexMap<String, Spanned<Value>>,
|
||||
}
|
||||
|
||||
impl Scope {
|
||||
crate fn empty() -> Scope {
|
||||
Scope {
|
||||
it: Value::nothing(),
|
||||
it: Value::nothing().spanned_unknown(),
|
||||
vars: IndexMap::new(),
|
||||
}
|
||||
}
|
||||
@ -64,8 +64,10 @@ crate fn evaluate_baseline_expr(
|
||||
})
|
||||
}
|
||||
Some(next) => {
|
||||
item =
|
||||
Spanned::from_item(next.clone(), (expr.span().start, name.span().end))
|
||||
item = Spanned::from_item(
|
||||
next.clone().item,
|
||||
(expr.span().start, name.span().end),
|
||||
)
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -93,14 +95,11 @@ fn evaluate_reference(
|
||||
source: &Text,
|
||||
) -> Result<Spanned<Value>, ShellError> {
|
||||
match name {
|
||||
hir::Variable::It(span) => Ok(Spanned::from_item(scope.it.copy(), span)),
|
||||
hir::Variable::Other(span) => Ok(Spanned::from_item(
|
||||
scope
|
||||
.vars
|
||||
.get(span.slice(source))
|
||||
.map(|v| v.copy())
|
||||
.unwrap_or_else(|| Value::nothing()),
|
||||
span,
|
||||
)),
|
||||
hir::Variable::It(span) => Ok(Spanned::from_item(scope.it.item, span)),
|
||||
hir::Variable::Other(span) => Ok(scope
|
||||
.vars
|
||||
.get(span.slice(source))
|
||||
.map(|v| v.clone())
|
||||
.unwrap_or_else(|| Value::nothing().spanned(span))),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user