add repl support for parse errors

This commit is contained in:
Folkert 2021-02-08 21:09:53 +01:00
parent 523df61622
commit 09b3d40380
2 changed files with 47 additions and 3 deletions

View file

@ -7,6 +7,7 @@ use roc_collections::all::{MutMap, MutSet};
use roc_fmt::annotation::Formattable; use roc_fmt::annotation::Formattable;
use roc_fmt::annotation::{Newlines, Parens}; use roc_fmt::annotation::{Newlines, Parens};
use roc_gen::llvm::build::{build_proc, build_proc_header, OptLevel}; use roc_gen::llvm::build::{build_proc, build_proc_header, OptLevel};
use roc_load::file::LoadingProblem;
use roc_parse::parser::SyntaxError; use roc_parse::parser::SyntaxError;
use roc_types::pretty_print::{content_to_string, name_all_type_vars}; use roc_types::pretty_print::{content_to_string, name_all_type_vars};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -52,7 +53,15 @@ pub fn gen_and_eval<'a>(
ptr_bytes, ptr_bytes,
); );
let mut loaded = loaded.expect("failed to load module"); let mut loaded = match loaded {
Ok(v) => v,
Err(LoadingProblem::ParsingFailedReport(report)) => {
return Ok(ReplOutput::Problems(vec![report]));
}
Err(e) => {
panic!("error while loading module: {:?}", e)
}
};
use roc_load::file::MonomorphizedModule; use roc_load::file::MonomorphizedModule;
let MonomorphizedModule { let MonomorphizedModule {

View file

@ -108,7 +108,7 @@ fn to_type_report<'a>(
Type::TRecord(record, row, col) => { Type::TRecord(record, row, col) => {
to_trecord_report(alloc, filename, starting_line, record, row, col) to_trecord_report(alloc, filename, starting_line, record, row, col)
} }
_ => todo!(), _ => todo!("unhandled type parse error: {:?}", &parse_problem),
} }
} }
@ -157,6 +157,41 @@ fn to_trecord_report<'a>(
} }
} }
_ => todo!(), TRecord::IndentEnd(row, col) => {
// TODO check whether next character is a `}`
let surroundings = Region {
start_col,
start_line: start_row,
end_col: col,
end_line: row,
};
let region = Region {
start_col: col,
start_line: row,
end_col: col,
end_line: row,
};
let doc = alloc.stack(vec![
alloc.reflow("I am partway through parsing a record type, but I got stuck here:"),
alloc.region_with_subregion(surroundings, region),
alloc.concat(vec![
alloc.reflow(
r"I was expecting to see a closing curly brace before this, so try adding a ",
),
alloc.parser_suggestion("}"),
alloc.reflow(" and see if that helps?"),
]),
]);
Report {
filename: filename.clone(),
doc,
title: "UNFINISHED RECORD TYPE".to_string(),
}
}
_ => todo!("unhandled record type parse error: {:?}", &parse_problem),
} }
} }