WIP fixing newlines/call grammar.

This commit is contained in:
Jesse Brault 2025-11-03 13:41:05 -06:00
parent 1d11a45c68
commit 51c39f5f34
2 changed files with 40 additions and 3 deletions

View File

@ -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<Rule> {
@ -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));
}
}
}

View File

@ -758,17 +758,17 @@ SuffixOperator = ${
| WHITESPACE* ~ AnySpaceSuffixOperator ~ WHITESPACE*
}
BoundSuffixOperator = {
BoundSuffixOperator = !{
PlusPlus
| MinusMinus
}
NoNewlineSuffixOperator = {
NoNewlineSuffixOperator = !{
ObjectIndex
| Call
}
AnySpaceSuffixOperator = {
AnySpaceSuffixOperator = !{
ObjectProperty
}