mirror of
https://github.com/AleoHQ/leo.git
synced 2024-11-24 19:03:27 +03:00
impl array-type in ast
This commit is contained in:
parent
3b737b2a34
commit
7a0dc342fb
@ -194,7 +194,29 @@ type_self = { "Self" }
|
||||
type_circuit = { identifier }
|
||||
|
||||
// Declared in types/array_type.rs
|
||||
type_array = { type_data ~ ("[" ~ number_positive ~ "]")+ }
|
||||
type_array = { "[" ~ array_element ~ ";" ~ array_dimensions ~ "]" }
|
||||
|
||||
// Declared in types/array_element.rs
|
||||
array_element = {
|
||||
type_self
|
||||
| type_tuple
|
||||
| type_data
|
||||
| type_circuit
|
||||
}
|
||||
|
||||
// Declared in types/array_dimensions.rs
|
||||
array_dimensions = {
|
||||
dimension_single
|
||||
| dimension_multiple
|
||||
}
|
||||
|
||||
// Declared in types/array_dimensions.rs
|
||||
dimension_single = {
|
||||
number_positive
|
||||
}
|
||||
|
||||
// Declared in types/array_dimensions.rs
|
||||
dimension_multiple = { "(" ~ number_positive ~ ("," ~ number_positive)* ~ ")"}
|
||||
|
||||
type_tuple = { "(" ~ NEWLINE* ~ type_ ~ ("," ~ NEWLINE* ~ type_)+ ~ ","? ~ NEWLINE* ~ ")" }
|
||||
|
||||
|
46
ast/src/types/array_dimensions.rs
Normal file
46
ast/src/types/array_dimensions.rs
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2019-2020 Aleo Systems Inc.
|
||||
// This file is part of the Leo library.
|
||||
|
||||
// The Leo library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// The Leo library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// 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, values::PositiveNumber, SpanDef};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::array_dimensions))]
|
||||
pub enum ArrayDimensions<'ast> {
|
||||
Single(Single<'ast>),
|
||||
Multiple(Multiple<'ast>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::dimension_single))]
|
||||
pub struct Single<'ast> {
|
||||
pub number: PositiveNumber<'ast>,
|
||||
#[pest_ast(outer())]
|
||||
#[serde(with = "SpanDef")]
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::dimension_multiple))]
|
||||
pub struct Multiple<'ast> {
|
||||
pub numbers: Vec<PositiveNumber<'ast>>,
|
||||
#[pest_ast(outer())]
|
||||
#[serde(with = "SpanDef")]
|
||||
pub span: Span<'ast>,
|
||||
}
|
29
ast/src/types/array_element.rs
Normal file
29
ast/src/types/array_element.rs
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright (C) 2019-2020 Aleo Systems Inc.
|
||||
// This file is part of the Leo library.
|
||||
|
||||
// The Leo library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// The Leo library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// 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, types::*};
|
||||
|
||||
use pest_ast::FromPest;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::array_element))]
|
||||
pub enum ArrayElement<'ast> {
|
||||
Basic(DataType),
|
||||
Tuple(TupleType<'ast>),
|
||||
Circuit(CircuitType<'ast>),
|
||||
SelfType(SelfType),
|
||||
}
|
@ -14,7 +14,11 @@
|
||||
// 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, types::DataType, values::PositiveNumber, SpanDef};
|
||||
use crate::{
|
||||
ast::Rule,
|
||||
types::{ArrayDimensions, ArrayElement},
|
||||
SpanDef,
|
||||
};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
@ -23,8 +27,8 @@ use serde::Serialize;
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_array))]
|
||||
pub struct ArrayType<'ast> {
|
||||
pub _type: DataType,
|
||||
pub dimensions: Vec<PositiveNumber<'ast>>,
|
||||
pub type_: ArrayElement<'ast>,
|
||||
pub dimensions: ArrayDimensions<'ast>,
|
||||
#[pest_ast(outer())]
|
||||
#[serde(with = "SpanDef")]
|
||||
pub span: Span<'ast>,
|
||||
|
@ -17,6 +17,12 @@
|
||||
pub mod address_type;
|
||||
pub use address_type::*;
|
||||
|
||||
pub mod array_dimensions;
|
||||
pub use array_dimensions::*;
|
||||
|
||||
pub mod array_element;
|
||||
pub use array_element::*;
|
||||
|
||||
pub mod array_type;
|
||||
pub use array_type::*;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user