restrict grammar rule for array initializers

This commit is contained in:
collin 2020-09-02 12:19:43 -07:00
parent 3b737b2a34
commit 0edad533fb
3 changed files with 10 additions and 4 deletions

View File

@ -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")]

View File

@ -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* ~ "]"}

View File

@ -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 {