Skip to content

Commit

Permalink
generalising caption and body
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Dec 2, 2024
1 parent 1ce8480 commit 928285f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion v0.5/fastn-unresolved/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub struct ComponentInvocation {
pub caption: UR<Option<fastn_section::HeaderValue>, ()>,
pub properties: Vec<UR<Property, fastn_resolved::Property>>,
/// once the body is resolved, it is set to () here, and moved to properties
pub body: UR<Vec<fastn_section::Tes>, ()>,
pub body: UR<Option<fastn_section::HeaderValue>, ()>,
pub children: Vec<UR<ComponentInvocation, fastn_resolved::ComponentInvocation>>,
}

Expand Down
6 changes: 3 additions & 3 deletions v0.5/fastn-unresolved/src/parser/component_invocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ pub(super) fn component_invocation(
module: document.module.clone(),
name: fastn_unresolved::UR::UnResolved(section.init.name.clone()),
caption: section.caption.into(),
properties: vec![], // todo
body: vec![].into(), // todo
children: vec![], // todo
properties: vec![], // todo
body: fastn_unresolved::UR::UnResolved(None), // todo
children: vec![], // todo
}
.into(),
)
Expand Down
23 changes: 15 additions & 8 deletions v0.5/fastn-unresolved/src/resolver/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
pub fn arguments(
arguments: &[fastn_resolved::Argument],
caption: &mut fastn_unresolved::UR<Option<fastn_section::HeaderValue>, ()>,
_properties: &mut Vec<
#[expect(clippy::ptr_arg)] _properties: &mut Vec<
fastn_unresolved::UR<fastn_unresolved::Property, fastn_resolved::Property>,
>,
_body: &mut fastn_unresolved::UR<Vec<fastn_section::Tes>, ()>,
body: &mut fastn_unresolved::UR<Option<fastn_section::HeaderValue>, ()>,
_children: &[fastn_unresolved::UR<
fastn_unresolved::ComponentInvocation,
fastn_resolved::ComponentInvocation,
Expand All @@ -15,18 +15,25 @@ pub fn arguments(
_arena: &mut fastn_unresolved::Arena,
_output: &mut fastn_unresolved::resolver::Output,
) {
if let fastn_unresolved::UR::UnResolved(None) = caption {
*caption = fastn_unresolved::UR::Resolved(())
caption_or_body(caption, true, arguments);
caption_or_body(body, false, arguments);
}

fn caption_or_body(
v: &mut fastn_unresolved::UR<Option<fastn_section::HeaderValue>, ()>,
_is_caption: bool,
arguments: &[fastn_resolved::Argument],
) {
if let fastn_unresolved::UR::UnResolved(None) = v {
*v = fastn_unresolved::UR::Resolved(())
}
if let fastn_unresolved::UR::UnResolved(Some(_v)) = caption {
if let fastn_unresolved::UR::UnResolved(Some(_v)) = v {
// see if any of the arguments are of type caption.
// assume there is only one such argument, because otherwise arguments would have failed
// to resolve
match arguments.iter().find(|v| v.is_caption()) {
Some(_v) => todo!(),
None => {
*caption = fastn_unresolved::UR::Invalid(fastn_section::Error::UnexpectedCaption)
}
None => *v = fastn_unresolved::UR::Invalid(fastn_section::Error::UnexpectedCaption),
}
}
}

0 comments on commit 928285f

Please sign in to comment.