1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-10-16 02:37:40 -05:00
This commit is contained in:
Natapat Samutpong 2022-03-20 20:25:31 +07:00
parent cf3dccca2c
commit 4e6acf7038
3 changed files with 11 additions and 14 deletions

View file

@ -47,7 +47,6 @@ impl Diagnostics {
_ => None,
});
// TODO: Lowering error
lex_error.into_iter()
.map(|e| e.map(|e| e.to_string()))
.chain(parse_error.into_iter().map(|e| e.map(|tok| tok.to_string())))

View file

@ -40,21 +40,19 @@ pub struct LoweringError {
pub note: Option<String>,
}
impl IR {
pub fn new(kind: IRKind, span: Range<usize>) -> Self {
Self { kind, span }
}
}
pub fn ast_to_ir(ast: Vec<(Expr, Range<usize>)>) -> (Vec<IR>, Vec<LoweringError>) {
let mut irs = Vec::new();
let mut errors = Vec::new();
for expr in ast {
let ir_kind = expr_to_ir(&expr.0);
if let Some(err) = ir_kind.1 {
match ir_kind {
(Some(ir), None) => {
irs.push(IR { kind: ir, span: expr.1 });
},
(None, Some(err)) => {
errors.push(err);
} else {
irs.push(IR::new(ir_kind.0.unwrap(), expr.1));
},
_ => unreachable!(),
}
}
(irs, errors)