Implemented key extraction
This commit is contained in:
parent
e895ef775f
commit
85226fbfbb
|
@ -160,6 +160,7 @@ pub enum Expr {
|
||||||
index: Box<Spanned<Expr>>,
|
index: Box<Spanned<Expr>>,
|
||||||
},
|
},
|
||||||
Len(Box<Spanned<Expr>>),
|
Len(Box<Spanned<Expr>>),
|
||||||
|
Keys(Box<Spanned<Expr>>),
|
||||||
Variable(String),
|
Variable(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -195,7 +195,14 @@ impl ExecEnv {
|
||||||
.unwrap_or(Value::Nul)
|
.unwrap_or(Value::Nul)
|
||||||
}
|
}
|
||||||
Len(expr) => Value::Int(self.eval_expr(expr)?.length()),
|
Len(expr) => Value::Int(self.eval_expr(expr)?.length()),
|
||||||
|
Keys(expr) => Value::Cart(
|
||||||
|
self.eval_expr(expr)?
|
||||||
|
.into_cart()
|
||||||
|
.into_keys()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(i, k)| (Value::Int(i as isize + 1), ValueRef::new(k)))
|
||||||
|
.collect(),
|
||||||
|
),
|
||||||
// TODO: not too happy with constructing an artificial
|
// TODO: not too happy with constructing an artificial
|
||||||
// Ident here.
|
// Ident here.
|
||||||
Variable(name) => {
|
Variable(name) => {
|
||||||
|
|
|
@ -294,6 +294,10 @@ impl<'source> Parser<'source> {
|
||||||
}
|
}
|
||||||
None => break Expr::Len(Box::new(expr)),
|
None => break Expr::Len(Box::new(expr)),
|
||||||
},
|
},
|
||||||
|
Token::GreaterThan if buf.is_none() => {
|
||||||
|
self.require(Token::RightBracket)?;
|
||||||
|
break Expr::Keys(Box::new(expr));
|
||||||
|
}
|
||||||
token => buf = Some(self.parse_expr(token, &mut buf)?),
|
token => buf = Some(self.parse_expr(token, &mut buf)?),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue