mirror of
https://github.com/AleoHQ/leo.git
synced 2024-11-25 13:53:29 +03:00
impl new group notation typed
This commit is contained in:
parent
0226c09e4d
commit
60bf079e33
@ -1,4 +1,4 @@
|
||||
use crate::{CircuitFieldDefinition, Identifier, IntegerType, RangeOrExpression, Span, SpreadOrExpression};
|
||||
use crate::{CircuitFieldDefinition, GroupValue, Identifier, IntegerType, RangeOrExpression, Span, SpreadOrExpression};
|
||||
use leo_ast::{
|
||||
access::{Access, AssigneeAccess},
|
||||
common::{Assignee, Identifier as AstIdentifier},
|
||||
@ -17,7 +17,7 @@ use leo_ast::{
|
||||
AddressValue,
|
||||
BooleanValue,
|
||||
FieldValue,
|
||||
GroupValue,
|
||||
GroupValue as AstGroupValue,
|
||||
IntegerValue,
|
||||
NumberValue as AstNumber,
|
||||
PositiveNumber as AstPositiveNumber,
|
||||
@ -40,7 +40,7 @@ pub enum Expression {
|
||||
Address(String, Span),
|
||||
Boolean(String, Span),
|
||||
Field(String, Span),
|
||||
Group(String, Span),
|
||||
Group(GroupValue),
|
||||
Implicit(String, Span),
|
||||
Integer(IntegerType, String, Span),
|
||||
|
||||
@ -86,7 +86,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(_, old_span) => *old_span = new_span.clone(),
|
||||
Expression::Group(value) => value.span = new_span.clone(),
|
||||
|
||||
Expression::Add(_, _, old_span) => *old_span = new_span.clone(),
|
||||
Expression::Sub(_, _, old_span) => *old_span = new_span.clone(),
|
||||
@ -146,7 +146,7 @@ impl<'ast> fmt::Display for Expression {
|
||||
Expression::Address(ref address, ref _span) => write!(f, "{}", address),
|
||||
Expression::Boolean(ref bool, ref _span) => write!(f, "{}", bool),
|
||||
Expression::Field(ref field, ref _span) => write!(f, "{}", field),
|
||||
Expression::Group(ref group, ref _span) => write!(f, "{}", group),
|
||||
Expression::Group(ref group) => write!(f, "{}", group),
|
||||
Expression::Implicit(ref value, ref _span) => write!(f, "{}", value),
|
||||
Expression::Integer(ref type_, ref integer, ref _span) => write!(f, "{}{}", integer, type_),
|
||||
|
||||
@ -509,9 +509,9 @@ impl<'ast> From<FieldValue<'ast>> for Expression {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> From<GroupValue<'ast>> for Expression {
|
||||
fn from(group: GroupValue<'ast>) -> Self {
|
||||
Expression::Group(group.to_string(), Span::from(group.span))
|
||||
impl<'ast> From<AstGroupValue<'ast>> for Expression {
|
||||
fn from(ast_group: AstGroupValue<'ast>) -> Self {
|
||||
Expression::Group(GroupValue::from(ast_group))
|
||||
}
|
||||
}
|
||||
|
||||
|
68
typed/src/groups/group_coordinate.rs
Normal file
68
typed/src/groups/group_coordinate.rs
Normal file
@ -0,0 +1,68 @@
|
||||
use crate::common::span::Span;
|
||||
use leo_ast::values::{
|
||||
GroupCoordinate as AstGroupCoordinate,
|
||||
Inferred as AstInferred,
|
||||
NumberValue as AstNumberValue,
|
||||
SignHigh as AstSignHigh,
|
||||
SignLow as AstSignLow,
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum GroupCoordinate {
|
||||
Number(String, Span),
|
||||
SignHigh(Span),
|
||||
SignLow(Span),
|
||||
Inferred(Span),
|
||||
}
|
||||
|
||||
impl<'ast> From<AstGroupCoordinate<'ast>> for GroupCoordinate {
|
||||
fn from(coordinate: AstGroupCoordinate<'ast>) -> Self {
|
||||
match coordinate {
|
||||
AstGroupCoordinate::Number(number) => GroupCoordinate::from(number),
|
||||
AstGroupCoordinate::SignHigh(sign_high) => GroupCoordinate::from(sign_high),
|
||||
AstGroupCoordinate::SignLow(sign_low) => GroupCoordinate::from(sign_low),
|
||||
AstGroupCoordinate::Inferred(inferred) => GroupCoordinate::from(inferred),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for GroupCoordinate {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
GroupCoordinate::Number(number, _) => write!(f, "{}", number),
|
||||
GroupCoordinate::SignHigh(_) => write!(f, "+"),
|
||||
GroupCoordinate::SignLow(_) => write!(f, "-"),
|
||||
GroupCoordinate::Inferred(_) => write!(f, "_"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> From<AstNumberValue<'ast>> for GroupCoordinate {
|
||||
fn from(number: AstNumberValue<'ast>) -> Self {
|
||||
let value = number.to_string();
|
||||
let span = Span::from(number.span().clone());
|
||||
|
||||
GroupCoordinate::Number(value, span)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> From<AstSignHigh<'ast>> for GroupCoordinate {
|
||||
fn from(sign: AstSignHigh<'ast>) -> Self {
|
||||
GroupCoordinate::SignHigh(Span::from(sign.span))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> From<AstSignLow<'ast>> for GroupCoordinate {
|
||||
fn from(sign: AstSignLow<'ast>) -> Self {
|
||||
GroupCoordinate::SignLow(Span::from(sign.span))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> From<AstInferred<'ast>> for GroupCoordinate {
|
||||
fn from(sign: AstInferred<'ast>) -> Self {
|
||||
GroupCoordinate::Inferred(Span::from(sign.span))
|
||||
}
|
||||
}
|
31
typed/src/groups/group_value.rs
Normal file
31
typed/src/groups/group_value.rs
Normal file
@ -0,0 +1,31 @@
|
||||
use crate::{common::span::Span, groups::GroupCoordinate};
|
||||
use leo_ast::values::GroupValue as AstGroupValue;
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
impl<'ast> From<AstGroupValue<'ast>> for GroupValue {
|
||||
fn from(ast_group: AstGroupValue<'ast>) -> Self {
|
||||
let ast_x = ast_group.value.x;
|
||||
let ast_y = ast_group.value.y;
|
||||
|
||||
Self {
|
||||
x: GroupCoordinate::from(ast_x),
|
||||
y: GroupCoordinate::from(ast_y),
|
||||
span: Span::from(ast_group.span),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for GroupValue {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "({}, {})", self.x, self.y)
|
||||
}
|
||||
}
|
5
typed/src/groups/mod.rs
Normal file
5
typed/src/groups/mod.rs
Normal file
@ -0,0 +1,5 @@
|
||||
pub mod group_coordinate;
|
||||
pub use self::group_coordinate::*;
|
||||
|
||||
pub mod group_value;
|
||||
pub use self::group_value::*;
|
@ -16,6 +16,9 @@ pub use self::expression::*;
|
||||
pub mod functions;
|
||||
pub use self::functions::*;
|
||||
|
||||
pub mod groups;
|
||||
pub use self::groups::*;
|
||||
|
||||
pub mod imports;
|
||||
pub use self::imports::*;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user