Skip to content

Commit

Permalink
resolving simple string
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Dec 3, 2024
1 parent 8ca96d7 commit 4881dab
Showing 1 changed file with 49 additions and 12 deletions.
61 changes: 49 additions & 12 deletions v0.5/fastn-unresolved/src/resolver/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ pub fn arguments(
Err(e) => *p = fastn_unresolved::UR::Invalid(e),
}
}

// TODO: check if any required argument is missing (should only be done when everything is
// resolved, how do we track this resolution?
// maybe this function can return a bool to say everything is resolved? but if everything
// is marked resolved, we have an issue, maybe we put something extra in properties in
// unresolved state, and resolve only when this is done?
}

fn caption_or_body(
Expand Down Expand Up @@ -81,26 +87,57 @@ enum Property<'a> {
Body,
}

impl Property<'_> {
fn source(&self) -> fastn_resolved::PropertySource {
match self {
Property::Field(f) => fastn_resolved::PropertySource::Header {
name: f.to_string(),
mutable: false,
},
Property::Body => fastn_resolved::PropertySource::Body,
Property::Caption => fastn_resolved::PropertySource::Caption,
}
}
}

fn resolve_argument(
arguments: &[fastn_resolved::Argument],
property: Property,
_value: &fastn_section::HeaderValue,
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()
// }
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,
}) {
Some(a) => a,
None => return Err(fastn_section::Error::UnexpectedCaption), // TODO: do better
};

match argument.kind.kind {
fastn_resolved::Kind::String => resolve_string(&property, value),
_ => todo!(),
}
}

fn resolve_string(
property: &Property,
value: &fastn_section::HeaderValue,
) -> Result<Option<fastn_resolved::Property>, fastn_section::Error> {
if let Some(v) = value.as_plain_string() {
return Ok(Some(fastn_resolved::Property {
value: fastn_resolved::PropertyValue::Value {
value: fastn_resolved::Value::String {
text: v.to_string(),
},
is_mutable: false,
line_number: 0,
},
source: property.source(),
condition: None,
line_number: 0,
}));
};

todo!()
}

0 comments on commit 4881dab

Please sign in to comment.