kotlin_parser/parse/declaration/
typealias.rs1use crate::{
2 ast::*,
3 parse::ty::{type_params_parser, type_parser},
4};
5use chumsky::prelude::*;
6
7use super::modifier_parser;
8
9pub fn typealias_parser(
10 expr_parser: impl Parser<char, Expression, Error = Simple<char>>,
11) -> impl Parser<char, TypeAliasDeclaration, Error = Simple<char>> {
12 modifier_parser()
13 .repeated()
14 .or_not()
15 .then(
16 just("typealias")
17 .padded()
18 .ignore_then(text::ident().padded())
19 .then(type_params_parser(expr_parser).or_not())
20 .then_ignore(just('='))
21 .then(type_parser()),
22 )
23 .map(
24 |(modifiers, ((name, type_params), ty))| TypeAliasDeclaration {
25 modifiers: modifiers.unwrap_or_default(),
26 name,
27 type_params: type_params.unwrap_or_default(),
28 ty,
29 },
30 )
31}