Skip to content

Commit

Permalink
resolving all properties
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Dec 3, 2024
1 parent 5be2f71 commit 8ca96d7
Showing 1 changed file with 62 additions and 26 deletions.
88 changes: 62 additions & 26 deletions v0.5/fastn-unresolved/src/resolver/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pub fn arguments(
arguments: &[fastn_resolved::Argument],
caption: &mut fastn_unresolved::UR<Option<fastn_section::HeaderValue>, ()>,
#[expect(clippy::ptr_arg)] _properties: &mut Vec<
properties: &mut Vec<
fastn_unresolved::UR<fastn_unresolved::Property, fastn_resolved::Property>,
>,
body: &mut fastn_unresolved::UR<Option<fastn_section::HeaderValue>, ()>,
Expand All @@ -15,56 +15,92 @@ pub fn arguments(
_arena: &mut fastn_unresolved::Arena,
_output: &mut fastn_unresolved::resolver::Output,
) {
caption_or_body(caption, true, arguments);
caption_or_body(body, false, arguments);
caption_or_body(caption, true, arguments, properties);
caption_or_body(body, false, arguments, properties);
for p in properties.iter_mut() {
let inner_p = if let fastn_unresolved::UR::UnResolved(inner_p) = p {
inner_p
} else {
continue;
};
match resolve_argument(
arguments,
Property::Field(inner_p.name.str()),
&inner_p.value,
) {
Ok(Some(d)) => *p = fastn_unresolved::UR::Resolved(d),
Ok(None) => {}
Err(e) => *p = fastn_unresolved::UR::Invalid(e),
}
}
}

fn caption_or_body(
v: &mut fastn_unresolved::UR<Option<fastn_section::HeaderValue>, ()>,
is_caption: bool,
arguments: &[fastn_resolved::Argument],
properties: &mut Vec<
fastn_unresolved::UR<fastn_unresolved::Property, fastn_resolved::Property>,
>,
) {
if let fastn_unresolved::UR::UnResolved(None) = v {
*v = fastn_unresolved::UR::Resolved(());
return;
}

let (argument, inner_v) = if let fastn_unresolved::UR::UnResolved(Some(inner_v)) = v {
let inner_v = if let fastn_unresolved::UR::UnResolved(Some(inner_v)) = v {
// see if any of the arguments are of type caption or body
// assume there is only one such argument, because otherwise arguments would have failed
// to resolve
match arguments.iter().find(|v| {
if is_caption {
v.is_caption()
} else {
v.is_body()
}
}) {
Some(a) => (a, inner_v),
None => {
*v = fastn_unresolved::UR::Invalid(fastn_section::Error::UnexpectedCaption);
return;
}
}
inner_v
} else {
return;
};

match crate::resolver::arguments::argument(argument, inner_v) {
Ok(Some(_p)) => {
todo!()
// *v = fastn_unresolved::UR::Resolved(p)
}
Ok(None) => {
todo!()
match resolve_argument(
arguments,
if is_caption {
Property::Caption
} else {
Property::Body
},
inner_v,
) {
Ok(Some(p)) => {
*v = fastn_unresolved::UR::Resolved(());
properties.push(fastn_unresolved::UR::Resolved(p));
}
Ok(None) => {}
Err(e) => *v = fastn_unresolved::UR::Invalid(e),
}
}

fn argument(
_argument: &fastn_resolved::Argument,
enum Property<'a> {
Field(&'a str),
Caption,
Body,
}

fn resolve_argument(
arguments: &[fastn_resolved::Argument],
property: Property,
_value: &fastn_section::HeaderValue,
) -> Result<Option<fastn_resolved::Property>, fastn_section::Error> {
let _argument = match arguments.iter().find(|v| {
match property {
Property::Caption => v.is_caption(),
Property::Body => v.is_body(),
Property::Field(ref f) => &v.name == f,
}
// if is_caption {
// v.is_caption()
// } else {
// v.is_body()
// }
}) {
Some(a) => a,
None => return Err(fastn_section::Error::UnexpectedCaption), // TODO: do better
};

todo!()
}

0 comments on commit 8ca96d7

Please sign in to comment.