WIP fixing newlines/call grammar.
This commit is contained in:
parent
1d11a45c68
commit
51c39f5f34
@ -87,7 +87,11 @@ pub mod build {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod build_tests {
|
mod build_tests {
|
||||||
use super::*;
|
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::parser::DeimosParser;
|
||||||
|
use crate::util::indent_writer::IndentWriter;
|
||||||
use pest::Parser;
|
use pest::Parser;
|
||||||
|
|
||||||
fn parse(rule: Rule, input: &str) -> Pair<Rule> {
|
fn parse(rule: Rule, input: &str) -> Pair<Rule> {
|
||||||
@ -95,6 +99,14 @@ pub mod build {
|
|||||||
parse_result.expect("parsing failed").next().unwrap()
|
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]
|
#[test]
|
||||||
fn boolean_literal_true() {
|
fn boolean_literal_true() {
|
||||||
let pair = parse(
|
let pair = parse(
|
||||||
@ -159,6 +171,31 @@ pub mod build {
|
|||||||
let pair = parse(Rule::Expression, "hello(42)");
|
let pair = parse(Rule::Expression, "hello(42)");
|
||||||
let expression = build_expression(0, pair);
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -758,17 +758,17 @@ SuffixOperator = ${
|
|||||||
| WHITESPACE* ~ AnySpaceSuffixOperator ~ WHITESPACE*
|
| WHITESPACE* ~ AnySpaceSuffixOperator ~ WHITESPACE*
|
||||||
}
|
}
|
||||||
|
|
||||||
BoundSuffixOperator = {
|
BoundSuffixOperator = !{
|
||||||
PlusPlus
|
PlusPlus
|
||||||
| MinusMinus
|
| MinusMinus
|
||||||
}
|
}
|
||||||
|
|
||||||
NoNewlineSuffixOperator = {
|
NoNewlineSuffixOperator = !{
|
||||||
ObjectIndex
|
ObjectIndex
|
||||||
| Call
|
| Call
|
||||||
}
|
}
|
||||||
|
|
||||||
AnySpaceSuffixOperator = {
|
AnySpaceSuffixOperator = !{
|
||||||
ObjectProperty
|
ObjectProperty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user