feat(compiler): @embed model kwarg in grammar/AST/parser (RFC-012 Phase 3)

Annotations gain optional comma-separated key=value kwargs. Annotation keeps value (existing consumers unchanged) and adds kwargs: BTreeMap with serde(default, skip_serializing_if) so empty kwargs are omitted and existing schemas' IR JSON/hash stay byte-identical. The parser rejects any @embed kwarg other than model. render_annotations shows kwargs. 3 new parser tests.
This commit is contained in:
Ragnor Comerford 2026-06-15 21:09:15 +02:00
parent 30377c453b
commit 74476f7f51
No known key found for this signature in database
6 changed files with 120 additions and 9 deletions

View file

@ -696,9 +696,19 @@ pub(crate) fn render_constraint(constraint: &omnigraph_compiler::schema::ast::Co
pub(crate) fn render_annotations(annotations: &[omnigraph_compiler::schema::ast::Annotation]) -> String {
annotations
.iter()
.map(|annotation| match &annotation.value {
Some(value) => format!("@{}({})", annotation.name, value),
None => format!("@{}", annotation.name),
.map(|annotation| {
let mut args: Vec<String> = Vec::new();
if let Some(value) = &annotation.value {
args.push(value.clone());
}
for (key, val) in &annotation.kwargs {
args.push(format!("{}={}", key, val));
}
if args.is_empty() {
format!("@{}", annotation.name)
} else {
format!("@{}({})", annotation.name, args.join(", "))
}
})
.collect::<Vec<_>>()
.join(", ")