mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-10-26 07:00:35 +03:00
Migrate assignee
This commit is contained in:
parent
6d9d92dcaf
commit
eb5c3864a7
@ -52,30 +52,6 @@ lazy_static! {
|
||||
static ref PRECEDENCE_CLIMBER: PrecClimber<Rule> = precedence_climber();
|
||||
}
|
||||
|
||||
// Access
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq)]
|
||||
#[pest_ast(rule(Rule::assignee))]
|
||||
pub struct Assignee<'ast> {
|
||||
pub identifier: Identifier<'ast>,
|
||||
pub accesses: Vec<AssigneeAccess<'ast>>,
|
||||
#[pest_ast(outer())]
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for Assignee<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.identifier)?;
|
||||
for (i, access) in self.accesses.iter().enumerate() {
|
||||
write!(f, "{}", access)?;
|
||||
if i < self.accesses.len() - 1 {
|
||||
write!(f, ", ")?;
|
||||
}
|
||||
}
|
||||
write!(f, "")
|
||||
}
|
||||
}
|
||||
|
||||
// Expressions
|
||||
|
||||
fn precedence_climber() -> PrecClimber<Rule> {
|
||||
|
27
ast/src/common/assignee.rs
Normal file
27
ast/src/common/assignee.rs
Normal file
@ -0,0 +1,27 @@
|
||||
use crate::{access::AssigneeAccess, ast::Rule, common::Identifier, types::Type};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq)]
|
||||
#[pest_ast(rule(Rule::assignee))]
|
||||
pub struct Assignee<'ast> {
|
||||
pub identifier: Identifier<'ast>,
|
||||
pub accesses: Vec<AssigneeAccess<'ast>>,
|
||||
#[pest_ast(outer())]
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for Assignee<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.identifier)?;
|
||||
for (i, access) in self.accesses.iter().enumerate() {
|
||||
write!(f, "{}", access)?;
|
||||
if i < self.accesses.len() - 1 {
|
||||
write!(f, ", ")?;
|
||||
}
|
||||
}
|
||||
write!(f, "")
|
||||
}
|
||||
}
|
@ -1,3 +1,6 @@
|
||||
pub mod assignee;
|
||||
pub use assignee::*;
|
||||
|
||||
pub mod identifier;
|
||||
pub use identifier::*;
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
/// Common
|
||||
|
||||
// Declared in common/assignee.rs
|
||||
assignee = { identifier ~ access_assignee* }
|
||||
|
||||
// Declared in common/identifier.rs
|
||||
identifier = @{ ((!protected_name ~ ASCII_ALPHA) | (protected_name ~ (ASCII_ALPHANUMERIC | "_"))) ~ (ASCII_ALPHANUMERIC | "_")* }
|
||||
protected_name = { visibility | "let" | "for"| "if" | "else" | "as" | "return" }
|
||||
@ -161,8 +164,6 @@ access_member = { "." ~ identifier }
|
||||
// Declared in access/static_member_access.rs
|
||||
access_static_member = { "::" ~ identifier }
|
||||
|
||||
assignee = { identifier ~ access_assignee* }
|
||||
|
||||
/// Circuits
|
||||
|
||||
// Declared in circuits/circuit_definition.rs
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{ast::{Rule, LineEnd, Assignee}, expressions::Expression, operations::AssignOperation};
|
||||
use crate::{ast::{Rule, LineEnd}, common::Assignee, expressions::Expression, operations::AssignOperation};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
|
@ -15,6 +15,7 @@ use leo_ast::{
|
||||
CircuitMember
|
||||
},
|
||||
common::{
|
||||
Assignee,
|
||||
Identifier,
|
||||
RangeOrExpression as AstRangeOrExpression,
|
||||
SpreadOrExpression as AstSpreadOrExpression,
|
||||
@ -433,9 +434,9 @@ impl<'ast> types::Expression {
|
||||
}
|
||||
}
|
||||
|
||||
// ast::Assignee -> types::Expression for operator assign statements
|
||||
impl<'ast> From<ast::Assignee<'ast>> for types::Expression {
|
||||
fn from(assignee: ast::Assignee<'ast>) -> Self {
|
||||
// Assignee -> types::Expression for operator assign statements
|
||||
impl<'ast> From<Assignee<'ast>> for types::Expression {
|
||||
fn from(assignee: Assignee<'ast>) -> Self {
|
||||
let variable = types::Expression::Identifier(types::Identifier::from(assignee.identifier));
|
||||
|
||||
// we start with the id, and we fold the array of accesses by wrapping the current value
|
||||
@ -465,8 +466,8 @@ impl<'ast> From<Identifier<'ast>> for types::Assignee {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> From<ast::Assignee<'ast>> for types::Assignee {
|
||||
fn from(assignee: ast::Assignee<'ast>) -> Self {
|
||||
impl<'ast> From<Assignee<'ast>> for types::Assignee {
|
||||
fn from(assignee: Assignee<'ast>) -> Self {
|
||||
let variable = types::Assignee::from(assignee.identifier);
|
||||
|
||||
// we start with the id, and we fold the array of accesses by wrapping the current value
|
||||
|
Loading…
Reference in New Issue
Block a user