mirror of
https://github.com/PaddiM8/kalker.git
synced 2025-01-19 03:38:13 +01:00
Support nested vector comprehensions
This commit is contained in:
parent
4b996989ca
commit
70f56f43db
@ -325,7 +325,14 @@ fn analyse_binary(
|
|||||||
(_, TokenKind::Colon, _) => {
|
(_, TokenKind::Colon, _) => {
|
||||||
context.in_comprehension = true;
|
context.in_comprehension = true;
|
||||||
context.in_conditional = true;
|
context.in_conditional = true;
|
||||||
context.comprehension_vars = Some(Vec::new());
|
|
||||||
|
let comprehension_vars_index =
|
||||||
|
if let Some(existing_comprehension_vars) = &context.comprehension_vars {
|
||||||
|
existing_comprehension_vars.len()
|
||||||
|
} else {
|
||||||
|
context.comprehension_vars = Some(Vec::new());
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
let mut conditions = vec![right];
|
let mut conditions = vec![right];
|
||||||
let mut has_comma = false;
|
let mut has_comma = false;
|
||||||
@ -346,14 +353,11 @@ fn analyse_binary(
|
|||||||
context.in_comprehension = false;
|
context.in_comprehension = false;
|
||||||
context.in_conditional = false;
|
context.in_conditional = false;
|
||||||
let left = analyse_expr(context, left)?;
|
let left = analyse_expr(context, left)?;
|
||||||
|
let mut all_vars = context.comprehension_vars.take().unwrap();
|
||||||
|
let vars = all_vars.drain(comprehension_vars_index..).collect();
|
||||||
|
context.comprehension_vars = Some(all_vars);
|
||||||
|
|
||||||
let result = Expr::Comprehension(
|
Ok(Expr::Comprehension(Box::new(left), conditions, vars))
|
||||||
Box::new(left),
|
|
||||||
conditions,
|
|
||||||
context.comprehension_vars.take().unwrap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(result)
|
|
||||||
}
|
}
|
||||||
(
|
(
|
||||||
Expr::Var(_),
|
Expr::Var(_),
|
||||||
|
Loading…
Reference in New Issue
Block a user