mirror of
https://github.com/nushell/nushell
synced 2025-01-14 14:14:13 +00:00
Fix var decl. improve for loop
This commit is contained in:
parent
b0ffaf1c91
commit
b6f00d07e8
3 changed files with 5 additions and 20 deletions
|
@ -157,7 +157,7 @@ fn eval_call(state: &State, stack: Stack, call: &Call) -> Result<Value, ShellErr
|
|||
|
||||
let rhs = eval_expression(state, stack.clone(), keyword_expr)?;
|
||||
|
||||
println!("Adding: {:?} to {}", rhs, var_id);
|
||||
//println!("Adding: {:?} to {}", rhs, var_id);
|
||||
|
||||
StackFrame::add_var(stack, var_id, rhs);
|
||||
Ok(Value::Unknown)
|
||||
|
@ -250,8 +250,7 @@ fn eval_call(state: &State, stack: Stack, call: &Call) -> Result<Value, ShellErr
|
|||
if curr == end_val {
|
||||
break;
|
||||
} else {
|
||||
let block_stack = StackFrame::enter_scope(stack.clone());
|
||||
eval_block(state, block_stack, block)?;
|
||||
eval_block(state, stack.clone(), block)?;
|
||||
|
||||
StackFrame::add_var(
|
||||
stack.clone(),
|
||||
|
|
|
@ -26,7 +26,7 @@ fn main() -> std::io::Result<()> {
|
|||
working_set.add_decl(sig.into());
|
||||
|
||||
let sig = Signature::build("let")
|
||||
.required("var_name", SyntaxShape::Variable, "variable name")
|
||||
.required("var_name", SyntaxShape::VarWithOptType, "variable name")
|
||||
.required(
|
||||
"initial_value",
|
||||
SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::Expression)),
|
||||
|
|
|
@ -1212,21 +1212,19 @@ impl<'a> ParserWorkingSet<'a> {
|
|||
let type_bytes = self.get_span_contents(spans[*spans_idx]);
|
||||
|
||||
let ty = self.parse_type(type_bytes);
|
||||
*spans_idx += 1;
|
||||
|
||||
let id = self.add_variable(bytes[0..(bytes.len() - 1)].to_vec(), ty.clone());
|
||||
|
||||
(
|
||||
Expression {
|
||||
expr: Expr::Var(id),
|
||||
span: span(&spans[*spans_idx - 2..*spans_idx]),
|
||||
span: span(&spans[*spans_idx - 1..*spans_idx + 1]),
|
||||
ty,
|
||||
},
|
||||
None,
|
||||
)
|
||||
} else {
|
||||
let id = self.add_variable(bytes[0..(bytes.len() - 1)].to_vec(), Type::Unknown);
|
||||
*spans_idx += 1;
|
||||
(
|
||||
Expression {
|
||||
expr: Expr::Var(id),
|
||||
|
@ -1238,12 +1236,11 @@ impl<'a> ParserWorkingSet<'a> {
|
|||
}
|
||||
} else {
|
||||
let id = self.add_variable(bytes, Type::Unknown);
|
||||
*spans_idx += 1;
|
||||
|
||||
(
|
||||
Expression {
|
||||
expr: Expr::Var(id),
|
||||
span: span(&spans[*spans_idx - 1..*spans_idx]),
|
||||
span: span(&spans[*spans_idx..*spans_idx + 1]),
|
||||
ty: Type::Unknown,
|
||||
},
|
||||
None,
|
||||
|
@ -2093,17 +2090,6 @@ impl<'a> ParserWorkingSet<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn parse_keyword(&self, span: Span, keyword: &[u8]) -> Option<ParseError> {
|
||||
if self.get_span_contents(span) == keyword {
|
||||
None
|
||||
} else {
|
||||
Some(ParseError::Mismatch(
|
||||
String::from_utf8_lossy(keyword).to_string(),
|
||||
span,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_def(&mut self, spans: &[Span]) -> (Statement, Option<ParseError>) {
|
||||
let mut error = None;
|
||||
let name = self.get_span_contents(spans[0]);
|
||||
|
|
Loading…
Reference in a new issue