Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
DaviRain-Su committed May 31, 2024
1 parent 0f1373b commit 1d0d9d7
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/ast/expression/if_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ impl If {
&mut self.consequence
}

pub fn condition_mut(&mut self) -> &mut Box<Expression> {
&mut self.condition
pub fn update_expression(&mut self, expression: Expression) {
self.condition = Box::new(expression);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ast/expression/infix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ impl Infix {
&self.right
}

pub fn right_mut(&mut self) -> &mut Box<Expression> {
&mut self.right
pub fn update_expression(&mut self, right: Expression) {
self.right = Box::new(right);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ast/expression/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ impl IntegerLiteral {
self.value
}

pub fn value_mut(&mut self) -> &mut isize {
&mut self.value
pub fn update_value(&mut self, value: isize) {
self.value = value;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ast/expression/prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ impl Prefix {
&self.right
}

pub fn right_mut(&mut self) -> &mut Box<Expression> {
&mut self.right
pub fn update_expression(&mut self, expression: Expression) {
self.right = Box::new(expression);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ast/statement/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ impl ExpressionStatement {
&self.expression
}

pub fn expression_mut(&mut self) -> &mut Expression {
&mut self.expression
pub fn update_expression(&mut self, expression: Expression) {
self.expression = expression;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/ast/statement/let_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ impl LetStatement {
&self.value
}

pub fn value_mut(&mut self) -> &mut Expression {
&mut self.value
pub fn update_expression(&mut self, value: Expression) {
self.value = Box::new(value);
}

pub fn name(&self) -> &Identifier {
&self.name
}

pub fn name_mut(&mut self) -> &mut Identifier {
&mut self.name
pub fn update_identifier(&mut self, name: Identifier) {
self.name = name;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ast/statement/return_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ impl ReturnStatement {
&self.return_value
}

pub fn return_value_mut(&mut self) -> &mut Box<Expression> {
&mut self.return_value
pub fn update_expression(&mut self, expression: Expression) {
self.return_value = Box::new(expression);
}

pub fn return_value_into(self) -> Expression {
Expand Down
18 changes: 9 additions & 9 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ impl<'a> Parser<'a> {
}
.into());
}
*stmt.name_mut() = Identifier::new(
stmt.update_identifier(Identifier::new(
self.current_token.clone(),
self.current_token.literal().into(),
);
));
tracing::trace!("stmt = {stmt}");
if self.expect_peek(TokenType::ASSIGN).is_err() {
return Err(Error::CannotFindTokenType {
Expand All @@ -183,7 +183,7 @@ impl<'a> Parser<'a> {
.into());
}
self.next_token()?;
*stmt.value_mut() = self.parse_expression(LOWEST)?;
stmt.update_expression(self.parse_expression(LOWEST)?);
while !self.cur_token_is(TokenType::SEMICOLON) {
self.next_token()?;
}
Expand All @@ -198,7 +198,7 @@ impl<'a> Parser<'a> {
let mut stmt = ReturnStatement::new(self.current_token.clone());
self.next_token()?;
// add equal expression
*stmt.return_value_mut() = self.parse_expression(LOWEST)?.into();
stmt.update_expression(self.parse_expression(LOWEST)?.into());
while !self.cur_token_is(TokenType::SEMICOLON) {
self.next_token()?;
}
Expand All @@ -213,7 +213,7 @@ impl<'a> Parser<'a> {
tracing::trace!("current_token = {:?}", self.current_token);
let mut stmt = ExpressionStatement::new(self.current_token.clone());
tracing::trace!("before ExpressionStatement = {stmt}");
*stmt.expression_mut() = self.parse_expression(LOWEST)?;
stmt.update_expression(self.parse_expression(LOWEST)?);
if self.peek_token_is(TokenType::SEMICOLON) {
self.next_token()?;
}
Expand Down Expand Up @@ -314,7 +314,7 @@ impl<'a> Parser<'a> {
let mut literal = IntegerLiteral::new(self.current_token.clone());
let value = self.current_token.literal().parse::<isize>()?;

*literal.value_mut() = value;
literal.update_value(value);
Ok(literal.into())
}

Expand All @@ -326,7 +326,7 @@ impl<'a> Parser<'a> {
self.current_token.literal().into(),
);
self.next_token()?;
*expression.right_mut() = Box::new(self.parse_expression(PREFIX)?);
expression.update_expression(self.parse_expression(PREFIX)?);
Ok(expression.into())
}

Expand All @@ -345,7 +345,7 @@ impl<'a> Parser<'a> {

self.next_token()?;

*expression.right_mut() = Box::new(self.parse_expression(precedence)?);
expression.update_expression(self.parse_expression(precedence)?);

tracing::trace!("after InfixExpression = {expression}");

Expand Down Expand Up @@ -383,7 +383,7 @@ impl<'a> Parser<'a> {

self.next_token()?;

*expression.condition_mut() = Box::new(self.parse_expression(LOWEST)?);
expression.update_expression(self.parse_expression(LOWEST)?);

if self.expect_peek(TokenType::RPAREN).is_err() {
return Err(Error::CannotFindTokenType {
Expand Down

0 comments on commit 1d0d9d7

Please sign in to comment.