This commit is contained in:
Yehuda Katz
2019-07-08 09:44:53 -07:00
parent 71adfb4cdc
commit 7b68739b52
47 changed files with 467 additions and 354 deletions

View File

@ -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))),
}
}