Add parse_program to parser

The `Parser` can now parse a sequence of top-level expressions,
representing a complete program. This change modifies the `roundtrip`
function to iterate over these expressions and emit them, allowing for
multi-line program parsing.
This commit is contained in:
2026-03-31 07:55:20 +02:00
parent 9013f262ce
commit dd81482acb
3 changed files with 12 additions and 2 deletions
+2 -2
View File
@@ -186,7 +186,7 @@ impl CompilerApp {
fn roundtrip(&mut self) {
let mut parser = Parser::new(&self.source_code);
let ast = parser.parse_expression();
let expressions = parser.parse_program();
if parser.diagnostics.has_errors() {
let errors: Vec<_> = parser
.diagnostics
@@ -198,7 +198,7 @@ impl CompilerApp {
self.active_tab = AppTab::Output;
return;
}
self.source_code = emitter::emit(&ast);
self.source_code = expressions.iter().map(emitter::emit).collect::<Vec<_>>().join("\n");
self.output_log = "Roundtrip complete — source reformatted.".to_string();
self.active_tab = AppTab::Output;
}