finish porting to new parser

This commit is contained in:
2021-11-01 00:10:40 +01:00
parent 607c3c7a28
commit 02b8ff860b
7 changed files with 1184 additions and 1726 deletions

View File

@@ -6,9 +6,10 @@ mod ast;
mod constfold;
mod emit;
mod parser;
mod parser2;
mod typecheck;
type Span = std::ops::Range<usize>;
fn main() -> Result<()> {
let mut filename = PathBuf::from(
std::env::args()
@@ -18,28 +19,14 @@ fn main() -> Result<()> {
let mut input = String::new();
File::open(&filename)?.read_to_string(&mut input)?;
if let Err(_) = parser2::parse(&input) {
bail!("Parse failed");
}
let mut script = match parser::parse(input.as_str()) {
let mut script = match parser::parse(&input) {
Ok(script) => script,
Err(err) => {
bail!(
"parse error: {}",
nom::error::convert_error(input.as_str(), err)
);
}
Err(_) => bail!("Parse failed")
};
constfold::fold_script(&mut script);
if let Err(err) = typecheck::tc_script(&mut script) {
let line = input[..(input.len() - err.position.0)]
.chars()
.filter(|c| *c == '\n')
.count()
+ 1;
bail!("{} in line {}", err.message, line);
if let Err(_) = typecheck::tc_script(&mut script, &input) {
bail!("Parse failed");
}
let wasm = emit::emit(&script);