mirror of
https://github.com/AleoHQ/leo.git
synced 2024-11-25 13:53:29 +03:00
add group number syntax to pest ast
This commit is contained in:
parent
d3571a8e01
commit
b34b5f4a03
@ -234,7 +234,8 @@ value_boolean = { "true" | "false" }
|
||||
value_field = ${ value_number ~ type_field }
|
||||
|
||||
// Declared in values/group_value.rs
|
||||
value_group = ${ group_tuple ~ type_group }
|
||||
value_group = ${ group_single_or_tuple ~ type_group }
|
||||
group_single_or_tuple = {value_number | group_tuple}
|
||||
group_tuple = !{"(" ~ group_coordinate ~ "," ~ group_coordinate ~ ")"}
|
||||
|
||||
// Declared in values/group_coordinate.rs
|
||||
|
@ -14,7 +14,12 @@
|
||||
// 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::GroupType, values::GroupCoordinate, SpanDef};
|
||||
use crate::{
|
||||
ast::Rule,
|
||||
types::GroupType,
|
||||
values::{GroupCoordinate, NumberValue},
|
||||
SpanDef,
|
||||
};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
@ -24,7 +29,7 @@ use std::fmt;
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::value_group))]
|
||||
pub struct GroupValue<'ast> {
|
||||
pub value: GroupTuple<'ast>,
|
||||
pub value: GroupRepresentation<'ast>,
|
||||
pub type_: GroupType,
|
||||
#[pest_ast(outer())]
|
||||
#[serde(with = "SpanDef")]
|
||||
@ -37,6 +42,22 @@ impl<'ast> fmt::Display for GroupValue<'ast> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::group_single_or_tuple))]
|
||||
pub enum GroupRepresentation<'ast> {
|
||||
Single(NumberValue<'ast>),
|
||||
Tuple(GroupTuple<'ast>),
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for GroupRepresentation<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
GroupRepresentation::Single(number) => write!(f, "{}", number),
|
||||
GroupRepresentation::Tuple(tuple) => write!(f, "{}", tuple),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::group_tuple))]
|
||||
pub struct GroupTuple<'ast> {
|
||||
|
Loading…
Reference in New Issue
Block a user