kotlin_parser/parse/expression/
object_expr.rs

1use crate::{
2    ast::*,
3    parse::declaration::{
4        annotation::annotations_parser, entity::extends_parser,
5    },
6};
7use chumsky::prelude::*;
8
9use super::call::block_parser;
10
11pub fn object_expr_parser(
12    stmt_parser: impl Parser<char, Statement, Error = Simple<char>>,
13    expr_parser: impl Parser<char, Expression, Error = Simple<char>>,
14) -> impl Parser<char, Expression, Error = Simple<char>> {
15    annotations_parser(expr_parser)
16        .repeated()
17        .or_not()
18        .then(
19            just("object")
20                .padded()
21                .ignore_then(extends_parser().or_not())
22                .then(block_parser(stmt_parser)),
23        )
24        .map(|(annotations, (extends, body))| {
25            Expression::Object(ObjectExpression {
26                annotations: annotations.unwrap_or_default(),
27                extends: extends.unwrap_or_default(),
28                body,
29            })
30        })
31}