From 1079d53f052a97ea29f7aa6ce88ca2ad057b927e Mon Sep 17 00:00:00 2001 From: Natapat Samutpong Date: Sat, 12 Mar 2022 07:35:16 +0700 Subject: [PATCH] fix comment syntax --- crates/lexer/src/lib.rs | 4 +--- crates/main/src/main.rs | 16 ++++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/crates/lexer/src/lib.rs b/crates/lexer/src/lib.rs index 0b444c6..55e8252 100644 --- a/crates/lexer/src/lib.rs +++ b/crates/lexer/src/lib.rs @@ -111,9 +111,7 @@ pub fn lexer() -> impl Parser, Error = Simple> { .or(keyword) .recover_with(skip_then_retry_until([])); - let comment = just("--") - .ignore_then(filter(|c| *c != '\n').repeated()) - .then_ignore(just('\n')); + let comment = just("--").then(take_until(just('\n'))).padded(); token .padded_by(comment.repeated()) diff --git a/crates/main/src/main.rs b/crates/main/src/main.rs index a9e9085..a454f08 100644 --- a/crates/main/src/main.rs +++ b/crates/main/src/main.rs @@ -64,6 +64,7 @@ fn main() { for err in lex_error { diagnostics.add_lex_error(err); } for err in parse_error { diagnostics.add_parse_error(err); } + // Report syntax errors if any if diagnostics.has_error() { diagnostics.display(src); logif!(0, "Epic parsing fail"); @@ -77,6 +78,8 @@ fn main() { // Convert the AST to HIR let (ir, lowering_error) = ast_to_ir(ast); for err in lowering_error { diagnostics.add_lowering_error(err); } + + // Report lowering errors if any if diagnostics.has_error() { diagnostics.display(src); logif!(0, "Epic Lowering(HIR) fail"); @@ -98,17 +101,18 @@ fn main() { let mut file = fs::File::create(&output_path).expect("Failed to create file"); file.write_all(codegen.emitted.as_bytes()).expect("Failed to write to file"); - // End timer - let duration = start.elapsed().as_millis(); - - logif!(0, format!("Compilation took {}ms", duration)); - logif!(0, format!("Wrote output to `{}`", output_path.display())); - + // Compile the generate code let compiler = &config.compiler.compiler; Command::new(compiler) .arg(&output_path) .spawn() .expect("Failed to run compiler"); + + // End timer + let duration = start.elapsed().as_millis(); + + logif!(0, format!("Compilation took {}ms", duration)); + logif!(0, format!("Wrote output to `{}`", output_path.display())); }, None => { unreachable!(); } }