mod group;
mod lambda;
mod list;
mod literal;
mod pair;
mod path;
mod union;

pub use group::*;
pub use lambda::*;
pub use list::*;
pub use literal::*;
pub use pair::*;
pub use path::*;
pub use union::*;

use rue_ast::{AstNode, AstType};
use rue_types::TypeId;

use crate::{Compiler, CompletionContext, SyntaxItemKind};

pub fn compile_type(ctx: &mut Compiler, ty: &AstType) -> TypeId {
    ctx.add_syntax(
        SyntaxItemKind::CompletionContext(CompletionContext::Type),
        ty.syntax().text_range(),
    );

    match ty {
        AstType::PathType(path) => compile_path_type(ctx, path),
        AstType::UnionType(union) => compile_union_type(ctx, union),
        AstType::GroupType(group) => compile_group_type(ctx, group),
        AstType::PairType(pair) => compile_pair_type(ctx, pair),
        AstType::ListType(list) => compile_list_type(ctx, list),
        AstType::LiteralType(literal) => compile_literal_type(ctx, literal),
        AstType::LambdaType(lambda) => compile_lambda_type(ctx, lambda),
    }
}
