Skip to content

Commit

Permalink
Some renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
vhiribarren committed Mar 17, 2023
1 parent e8abe85 commit 29ecfc1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/ast.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#[derive(Debug)]
pub enum TopAST {
FunctionAST(FunctionAST),
PrototypeAST(PrototypeAST),
Function(FunctionAST),
Prototype(PrototypeAST),
}

#[derive(Debug)]
pub enum ExprAST {
NumberExprAST(NumberExprAST),
VariableExprAST(VariableExprAST),
BinaryExprAST(BinaryExprAST),
CallExprAST(CallExprAST),
NumberExpr(NumberExprAST),
VariableExpr(VariableExprAST),
BinaryExpr(BinaryExprAST),
CallExpr(CallExprAST),
}

#[derive(Debug)]
Expand Down
14 changes: 7 additions & 7 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ impl<'a> Parser<'a> {
let mut result = vec![];
loop {
match self.peek_token() {
Token::Def => result.push(TopAST::FunctionAST(self.parse_definition()?)),
Token::Extern => result.push(TopAST::PrototypeAST(self.parse_extern()?)),
Token::Def => result.push(TopAST::Function(self.parse_definition()?)),
Token::Extern => result.push(TopAST::Prototype(self.parse_extern()?)),
Token::Op(';') => {
self.consume_token();
}
Token::EoF => return Ok(result),
_ => result.push(TopAST::FunctionAST(self.parse_top_level_expression()?)),
_ => result.push(TopAST::Function(self.parse_top_level_expression()?)),
};
}
}
Expand Down Expand Up @@ -97,7 +97,7 @@ impl<'a> Parser<'a> {
rhs = self.parse_bin_op_rhs(tok_prec + 1, rhs)?;
}
}
lhs = ExprAST::BinaryExprAST(BinaryExprAST {
lhs = ExprAST::BinaryExpr(BinaryExprAST {
op,
lhs: Box::new(lhs),
rhs: Box::new(rhs),
Expand All @@ -107,7 +107,7 @@ impl<'a> Parser<'a> {

fn parse_number_expr(&mut self) -> Result<ExprAST> {
match self.consume_token() {
Token::Number(val) => Ok(ExprAST::NumberExprAST(NumberExprAST { val })),
Token::Number(val) => Ok(ExprAST::NumberExpr(NumberExprAST { val })),
_ => bail!("Was waiting for a Token::Number"),
}
}
Expand All @@ -127,7 +127,7 @@ impl<'a> Parser<'a> {
_ => bail!("Was waiting for a Token::Identifier"),
};
if !matches!(self.peek_token(), Token::Op('(')) {
return Ok(ExprAST::VariableExprAST(VariableExprAST { name }));
return Ok(ExprAST::VariableExpr(VariableExprAST { name }));
}
let mut args = vec![];
if !matches!(self.consume_token(), Token::Op(')')) {
Expand All @@ -143,7 +143,7 @@ impl<'a> Parser<'a> {
}
}
self.consume_token();
Ok(ExprAST::CallExprAST(CallExprAST { callee: name, args }))
Ok(ExprAST::CallExpr(CallExprAST { callee: name, args }))
}

fn parse_prototype(&mut self) -> Result<PrototypeAST> {
Expand Down

0 comments on commit 29ecfc1

Please sign in to comment.