add group number syntax to input ast

This commit is contained in:
collin 2020-08-18 12:54:11 -07:00
parent b34b5f4a03
commit 6df9a58d00
2 changed files with 24 additions and 3 deletions

View File

@ -131,7 +131,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

View File

@ -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::GroupType, values::GroupCoordinate};
use crate::{
ast::Rule,
types::GroupType,
values::{GroupCoordinate, NumberValue},
};
use pest::Span;
use pest_ast::FromPest;
@ -23,7 +27,7 @@ use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
#[pest_ast(rule(Rule::value_group))]
pub struct GroupValue<'ast> {
pub value: GroupTuple<'ast>,
pub value: GroupRepresentation<'ast>,
pub type_: GroupType,
#[pest_ast(outer())]
pub span: Span<'ast>,
@ -35,6 +39,22 @@ impl<'ast> fmt::Display for GroupValue<'ast> {
}
}
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
#[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, Eq)]
#[pest_ast(rule(Rule::group_tuple))]
pub struct GroupTuple<'ast> {