diff --git a/ast/src/access/access.rs b/ast/src/access/access.rs index 77e95a0603..44741af5c2 100644 --- a/ast/src/access/access.rs +++ b/ast/src/access/access.rs @@ -7,6 +7,7 @@ use serde::Serialize; #[pest_ast(rule(Rule::access))] pub enum Access<'ast> { Array(ArrayAccess<'ast>), + Tuple(TupleAccess<'ast>), Call(CallAccess<'ast>), Object(MemberAccess<'ast>), StaticObject(StaticMemberAccess<'ast>), diff --git a/ast/src/access/assignee_access.rs b/ast/src/access/assignee_access.rs index 6ae0b7f305..a68123783c 100644 --- a/ast/src/access/assignee_access.rs +++ b/ast/src/access/assignee_access.rs @@ -1,5 +1,5 @@ use crate::{ - access::{ArrayAccess, MemberAccess}, + access::{ArrayAccess, MemberAccess, TupleAccess}, ast::Rule, }; @@ -11,6 +11,7 @@ use std::fmt; #[pest_ast(rule(Rule::access_assignee))] pub enum AssigneeAccess<'ast> { Array(ArrayAccess<'ast>), + Tuple(TupleAccess<'ast>), Member(MemberAccess<'ast>), } @@ -18,6 +19,7 @@ impl<'ast> fmt::Display for AssigneeAccess<'ast> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { AssigneeAccess::Array(ref array) => write!(f, "[{}]", array.expression), + AssigneeAccess::Tuple(ref tuple) => write!(f, ".{}", tuple.number), AssigneeAccess::Member(ref member) => write!(f, ".{}", member.identifier), } } diff --git a/ast/src/access/mod.rs b/ast/src/access/mod.rs index 2912632030..cdb435a4f3 100644 --- a/ast/src/access/mod.rs +++ b/ast/src/access/mod.rs @@ -15,3 +15,6 @@ pub use member_access::*; pub mod static_member_access; pub use static_member_access::*; + +pub mod tuple_access; +pub use tuple_access::*; diff --git a/ast/src/access/tuple_access.rs b/ast/src/access/tuple_access.rs new file mode 100644 index 0000000000..428e0c09fc --- /dev/null +++ b/ast/src/access/tuple_access.rs @@ -0,0 +1,14 @@ +use crate::{ast::Rule, values::PositiveNumber, SpanDef}; + +use pest::Span; +use pest_ast::FromPest; +use serde::Serialize; + +#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] +#[pest_ast(rule(Rule::access_tuple))] +pub struct TupleAccess<'ast> { + pub number: PositiveNumber<'ast>, + #[pest_ast(outer())] + #[serde(with = "SpanDef")] + pub span: Span<'ast>, +} diff --git a/ast/src/leo.pest b/ast/src/leo.pest index 260f83f87d..8ab50cfbec 100644 --- a/ast/src/leo.pest +++ b/ast/src/leo.pest @@ -249,13 +249,16 @@ value_address = ${ type_address ~ "(" ~ address ~ ")" } /// Access // Declared in access/access.rs -access = { access_array | access_call | access_member | access_static_member} +access = { access_array | access_tuple | access_call | access_member | access_static_member} // Declared in access/array_access.rs access_array = !{ "[" ~ range_or_expression ~ "]" } +// Declared in access/tuple_access.rs +access_tuple = ${ "." ~ number_positive } + // Declared in access/assignee_access.rs -access_assignee = { access_array | access_member } +access_assignee = { access_array | access_tuple | access_member } // Declared in access/call_access.rs access_call = !{ expression_tuple }