107 lines
2.8 KiB
Rust
107 lines
2.8 KiB
Rust
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 {
|
|
//noinspection RsUnusedImport
|
|
use crate::parser::Rule;
|
|
//noinspection RsUnusedImport
|
|
use pest::iterators::Pair;
|
|
//noinspection RsUnusedImport
|
|
use crate::ast::node::*;
|
|
|
|
include!(concat!(env!("OUT_DIR"), "/src/ast/build.rs"));
|
|
|
|
#[cfg(test)]
|
|
mod build_tests {
|
|
use super::*;
|
|
use crate::parser::DeimosParser;
|
|
use pest::Parser;
|
|
|
|
fn parse(rule: Rule, input: &str) -> Pair<Rule> {
|
|
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(pair));
|
|
}
|
|
|
|
#[test]
|
|
fn boolean_literal_false() {
|
|
let pair = parse(
|
|
Rule::BooleanLiteral,
|
|
include_str!("build_tests/boolean_literal/false"),
|
|
);
|
|
assert_eq!(false, build_boolean_literal(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(pair));
|
|
}
|
|
|
|
#[test]
|
|
fn backtick_string_mixed() {
|
|
let pair = parse(
|
|
Rule::BacktickString,
|
|
include_str!("build_tests/backtick_string/mixed"),
|
|
);
|
|
let backtick_string = build_backtick_string(pair);
|
|
assert_eq!(backtick_string.inners().count(), 2);
|
|
assert_eq!(backtick_string.expressions().count(), 1);
|
|
}
|
|
}
|
|
}
|