From 51c39f5f34479a0fed2a3fce15215ece8de82ad6 Mon Sep 17 00:00:00 2001 From: Jesse Brault Date: Mon, 3 Nov 2025 13:41:05 -0600 Subject: [PATCH] WIP fixing newlines/call grammar. --- src/ast/mod.rs | 37 +++++++++++++++++++++++++++++++++++++ src/parser/deimos.pest | 6 +++--- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index b13c4f0..632ca3a 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -87,7 +87,11 @@ pub mod build { #[cfg(test)] mod build_tests { use super::*; + use crate::ast::ast_node::AstNodeRef; + use crate::ast::pretty_print::PrettyPrint; + use crate::ast::walk::walk_depth_first; use crate::parser::DeimosParser; + use crate::util::indent_writer::IndentWriter; use pest::Parser; fn parse(rule: Rule, input: &str) -> Pair { @@ -95,6 +99,14 @@ pub mod build { parse_result.expect("parsing failed").next().unwrap() } + fn fmt_ast(node: &dyn PrettyPrint) -> String { + let mut acc = String::new(); + let mut indent_writer = IndentWriter::new(0, " ", &mut acc); + node.pretty_print(&mut indent_writer) + .expect("Pretty print failed"); + acc + } + #[test] fn boolean_literal_true() { let pair = parse( @@ -159,6 +171,31 @@ pub mod build { let pair = parse(Rule::Expression, "hello(42)"); let expression = build_expression(0, pair); } + + #[test] + fn multiple_expression_statements() { + let pair = parse( + Rule::Function, + " + fn test() + println 42 + println 43 + end + ", + ); + let function = build_function(0, pair); + + let mut number_of_statements = 0; + + walk_depth_first(&function, &mut |node| match node { + AstNodeRef::Statement(_) => { + number_of_statements += 1; + } + _ => {} + }); + + assert_eq!(2, number_of_statements, "Ast: {}", fmt_ast(&function)); + } } } diff --git a/src/parser/deimos.pest b/src/parser/deimos.pest index 31abcf5..0abceac 100644 --- a/src/parser/deimos.pest +++ b/src/parser/deimos.pest @@ -758,17 +758,17 @@ SuffixOperator = ${ | WHITESPACE* ~ AnySpaceSuffixOperator ~ WHITESPACE* } -BoundSuffixOperator = { +BoundSuffixOperator = !{ PlusPlus | MinusMinus } -NoNewlineSuffixOperator = { +NoNewlineSuffixOperator = !{ ObjectIndex | Call } -AnySpaceSuffixOperator = { +AnySpaceSuffixOperator = !{ ObjectProperty }