pub mod node { include!(concat!(env!("OUT_DIR"), "/src/ast/node.rs")); impl OperatorInner { pub fn name(&self) -> &'static str { match self { OperatorInner::Or => "op_or", OperatorInner::And => "op_and", OperatorInner::EqualTo => "op_eq", OperatorInner::NotEqualTo => "op_neq", OperatorInner::Greater => "op_gt", OperatorInner::Less => "op_lt", OperatorInner::GreaterEqual => "op_ge", OperatorInner::LessEqual => "op_le", OperatorInner::Add => "op_add", OperatorInner::Subtract => "op_sub", OperatorInner::Multiply => "op_mul", OperatorInner::Divide => "op_div", OperatorInner::Modulo => "op_mod", OperatorInner::LeftShift => "op_ls", OperatorInner::RightShift => "op_rs", OperatorInner::Spread => "op_spread", OperatorInner::Star => "op_star", OperatorInner::Not => "op_not", OperatorInner::Negative => "op_neg", OperatorInner::PlusPlus => "op_pp", OperatorInner::MinusMinus => "op_mm", OperatorInner::CallOp => "op_call", OperatorInner::Index => "op_index", } } } 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) -> CompilationUnit { let compilation_unit_pair = parsed_pairs.next().unwrap(); 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::fmt::Result; } include!(concat!(env!("OUT_DIR"), "/src/ast/pretty_print.rs")); } pub mod ast_node { include!(concat!(env!("OUT_DIR"), "/src/ast/ast_node.rs")); } pub mod walk { include!(concat!(env!("OUT_DIR"), "/src/ast/walk.rs")); }