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:
+2
-2
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user