-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement parsing for most statements
- Loading branch information
Showing
8 changed files
with
628 additions
and
295 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
)) | ||
} | ||
} |
Oops, something went wrong.