diff --git a/src/ast/parser.rs b/src/ast/parser.rs index 284ca10..15ca0e4 100644 --- a/src/ast/parser.rs +++ b/src/ast/parser.rs @@ -119,6 +119,15 @@ impl<'a> Parser<'a> { matches!(self.current_token.kind, TokenKind::EOF) } + /// Parses a complete program as a sequence of top-level expressions. + pub fn parse_program(&mut self) -> Vec { + let mut expressions = Vec::new(); + while !self.at_eof() { + expressions.push(self.parse_expression()); + } + expressions + } + fn synchronize(&mut self) { while !self.at_eof() { match self.peek() { diff --git a/src/main.rs b/src/main.rs index de7cb01..8ced4a4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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::>().join("\n"); self.output_log = "Roundtrip complete — source reformatted.".to_string(); self.active_tab = AppTab::Output; } diff --git a/tests/data_server.rs b/tests/data_server.rs index a739371..d4d9807 100644 --- a/tests/data_server.rs +++ b/tests/data_server.rs @@ -120,6 +120,7 @@ fn test_real_m1_full_iteration() { assert!(total_records > 0, "Should have read some records"); } +// FIXME: This test is flaky — thread scheduling can cause uneven read counts. #[test] fn test_real_concurrent_access() { if skip_if_no_data() {