mirror of
https://github.com/AleoHQ/leo.git
synced 2024-11-29 22:36:05 +03:00
restrict grammar rule for array initializers
This commit is contained in:
parent
3b737b2a34
commit
0edad533fb
@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{ast::Rule, common::SpreadOrExpression, values::PositiveNumber, SpanDef};
|
||||
use crate::{ast::Rule, expressions::Expression, values::PositiveNumber, SpanDef};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
@ -23,7 +23,7 @@ use serde::Serialize;
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::expression_array_initializer))]
|
||||
pub struct ArrayInitializerExpression<'ast> {
|
||||
pub expression: Box<SpreadOrExpression<'ast>>,
|
||||
pub expression: Box<Expression<'ast>>,
|
||||
pub count: PositiveNumber<'ast>,
|
||||
#[pest_ast(outer())]
|
||||
#[serde(with = "SpanDef")]
|
||||
|
@ -324,7 +324,7 @@ expression = { expression_term ~ (operation_binary ~ expression_term)* }
|
||||
expression_tuple = { "(" ~ (expression ~ ("," ~ expression)*)? ~ ")" }
|
||||
|
||||
// Declared in expressions/array_initializer_expression.rs
|
||||
expression_array_initializer = { "[" ~ spread_or_expression ~ ";" ~ number_positive ~ "]" }
|
||||
expression_array_initializer = { "[" ~ expression ~ ";" ~ number_positive ~ "]" }
|
||||
|
||||
// Declared in expressions/array_inline_expression.rs
|
||||
expression_array_inline = { "[" ~ NEWLINE* ~ inline_array_inner ~ NEWLINE* ~ "]"}
|
||||
|
@ -15,7 +15,7 @@
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::Expression;
|
||||
use leo_ast::common::SpreadOrExpression as AstSpreadOrExpression;
|
||||
use leo_ast::{common::SpreadOrExpression as AstSpreadOrExpression, expressions::Expression as AstExpression};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
@ -38,6 +38,12 @@ impl<'ast> From<AstSpreadOrExpression<'ast>> for SpreadOrExpression {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> From<AstExpression<'ast>> for SpreadOrExpression {
|
||||
fn from(expression: AstExpression<'ast>) -> Self {
|
||||
SpreadOrExpression::Expression(Expression::from(expression))
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for SpreadOrExpression {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
|
Loading…
Reference in New Issue
Block a user