1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use crate::{ast, coerce, context::*, types::*, StringId};

pub(super) fn model(model_attributes: &mut ModelAttributes, ctx: &mut Context<'_>) {
    model_attributes.schema = visit_schema_attribute(ctx);
}

pub(super) fn r#enum(enum_attributes: &mut EnumAttributes, ctx: &mut Context<'_>) {
    enum_attributes.schema = visit_schema_attribute(ctx);
}

fn visit_schema_attribute(ctx: &mut Context<'_>) -> Option<(StringId, ast::Span)> {
    let arg = match ctx.visit_default_arg("map") {
        Ok(arg) => arg,
        Err(err) => {
            ctx.push_error(err);
            return None;
        }
    };
    let name = coerce::string(arg, ctx.diagnostics)?;
    Some((ctx.interner.intern(name), arg.span()))
}