diff --git a/typed/src/expression.rs b/typed/src/expression.rs
index 2d7bfceada..09edc78460 100644
--- a/typed/src/expression.rs
+++ b/typed/src/expression.rs
@@ -102,7 +102,7 @@ impl Expression {
pub fn set_span(&mut self, new_span: &Span) {
match self {
Expression::Field(_, old_span) => *old_span = new_span.clone(),
- Expression::Group(value) => value.span = new_span.clone(),
+ Expression::Group(value) => value.set_span(new_span),
Expression::Add(_, _, old_span) => *old_span = new_span.clone(),
Expression::Sub(_, _, old_span) => *old_span = new_span.clone(),
diff --git a/typed/src/groups/group_value.rs b/typed/src/groups/group_value.rs
index e3412ccb08..01ef67253d 100644
--- a/typed/src/groups/group_value.rs
+++ b/typed/src/groups/group_value.rs
@@ -15,46 +15,100 @@
// along with the Leo library. If not, see .
use crate::{common::span::Span, groups::GroupCoordinate};
-use leo_ast::values::GroupValue as AstGroupValue;
-use leo_input::values::GroupValue as InputGroupValue;
+use leo_ast::values::{
+ GroupRepresentation as AstGroupRepresentation,
+ GroupTuple as AstGroupTuple,
+ GroupValue as AstGroupValue,
+};
+use leo_input::values::{
+ GroupRepresentation as InputGroupRepresentation,
+ GroupTuple as InputGroupTuple,
+ GroupValue as InputGroupValue,
+};
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
-pub struct GroupValue {
- pub x: GroupCoordinate,
- pub y: GroupCoordinate,
- pub span: Span,
+pub enum GroupValue {
+ Single(String, Span),
+ Tuple(GroupTuple),
+}
+
+impl GroupValue {
+ pub fn set_span(&mut self, new_span: &Span) {
+ match self {
+ GroupValue::Single(_, old_span) => *old_span = new_span.clone(),
+ GroupValue::Tuple(tuple) => tuple.span = new_span.clone(),
+ }
+ }
}
impl<'ast> From> for GroupValue {
- fn from(ast_group: AstGroupValue<'ast>) -> Self {
- let ast_x = ast_group.value.x;
- let ast_y = ast_group.value.y;
+ fn from(ast_group: AstGroupValue) -> Self {
+ let span = Span::from(ast_group.span);
- Self {
- x: GroupCoordinate::from(ast_x),
- y: GroupCoordinate::from(ast_y),
- span: Span::from(ast_group.span),
+ match ast_group.value {
+ AstGroupRepresentation::Single(number) => GroupValue::Single(number.to_string(), span),
+ AstGroupRepresentation::Tuple(tuple) => GroupValue::Tuple(GroupTuple::from(tuple)),
}
}
}
impl<'ast> From> for GroupValue {
- fn from(ast_group: InputGroupValue<'ast>) -> Self {
- let ast_x = ast_group.value.x;
- let ast_y = ast_group.value.y;
+ fn from(ast_group: InputGroupValue) -> Self {
+ let span = Span::from(ast_group.span);
- Self {
- x: GroupCoordinate::from(ast_x),
- y: GroupCoordinate::from(ast_y),
- span: Span::from(ast_group.span),
+ match ast_group.value {
+ InputGroupRepresentation::Single(number) => GroupValue::Single(number.to_string(), span),
+ InputGroupRepresentation::Tuple(tuple) => GroupValue::Tuple(GroupTuple::from(tuple)),
}
}
}
impl fmt::Display for GroupValue {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match self {
+ GroupValue::Single(string, _) => write!(f, "{}", string),
+ GroupValue::Tuple(tuple) => write!(f, "{}", tuple),
+ }
+ }
+}
+
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct GroupTuple {
+ pub x: GroupCoordinate,
+ pub y: GroupCoordinate,
+ pub span: Span,
+}
+
+impl<'ast> From> for GroupTuple {
+ fn from(ast_group: AstGroupTuple<'ast>) -> Self {
+ let ast_x = ast_group.x;
+ let ast_y = ast_group.y;
+
+ Self {
+ x: GroupCoordinate::from(ast_x),
+ y: GroupCoordinate::from(ast_y),
+ span: Span::from(ast_group.span),
+ }
+ }
+}
+
+impl<'ast> From> for GroupTuple {
+ fn from(ast_group: InputGroupTuple<'ast>) -> Self {
+ let ast_x = ast_group.x;
+ let ast_y = ast_group.y;
+
+ Self {
+ x: GroupCoordinate::from(ast_x),
+ y: GroupCoordinate::from(ast_y),
+ span: Span::from(ast_group.span),
+ }
+ }
+}
+
+impl fmt::Display for GroupTuple {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "({}, {})", self.x, self.y)
}