Fixed array expr
This commit is contained in:
@@ -7,6 +7,8 @@ pub enum Expression {
|
||||
Literal(Literal),
|
||||
Path(ExprPath),
|
||||
Statement(Box<Statement>),
|
||||
Array(Vec<Expression>),
|
||||
ArrayRepeat(Box<Expression>, Box<Expression>),
|
||||
Closure {
|
||||
return_type: Option<TypeExpr>,
|
||||
params: Vec<VarDecl>,
|
||||
@@ -31,8 +33,6 @@ pub enum Literal {
|
||||
Float(f64),
|
||||
Bool(bool),
|
||||
Tuple(Vec<Expression>),
|
||||
Array(Vec<Expression>),
|
||||
ArrayRepeat(Box<Expression>, Box<Expression>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
|
||||
@@ -459,10 +459,12 @@ tuple = {
|
||||
"(" ~ (expr ~ ("," ~ expr)*)? ~ ","? ~ ")"
|
||||
}
|
||||
|
||||
array = {
|
||||
"[" ~ expr ~ ";" ~ expr ~ "]" // Repeat notation: [0; 10]
|
||||
array_repeat = {
|
||||
"[" ~ expr ~ ";" ~ expr ~ "]"
|
||||
}
|
||||
|
||||
| "[" ~ (expr ~ ("," ~ expr)* ~ ","?)? ~ "]" // Standard elements initialization
|
||||
array = {
|
||||
"[" ~ (expr ~ ("," ~ expr)* ~ ","?)? ~ "]"
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
@@ -496,6 +498,7 @@ primary = {
|
||||
| literal
|
||||
| expr_path
|
||||
| tuple
|
||||
| array_repeat
|
||||
| array
|
||||
}
|
||||
|
||||
@@ -624,3 +627,4 @@ bin_op = {
|
||||
expr = { term ~ (bin_op ~ term)* }
|
||||
|
||||
term = { prefix* ~ primary ~ postfix* }
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Expression {
|
||||
}
|
||||
|
||||
Rule::closure => {
|
||||
ast_expr!(Self::Closure {
|
||||
ast_expr!(Expression::Closure {
|
||||
return_type: consume_rule(&mut inner, Rule::type_expr)
|
||||
.map(TypeExpr::try_from)
|
||||
.transpose(),
|
||||
@@ -85,6 +85,17 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Expression {
|
||||
})
|
||||
}
|
||||
|
||||
Rule::array => {
|
||||
ast_expr!(Expression::Array(collect_recovered(inner)))
|
||||
}
|
||||
|
||||
Rule::array_repeat => {
|
||||
ast_expr!(Expression::ArrayRepeat(
|
||||
Expression::try_from(inner.next().unwrap()).map(Box::new),
|
||||
Expression::try_from(inner.next().unwrap()).map(Box::new)
|
||||
))
|
||||
}
|
||||
|
||||
Rule::primary => pair.into_inner().next().unwrap().try_into(),
|
||||
Rule::static_path => ast_expr!(Expression::Path(pair.try_into())),
|
||||
Rule::literal => ast_expr!(Expression::Literal(pair.try_into())),
|
||||
|
||||
Reference in New Issue
Block a user