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 1d0d9d7 commit da9e740
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/ast/expression/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ impl FunctionLiteral {
&self.body
}

pub fn body_mut(&mut self) -> &mut BlockStatement {
&mut self.body
pub fn update_body(&mut self, body: BlockStatement) {
self.body = body;
}

pub fn parameters(&self) -> &[Identifier] {
Expand Down
8 changes: 4 additions & 4 deletions src/ast/expression/if_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ impl If {
&self.condition
}

pub fn alternative_mut(&mut self) -> &mut Option<BlockStatement> {
&mut self.alternative
pub fn update_alternative(&mut self, alternative: BlockStatement) {
self.alternative = Some(alternative);
}

pub fn consequence_mut(&mut self) -> &mut Option<BlockStatement> {
&mut self.consequence
pub fn update_consequence(&mut self, consequence: BlockStatement) {
self.consequence = Some(consequence);
}

pub fn update_expression(&mut self, expression: Expression) {
Expand Down
4 changes: 2 additions & 2 deletions src/ast/expression/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ impl Index {
&self.index
}

pub fn index_mut(&mut self) -> &mut Box<Expression> {
&mut self.index
pub fn update_index(&mut self, index: Expression) {
self.index = Box::new(index);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ impl<'a> Parser<'a> {
.into());
}

*expression.consequence_mut() = Some(self.parse_block_statement()?);
expression.update_consequence(self.parse_block_statement()?);

if self.peek_token_is(TokenType::ELSE) {
self.next_token()?;
Expand All @@ -411,7 +411,7 @@ impl<'a> Parser<'a> {
.into());
}

*expression.alternative_mut() = Some(self.parse_block_statement()?);
expression.update_alternative(self.parse_block_statement()?);
}

Ok(Expression::If(expression))
Expand Down Expand Up @@ -450,7 +450,7 @@ impl<'a> Parser<'a> {
.into());
}

*lit.body_mut() = self.parse_block_statement()?;
lit.update_body(self.parse_block_statement()?);

Ok(Expression::FunctionLiteral(lit))
}
Expand Down Expand Up @@ -516,7 +516,7 @@ impl<'a> Parser<'a> {

self.next_token()?;

*exp.index_mut() = Box::new(self.parse_expression(LOWEST)?);
exp.update_index(self.parse_expression(LOWEST)?);

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

0 comments on commit da9e740

Please sign in to comment.