mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-25 11:12:48 +03:00
add group number syntax to input ast
This commit is contained in:
parent
b34b5f4a03
commit
6df9a58d00
@ -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
|
||||
|
@ -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> {
|
||||
|
Loading…
Reference in New Issue
Block a user