mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-23 23:23:50 +03:00
Merge pull request #326 from AleoHQ/refactor/array-initializer
Restrict pest grammar rule for array initializers
This commit is contained in:
commit
cb3fcf1d1e
@ -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")]
|
||||
|
@ -346,7 +346,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