pub mod node { include!(concat!(env!("OUT_DIR"), "/src/ast/node.rs")); impl Default for Parameters { fn default() -> Self { Self::new(vec![]) } } impl Default for GenericParameters { fn default() -> Self { Self::new(Box::new(IdentifierList::new(vec![]))) } } impl Default for GenericArguments { fn default() -> Self { Self::new(Box::new(TypeUseList::new(vec![]))) } } impl Default for ImplementsList { fn default() -> Self { Self::new(vec![]) } } impl ReturnType { pub fn void() -> Self { Self::new(Box::new(TypeUse::PrimitiveType(PrimitiveType::Void))) } } impl Default for ClassConstructor { fn default() -> Self { Self::new(vec![]) } } impl Default for ClosureParameters { fn default() -> Self { Self::new(vec![]) } } } pub mod build { use pest::iterators::Pairs; include!(concat!(env!("OUT_DIR"), "/src/ast/build.rs")); pub fn build_ast(file_id: usize, parsed_pairs: &mut Pairs) -> Box { let compilation_unit_pair = parsed_pairs.next().unwrap(); Box::new(build_compilation_unit(file_id, compilation_unit_pair)) } #[cfg(test)] mod build_tests { use super::*; use crate::parser::DeimosParser; use pest::Parser; fn parse(rule: Rule, input: &str) -> Pair { let parse_result = DeimosParser::parse(rule, input); parse_result.expect("parsing failed").next().unwrap() } #[test] fn boolean_literal_true() { let pair = parse( Rule::BooleanLiteral, include_str!("build_tests/boolean_literal/true"), ); assert_eq!(true, build_boolean_literal(0, pair)); } #[test] fn boolean_literal_false() { let pair = parse( Rule::BooleanLiteral, include_str!("build_tests/boolean_literal/false"), ); assert_eq!(false, build_boolean_literal(0, pair)); } #[test] fn backtick_inner_greeting() { let pair = parse( Rule::BacktickInner, include_str!("build_tests/backtick_inner/greeting"), ); assert_eq!("Hello, World!", build_backtick_inner(0, pair)); } #[test] fn backtick_string_mixed() { let pair = parse( Rule::BacktickString, include_str!("build_tests/backtick_string/mixed"), ); let backtick_string = build_backtick_string(0, pair); assert_eq!(backtick_string.inners().count(), 2); assert_eq!(backtick_string.expressions().count(), 1); } #[test] fn d_string_expression_simple() { let pair = parse(Rule::DStringExpression, "${thing}"); let d_string_expression = build_d_string_expression(0, pair); } #[test] fn d_string_inner() { let pair = parse(Rule::DStringInner, "Hello!"); let d_string_inner = build_d_string_inner(0, pair); assert_eq!("Hello!", d_string_inner); } #[test] fn d_string_mixed() { let pair = parse(Rule::DString, "\"Hello, ${world}!\""); let d_string = build_d_string(0, pair); assert_eq!(d_string.inners().count(), 2); assert_eq!(d_string.expressions().count(), 1); } #[test] fn expression_simple_call() { let pair = parse(Rule::Expression, "hello(42)"); let expression = build_expression(0, pair); } } } pub mod pretty_print { use crate::util::indent_writer::IndentWriter; pub trait PrettyPrint { fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()>; } include!(concat!(env!("OUT_DIR"), "/src/ast/pretty_print.rs")); }