Allow block expressions.
This commit is contained in:
parent
473e40e8a4
commit
22cb69a16b
@ -544,10 +544,15 @@ impl Engine<'_> {
|
||||
Expr::Identifier(id, pos) => {
|
||||
Self::search_scope(scope, id, Ok, *pos).map(|(_, val)| val)
|
||||
}
|
||||
|
||||
// lhs[idx_expr]
|
||||
Expr::Index(lhs, idx_expr, idx_pos) => self
|
||||
.eval_index_expr(scope, lhs, idx_expr, *idx_pos)
|
||||
.map(|(_, _, _, x)| x),
|
||||
|
||||
// Statement block
|
||||
Expr::Block(block, _) => self.eval_stmt(scope, block),
|
||||
|
||||
// lhs = rhs
|
||||
Expr::Assignment(lhs, rhs, _) => {
|
||||
let rhs_val = self.eval_expr(scope, rhs)?;
|
||||
|
@ -129,6 +129,7 @@ pub enum Expr {
|
||||
Identifier(String, Position),
|
||||
CharConstant(char, Position),
|
||||
StringConstant(String, Position),
|
||||
Block(Box<Stmt>, Position),
|
||||
FunctionCall(String, Vec<Expr>, Option<Dynamic>, Position),
|
||||
Assignment(Box<Expr>, Box<Expr>, Position),
|
||||
Dot(Box<Expr>, Box<Expr>, Position),
|
||||
@ -150,6 +151,7 @@ impl Expr {
|
||||
| Expr::CharConstant(_, pos)
|
||||
| Expr::StringConstant(_, pos)
|
||||
| Expr::FunctionCall(_, _, _, pos)
|
||||
| Expr::Block(_, pos)
|
||||
| Expr::Array(_, pos)
|
||||
| Expr::True(pos)
|
||||
| Expr::False(pos)
|
||||
@ -1185,6 +1187,14 @@ fn parse_array_expr<'a>(
|
||||
}
|
||||
|
||||
fn parse_primary<'a>(input: &mut Peekable<TokenIterator<'a>>) -> Result<Expr, ParseError> {
|
||||
// Block statement as expression
|
||||
match input.peek() {
|
||||
Some(&(Token::LeftBrace, pos)) => {
|
||||
return parse_block(input).map(|block| Expr::Block(Box::new(block), pos))
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
let token = input.next();
|
||||
|
||||
let mut follow_on = false;
|
||||
|
Loading…
Reference in New Issue
Block a user