From 8ca96d765cff437589cbcdde992925899423f5c8 Mon Sep 17 00:00:00 2001 From: Amit Upadhyay Date: Tue, 3 Dec 2024 16:45:50 +0530 Subject: [PATCH] resolving all properties --- .../src/resolver/arguments.rs | 88 +++++++++++++------ 1 file changed, 62 insertions(+), 26 deletions(-) diff --git a/v0.5/fastn-unresolved/src/resolver/arguments.rs b/v0.5/fastn-unresolved/src/resolver/arguments.rs index 9199f2520..3f81b6289 100644 --- a/v0.5/fastn-unresolved/src/resolver/arguments.rs +++ b/v0.5/fastn-unresolved/src/resolver/arguments.rs @@ -2,7 +2,7 @@ pub fn arguments( arguments: &[fastn_resolved::Argument], caption: &mut fastn_unresolved::UR, ()>, - #[expect(clippy::ptr_arg)] _properties: &mut Vec< + properties: &mut Vec< fastn_unresolved::UR, >, body: &mut fastn_unresolved::UR, ()>, @@ -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, ()>, is_caption: bool, arguments: &[fastn_resolved::Argument], + properties: &mut Vec< + fastn_unresolved::UR, + >, ) { 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, 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!() }