mirror of
https://github.com/AleoHQ/leo.git
synced 2025-01-01 14:28:52 +03:00
mutable self wip
This commit is contained in:
parent
c89decbbf5
commit
59570002f2
@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{access::AssigneeAccess, ast::Rule, common::Identifier, SpanDef};
|
||||
use crate::{access::AssigneeAccess, ast::Rule, common::KeywordOrIdentifier, SpanDef};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
@ -24,7 +24,7 @@ use std::fmt;
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::assignee))]
|
||||
pub struct Assignee<'ast> {
|
||||
pub identifier: Identifier<'ast>,
|
||||
pub name: KeywordOrIdentifier<'ast>,
|
||||
pub accesses: Vec<AssigneeAccess<'ast>>,
|
||||
#[pest_ast(outer())]
|
||||
#[serde(with = "SpanDef")]
|
||||
@ -33,7 +33,7 @@ pub struct Assignee<'ast> {
|
||||
|
||||
impl<'ast> fmt::Display for Assignee<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.identifier)?;
|
||||
write!(f, "{}", self.name)?;
|
||||
for (i, access) in self.accesses.iter().enumerate() {
|
||||
write!(f, "{}", access)?;
|
||||
if i < self.accesses.len() - 1 {
|
||||
|
43
ast/src/common/keyword_or_identifier.rs
Normal file
43
ast/src/common/keyword_or_identifier.rs
Normal file
@ -0,0 +1,43 @@
|
||||
// Copyright (C) 2019-2020 Aleo Systems Inc.
|
||||
// This file is part of the Leo library.
|
||||
|
||||
// The Leo library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// The Leo library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{
|
||||
ast::Rule,
|
||||
common::{Identifier, SelfKeyword},
|
||||
functions::InputKeyword,
|
||||
};
|
||||
|
||||
use pest_ast::FromPest;
|
||||
use serde::Serialize;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::keyword_or_identifier))]
|
||||
pub enum KeywordOrIdentifier<'ast> {
|
||||
SelfKeyword(SelfKeyword<'ast>),
|
||||
Input(InputKeyword<'ast>),
|
||||
Identifier(Identifier<'ast>),
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for KeywordOrIdentifier<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
KeywordOrIdentifier::SelfKeyword(self_keyword) => write!(f, "{}", self_keyword),
|
||||
KeywordOrIdentifier::Input(input_keyword) => write!(f, "{}", input_keyword),
|
||||
KeywordOrIdentifier::Identifier(identifier) => write!(f, "{}", identifier),
|
||||
}
|
||||
}
|
||||
}
|
@ -26,6 +26,9 @@ pub use eoi::*;
|
||||
pub mod identifier;
|
||||
pub use identifier::*;
|
||||
|
||||
pub mod keyword_or_identifier;
|
||||
pub use keyword_or_identifier::*;
|
||||
|
||||
pub mod line_end;
|
||||
pub use line_end::*;
|
||||
|
||||
|
@ -22,6 +22,7 @@ use crate::{
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
use serde::Serialize;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::self_keyword))]
|
||||
@ -32,3 +33,9 @@ pub struct SelfKeyword<'ast> {
|
||||
#[serde(with = "SpanDef")]
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for SelfKeyword<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.keyword)
|
||||
}
|
||||
}
|
||||
|
@ -14,13 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{
|
||||
access::Access,
|
||||
ast::Rule,
|
||||
common::{Identifier, SelfKeyword},
|
||||
functions::InputKeyword,
|
||||
SpanDef,
|
||||
};
|
||||
use crate::{access::Access, ast::Rule, common::KeywordOrIdentifier, SpanDef};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
@ -35,11 +29,3 @@ pub struct PostfixExpression<'ast> {
|
||||
#[serde(with = "SpanDef")]
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::keyword_or_identifier))]
|
||||
pub enum KeywordOrIdentifier<'ast> {
|
||||
SelfKeyword(SelfKeyword<'ast>),
|
||||
Input(InputKeyword<'ast>),
|
||||
Identifier(Identifier<'ast>),
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ use crate::{
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
use serde::Serialize;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::input_keyword))]
|
||||
@ -32,3 +33,9 @@ pub struct InputKeyword<'ast> {
|
||||
#[serde(with = "SpanDef")]
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for InputKeyword<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.keyword)
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/// Common
|
||||
|
||||
// Declared in common/assignee.rs
|
||||
assignee = { identifier ~ access_assignee* }
|
||||
assignee = { keyword_or_identifier ~ access_assignee* }
|
||||
|
||||
// Declared in files/file.rs
|
||||
file = { SOI ~ NEWLINE* ~ definition* ~ NEWLINE* ~ EOI }
|
||||
|
@ -79,8 +79,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
span,
|
||||
),
|
||||
Assignee::Tuple(_tuple, index) => self.assign_tuple(cs, indicator, variable_name, index, new_value, span),
|
||||
Assignee::CircuitField(_assignee, object_name) => {
|
||||
self.mutute_circuit_variable(cs, indicator, variable_name, object_name, new_value, span)
|
||||
Assignee::CircuitField(_assignee, circuit_variable) => {
|
||||
self.mutute_circuit_variable(cs, indicator, variable_name, circuit_variable, new_value, span)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
use crate::{Expression, Identifier, RangeOrExpression};
|
||||
use leo_ast::{
|
||||
access::AssigneeAccess as AstAssigneeAccess,
|
||||
common::{Assignee as AstAssignee, Identifier as AstIdentifier},
|
||||
common::{Assignee as AstAssignee, Identifier as AstIdentifier, KeywordOrIdentifier},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -38,9 +38,15 @@ impl<'ast> From<AstIdentifier<'ast>> for Assignee {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> From<KeywordOrIdentifier<'ast>> for Assignee {
|
||||
fn from(name: KeywordOrIdentifier<'ast>) -> Self {
|
||||
Assignee::Identifier(Identifier::from(name))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> From<AstAssignee<'ast>> for Assignee {
|
||||
fn from(assignee: AstAssignee<'ast>) -> Self {
|
||||
let variable = Assignee::from(assignee.identifier);
|
||||
let variable = Assignee::from(assignee.name);
|
||||
|
||||
// We start with the id, and we fold the array of accesses by wrapping the current value
|
||||
assignee
|
||||
|
@ -23,8 +23,8 @@ use leo_ast::{
|
||||
use leo_input::common::Identifier as InputAstIdentifier;
|
||||
|
||||
use leo_ast::{
|
||||
common::SelfKeyword,
|
||||
expressions::{CircuitName, KeywordOrIdentifier},
|
||||
common::{KeywordOrIdentifier, SelfKeyword},
|
||||
expressions::CircuitName,
|
||||
functions::InputKeyword,
|
||||
types::SelfType,
|
||||
};
|
||||
|
@ -362,7 +362,7 @@ impl<'ast> From<AstExpression<'ast>> for Expression {
|
||||
// Assignee -> Expression for operator assign statements
|
||||
impl<'ast> From<Assignee<'ast>> for Expression {
|
||||
fn from(assignee: Assignee<'ast>) -> Self {
|
||||
let variable = Expression::Identifier(Identifier::from(assignee.identifier));
|
||||
let variable = Expression::Identifier(Identifier::from(assignee.name));
|
||||
|
||||
// we start with the id, and we fold the array of accesses by wrapping the current value
|
||||
assignee
|
||||
|
Loading…
Reference in New Issue
Block a user