kotlin_parser/parse/ty/
simple.rs

1use crate::ast::*;
2use chumsky::prelude::*;
3
4pub fn simple_type_parser() -> impl Parser<char, Type, Error = Simple<char>> {
5    recursive(|ty| {
6        text::ident()
7            .padded()
8            .then(type_args_parser(ty).or_not())
9            .then(just('?').or_not())
10            .map(|((name, type_args), is_nullable)| {
11                Type::Simple(Box::new(SimpleType {
12                    name,
13                    type_args: type_args.unwrap_or_default(),
14                    is_nullable: is_nullable.is_some(),
15                }))
16            })
17    })
18}
19
20pub fn type_args_parser(
21    ty: impl Parser<char, Type, Error = Simple<char>>,
22) -> impl Parser<char, Vec<Type>, Error = Simple<char>> {
23    ty.padded()
24        .separated_by(just(',').padded())
25        .delimited_by(just('<').padded(), just('>').padded())
26}