Skip to content

Commit

Permalink
ast: Remove mutability from VarDeclaration
Browse files Browse the repository at this point in the history
  • Loading branch information
CohenArthur committed Nov 13, 2024
1 parent 5917c1e commit 0798716
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 29 deletions.
16 changes: 4 additions & 12 deletions ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ pub enum Node {
else_block: Option<Box<Ast>>,
},
VarDeclaration {
mutable: bool,
to_declare: Symbol,
value: Box<Ast>,
},
Expand Down Expand Up @@ -409,19 +408,14 @@ pub trait Visitor {
fn visit_var_declaration(
&mut self,
location: SpanTuple,
mutable: bool,
to_declare: Symbol,
value: Box<Ast>,
) -> Result<Ast, Error> {
let value = self.boxed(value)?;

Ok(Ast {
location,
node: Node::VarDeclaration {
mutable,
to_declare,
value,
},
node: Node::VarDeclaration { to_declare, value },
})
}

Expand Down Expand Up @@ -503,11 +497,9 @@ pub trait Visitor {
if_block,
else_block,
} => self.visit_if_else(ast.location, if_condition, if_block, else_block),
Node::VarDeclaration {
mutable,
to_declare,
value,
} => self.visit_var_declaration(ast.location, mutable, to_declare, value),
Node::VarDeclaration { to_declare, value } => {
self.visit_var_declaration(ast.location, to_declare, value)
}
Node::VarAssign { to_assign, value } => {
self.visit_var_assign(ast.location, to_assign, value)
}
Expand Down
11 changes: 4 additions & 7 deletions flatten/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,6 @@ impl<'ast> Ctx<'ast> {
fn visit_var_declaration(
self,
ast: AstInfo<'ast>,
_mutable: bool,
_to_declare: &Symbol,
value: &'ast Ast,
) -> (Ctx<'ast>, RefIdx) {
Expand Down Expand Up @@ -900,11 +899,9 @@ impl<'ast> Ctx<'ast> {
if_block,
else_block,
} => self.visit_if_else(node, if_condition, if_block, else_block),
AstNode::VarDeclaration {
mutable,
to_declare,
value,
} => self.visit_var_declaration(node, *mutable, to_declare, value),
AstNode::VarDeclaration { to_declare, value } => {
self.visit_var_declaration(node, to_declare, value)
}
AstNode::VarAssign { to_assign, value } => {
self.visit_var_assign(node, to_assign, value)
}
Expand Down Expand Up @@ -1013,7 +1010,7 @@ mod tests {
fn where_expr() {
let ast = ast! {
where x = 15;
where mut y = x;
where y = x;
};

let fir = ast.flatten();
Expand Down
1 change: 0 additions & 1 deletion loop_desugar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ fn var_declare<S: Into<Symbol>>(loc: &SpanTuple, to_declare: S, value: Box<Ast>)
Ast {
location: loc.clone(),
node: Node::VarDeclaration {
mutable: false,
to_declare: to_declare.into(),
value,
},
Expand Down
6 changes: 1 addition & 5 deletions xparser/src/constructs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ fn method_or_field(
///
/// | 'type' type_id '(' named_args
/// | 'incl' spaced_identifier [ 'as' next IDENTIFIER ]
/// | 'mut' spaced_identifier '=' expr (* mutable variable assigment *)
/// | '@' spaced_identifier '(' args
///
/// | 'extern' 'func' function_declaration ';'
Expand Down Expand Up @@ -617,19 +616,16 @@ fn unit_type_decl(input: ParseInput, start_loc: Location) -> ParseResult<ParseIn
))
}

/// mut? [`spaced_identifier`] '=' expr
/// [`spaced_identifier`] '=' expr
fn unit_var_decl(input: ParseInput) -> ParseResult<ParseInput, Ast> {
let input = next(input);
let (input, mutable) = opt(tokens::mut_tok)(input)?;
let mutable = mutable.is_some();

let (input, (symbol, (start_loc, _))) = spaced_identifier(input)?;
let (input, _) = tokens::equal(input)?;
let (input, value) = expr(input)?;
let (input, end_loc) = position(input)?;

let assignment = Node::VarDeclaration {
mutable,
to_declare: Symbol::from(symbol),
value: Box::new(value),
};
Expand Down
4 changes: 0 additions & 4 deletions xparser/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ pub fn in_tok(input: ParseInput) -> ParseResult<ParseInput, ParseInput> {
specific_token(input, "in")
}

pub fn mut_tok(input: ParseInput) -> ParseResult<ParseInput, ParseInput> {
specific_token(input, "mut")
}

pub fn if_tok(input: ParseInput) -> ParseResult<ParseInput, ParseInput> {
specific_token(input, "if")
}
Expand Down

0 comments on commit 0798716

Please sign in to comment.