mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-02 12:22:08 +03:00
add tuple access to pest
This commit is contained in:
parent
0e00cbc422
commit
0671b36550
@ -7,6 +7,7 @@ use serde::Serialize;
|
|||||||
#[pest_ast(rule(Rule::access))]
|
#[pest_ast(rule(Rule::access))]
|
||||||
pub enum Access<'ast> {
|
pub enum Access<'ast> {
|
||||||
Array(ArrayAccess<'ast>),
|
Array(ArrayAccess<'ast>),
|
||||||
|
Tuple(TupleAccess<'ast>),
|
||||||
Call(CallAccess<'ast>),
|
Call(CallAccess<'ast>),
|
||||||
Object(MemberAccess<'ast>),
|
Object(MemberAccess<'ast>),
|
||||||
StaticObject(StaticMemberAccess<'ast>),
|
StaticObject(StaticMemberAccess<'ast>),
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
access::{ArrayAccess, MemberAccess},
|
access::{ArrayAccess, MemberAccess, TupleAccess},
|
||||||
ast::Rule,
|
ast::Rule,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -11,6 +11,7 @@ use std::fmt;
|
|||||||
#[pest_ast(rule(Rule::access_assignee))]
|
#[pest_ast(rule(Rule::access_assignee))]
|
||||||
pub enum AssigneeAccess<'ast> {
|
pub enum AssigneeAccess<'ast> {
|
||||||
Array(ArrayAccess<'ast>),
|
Array(ArrayAccess<'ast>),
|
||||||
|
Tuple(TupleAccess<'ast>),
|
||||||
Member(MemberAccess<'ast>),
|
Member(MemberAccess<'ast>),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ impl<'ast> fmt::Display for AssigneeAccess<'ast> {
|
|||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
AssigneeAccess::Array(ref array) => write!(f, "[{}]", array.expression),
|
AssigneeAccess::Array(ref array) => write!(f, "[{}]", array.expression),
|
||||||
|
AssigneeAccess::Tuple(ref tuple) => write!(f, ".{}", tuple.number),
|
||||||
AssigneeAccess::Member(ref member) => write!(f, ".{}", member.identifier),
|
AssigneeAccess::Member(ref member) => write!(f, ".{}", member.identifier),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,3 +15,6 @@ pub use member_access::*;
|
|||||||
|
|
||||||
pub mod static_member_access;
|
pub mod static_member_access;
|
||||||
pub use static_member_access::*;
|
pub use static_member_access::*;
|
||||||
|
|
||||||
|
pub mod tuple_access;
|
||||||
|
pub use tuple_access::*;
|
||||||
|
14
ast/src/access/tuple_access.rs
Normal file
14
ast/src/access/tuple_access.rs
Normal file
@ -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>,
|
||||||
|
}
|
@ -249,13 +249,16 @@ value_address = ${ type_address ~ "(" ~ address ~ ")" }
|
|||||||
/// Access
|
/// Access
|
||||||
|
|
||||||
// Declared in access/access.rs
|
// 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
|
// Declared in access/array_access.rs
|
||||||
access_array = !{ "[" ~ range_or_expression ~ "]" }
|
access_array = !{ "[" ~ range_or_expression ~ "]" }
|
||||||
|
|
||||||
|
// Declared in access/tuple_access.rs
|
||||||
|
access_tuple = ${ "." ~ number_positive }
|
||||||
|
|
||||||
// Declared in access/assignee_access.rs
|
// 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
|
// Declared in access/call_access.rs
|
||||||
access_call = !{ expression_tuple }
|
access_call = !{ expression_tuple }
|
||||||
|
Loading…
Reference in New Issue
Block a user