diff --git a/ast/src/common/input_keyword.rs b/ast/src/common/input_keyword.rs index cc9d167861..e0cae2d4d5 100644 --- a/ast/src/common/input_keyword.rs +++ b/ast/src/common/input_keyword.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Node, Span}; +use crate::{Identifier, Node, Span}; use serde::{Deserialize, Serialize}; use std::fmt; @@ -22,8 +22,9 @@ use std::fmt; /// The `input` keyword can view program register, record, and state values. /// Values cannot be modified. The `input` keyword cannot be made mutable. #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +#[serde(transparent)] pub struct InputKeyword { - pub span: Span, + pub ident: Identifier, } impl fmt::Display for InputKeyword { @@ -34,10 +35,10 @@ impl fmt::Display for InputKeyword { impl Node for InputKeyword { fn span(&self) -> &Span { - &self.span + &self.ident.span } fn set_span(&mut self, span: Span) { - self.span = span; + self.ident.span = span; } } diff --git a/ast/src/common/mut_self_keyword.rs b/ast/src/common/mut_self_keyword.rs index 34de7c9921..e5cb3f1d5b 100644 --- a/ast/src/common/mut_self_keyword.rs +++ b/ast/src/common/mut_self_keyword.rs @@ -14,15 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Node, Span}; +use crate::{Identifier, Node, Span}; use serde::{Deserialize, Serialize}; use std::fmt; /// The `mut self` keyword can view and modify circuit values inside of a circuit function. #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +#[serde(transparent)] pub struct MutSelfKeyword { - pub span: Span, + pub ident: Identifier, } impl fmt::Display for MutSelfKeyword { @@ -33,10 +34,10 @@ impl fmt::Display for MutSelfKeyword { impl Node for MutSelfKeyword { fn span(&self) -> &Span { - &self.span + &self.ident.span } fn set_span(&mut self, span: Span) { - self.span = span; + self.ident.span = span; } } diff --git a/ast/src/common/self_keyword.rs b/ast/src/common/self_keyword.rs index ba92db2160..5b80b97ac6 100644 --- a/ast/src/common/self_keyword.rs +++ b/ast/src/common/self_keyword.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Node, Span}; +use crate::{Identifier, Node, Span}; use serde::{Deserialize, Serialize}; use std::fmt; @@ -22,8 +22,9 @@ use std::fmt; /// The `self` keyword can view circuit values inside of a circuit function. /// Circuit values cannot be modified. To modify values use the `mut self` [MutSelfKeyword]. #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +#[serde(transparent)] pub struct SelfKeyword { - pub span: Span, + pub ident: Identifier, } impl fmt::Display for SelfKeyword { @@ -34,10 +35,10 @@ impl fmt::Display for SelfKeyword { impl Node for SelfKeyword { fn span(&self) -> &Span { - &self.span + &self.ident.span } fn set_span(&mut self, span: Span) { - self.span = span; + self.ident.span = span; } } diff --git a/ast/src/functions/input/input_variable.rs b/ast/src/functions/input/input_variable.rs index f342cb3e1b..66116f4988 100644 --- a/ast/src/functions/input/input_variable.rs +++ b/ast/src/functions/input/input_variable.rs @@ -96,9 +96,9 @@ impl Node for FunctionInput { fn span(&self) -> &Span { use FunctionInput::*; match self { - InputKeyword(keyword) => &keyword.span, - SelfKeyword(keyword) => &keyword.span, - MutSelfKeyword(keyword) => &keyword.span, + InputKeyword(keyword) => &keyword.ident.span, + SelfKeyword(keyword) => &keyword.ident.span, + MutSelfKeyword(keyword) => &keyword.ident.span, Variable(variable) => &variable.span, } } @@ -106,9 +106,9 @@ impl Node for FunctionInput { fn set_span(&mut self, span: Span) { use FunctionInput::*; match self { - InputKeyword(keyword) => keyword.span = span, - SelfKeyword(keyword) => keyword.span = span, - MutSelfKeyword(keyword) => keyword.span = span, + InputKeyword(keyword) => keyword.ident.span = span, + SelfKeyword(keyword) => keyword.ident.span = span, + MutSelfKeyword(keyword) => keyword.ident.span = span, Variable(variable) => variable.span = span, } } diff --git a/parser/src/parser/file.rs b/parser/src/parser/file.rs index 36dca63852..4d19a782e8 100644 --- a/parser/src/parser/file.rs +++ b/parser/src/parser/file.rs @@ -309,11 +309,16 @@ impl ParserContext { /// pub fn parse_function_input(&mut self) -> SyntaxResult { if let Some(token) = self.eat(Token::Input) { - return Ok(FunctionInput::InputKeyword(InputKeyword { span: token.span })); + return Ok(FunctionInput::InputKeyword(InputKeyword { + ident: Identifier { + name: token.token.to_string(), + span: token.span, + }, + })); } let const_ = self.eat(Token::Const); let mutable = self.eat(Token::Mut); - let name = if let Some(token) = self.eat(Token::LittleSelf) { + let mut name = if let Some(token) = self.eat(Token::LittleSelf) { Identifier { name: token.token.to_string(), span: token.span, @@ -326,11 +331,11 @@ impl ParserContext { //error } if let Some(mutable) = &mutable { - return Ok(FunctionInput::MutSelfKeyword(MutSelfKeyword { - span: &mutable.span + &name.span, - })); + name.span = &mutable.span + &name.span; + name.name = "mut self".to_string(); + return Ok(FunctionInput::MutSelfKeyword(MutSelfKeyword { ident: name })); } - return Ok(FunctionInput::SelfKeyword(SelfKeyword { span: name.span })); + return Ok(FunctionInput::SelfKeyword(SelfKeyword { ident: name })); } self.expect(Token::Colon)?; let type_ = self.parse_type()?.0;