forked from AbleScript/ablescript
Implemented key extraction
This commit is contained in:
parent
f99aad0152
commit
bd0983c4dd
|
@ -160,6 +160,7 @@ pub enum Expr {
|
|||
index: Box<Spanned<Expr>>,
|
||||
},
|
||||
Len(Box<Spanned<Expr>>),
|
||||
Keys(Box<Spanned<Expr>>),
|
||||
Variable(String),
|
||||
}
|
||||
|
||||
|
|
|
@ -195,7 +195,14 @@ impl ExecEnv {
|
|||
.unwrap_or(Value::Nul)
|
||||
}
|
||||
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
|
||||
// Ident here.
|
||||
Variable(name) => {
|
||||
|
|
|
@ -294,6 +294,10 @@ impl<'source> Parser<'source> {
|
|||
}
|
||||
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)?),
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue