Skip to content

Commit

Permalink
implement parsing for most statements
Browse files Browse the repository at this point in the history
  • Loading branch information
andogq committed Aug 31, 2024
1 parent 4fe15db commit 4e528db
Show file tree
Hide file tree
Showing 8 changed files with 628 additions and 295 deletions.
294 changes: 0 additions & 294 deletions src/hir/statement.rs

This file was deleted.

61 changes: 61 additions & 0 deletions src/hir/statement/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
mod s_break;
mod s_continue;
mod s_expression;
mod s_let;
mod s_return;

use super::*;

pub use self::{
s_break::Break, s_continue::Continue, s_expression::ExpressionStatement, s_let::Let,
s_return::Return,
};

ast_node! {
Statement<M>(
Return,
Let,
ExpressionStatement,
Break,
Continue,
)
}

impl SolveType for Statement<UntypedAstMetadata> {
type State = Scope;

fn solve(
self,
compiler: &mut Compiler,
state: &mut Self::State,
) -> Result<Self::Typed, TyError> {
Ok(match self {
Statement::Return(s) => Statement::Return(s.solve(compiler, state)?),
Statement::Let(s) => Statement::Let(s.solve(compiler, state)?),
Statement::ExpressionStatement(s) => {
Statement::ExpressionStatement(s.solve(compiler, state)?)
}
Statement::Break(s) => Statement::Break(s.solve(compiler, state)?),
Statement::Continue(s) => Statement::Continue(s.solve(compiler, state)?),
})
}
}

impl<M: AstMetadata<TyInfo: Default>> Statement<M> {
pub fn _return(expression: Expression<M>, span: M::Span) -> Self {
Self::Return(Return::new(expression, span, M::TyInfo::default()))
}

pub fn _let(name: M::IdentIdentifier, value: Expression<M>, span: M::Span) -> Self {
Self::Let(Let::new(name, value, span, M::TyInfo::default()))
}

pub fn expression(expression: Expression<M>, implicit_return: bool, span: M::Span) -> Self {
Self::ExpressionStatement(ExpressionStatement::new(
expression,
implicit_return,
span,
M::TyInfo::default(),
))
}
}
Loading

0 comments on commit 4e528db

Please sign in to comment.