From da1279badbf51fc5b2793a1d494963f55231448d Mon Sep 17 00:00:00 2001 From: Amit Upadhyay Date: Sat, 23 Nov 2024 23:05:11 +0530 Subject: [PATCH] an attempt at writing resolver --- v0.5/fastn-compiler/src/compiler.rs | 6 ++++-- .../src/resolver/component_invocation.rs | 7 ++++--- v0.5/fastn-unresolved/src/resolver/definition.rs | 3 ++- v0.5/fastn-unresolved/src/resolver/mod.rs | 2 ++ v0.5/fastn-unresolved/src/resolver/name.rs | 15 +++++++++++++++ 5 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 v0.5/fastn-unresolved/src/resolver/name.rs diff --git a/v0.5/fastn-compiler/src/compiler.rs b/v0.5/fastn-compiler/src/compiler.rs index d0388fdea..7919d5f56 100644 --- a/v0.5/fastn-compiler/src/compiler.rs +++ b/v0.5/fastn-compiler/src/compiler.rs @@ -89,7 +89,8 @@ impl Compiler { let mut definition = self.definitions.remove(&symbol); match definition.as_mut() { Some(fastn_unresolved::UR::UnResolved(definition)) => { - let o = definition.resolve(self.resolution_input()); + let mut o = Default::default(); + definition.resolve(self.resolution_input(), &mut o); r.need_more_symbols.extend(o.stuck_on); self.document.merge(o.errors, o.warnings, o.comments); } @@ -129,7 +130,8 @@ impl Compiler { for ci in content { match ci { fastn_unresolved::UR::UnResolved(mut c) => { - let needed = c.resolve(self.resolution_input()); + let mut needed = Default::default(); + c.resolve(self.resolution_input(), &mut needed); if needed.stuck_on.is_empty() { new_content.push(fastn_unresolved::UR::Resolved(c.resolved().unwrap())); } else { diff --git a/v0.5/fastn-unresolved/src/resolver/component_invocation.rs b/v0.5/fastn-unresolved/src/resolver/component_invocation.rs index de0121b24..3b83134d0 100644 --- a/v0.5/fastn-unresolved/src/resolver/component_invocation.rs +++ b/v0.5/fastn-unresolved/src/resolver/component_invocation.rs @@ -1,8 +1,9 @@ impl fastn_unresolved::ComponentInvocation { pub fn resolve( &mut self, - _input: fastn_unresolved::resolver::Input<'_>, - ) -> fastn_unresolved::resolver::Output { - todo!() + input: fastn_unresolved::resolver::Input<'_>, + output: &mut fastn_unresolved::resolver::Output, + ) { + fastn_unresolved::resolver::name::resolve(&mut self.name, input, output); } } diff --git a/v0.5/fastn-unresolved/src/resolver/definition.rs b/v0.5/fastn-unresolved/src/resolver/definition.rs index 46adecb5c..75b6925bd 100644 --- a/v0.5/fastn-unresolved/src/resolver/definition.rs +++ b/v0.5/fastn-unresolved/src/resolver/definition.rs @@ -2,7 +2,8 @@ impl fastn_unresolved::Definition { pub fn resolve( &mut self, _input: fastn_unresolved::resolver::Input<'_>, - ) -> fastn_unresolved::resolver::Output { + _output: &mut fastn_unresolved::resolver::Output, + ) { todo!() } } diff --git a/v0.5/fastn-unresolved/src/resolver/mod.rs b/v0.5/fastn-unresolved/src/resolver/mod.rs index d24516046..6feaccb90 100644 --- a/v0.5/fastn-unresolved/src/resolver/mod.rs +++ b/v0.5/fastn-unresolved/src/resolver/mod.rs @@ -7,6 +7,7 @@ mod component_invocation; mod definition; +mod name; pub struct Input<'a> { pub definitions: &'a std::collections::HashMap, @@ -14,6 +15,7 @@ pub struct Input<'a> { pub interner: &'a string_interner::DefaultStringInterner, } +#[derive(Debug, Default)] pub struct Output { pub stuck_on: std::collections::HashSet, pub errors: Vec>, diff --git a/v0.5/fastn-unresolved/src/resolver/name.rs b/v0.5/fastn-unresolved/src/resolver/name.rs new file mode 100644 index 000000000..9538b4411 --- /dev/null +++ b/v0.5/fastn-unresolved/src/resolver/name.rs @@ -0,0 +1,15 @@ +pub fn resolve( + name: &mut fastn_unresolved::UR, + _input: fastn_unresolved::resolver::Input<'_>, + _output: &mut fastn_unresolved::resolver::Output, +) { + let inner_name = if let fastn_unresolved::UR::UnResolved(name) = name { + name + } else { + return; + }; + + // verify name is good + + *name = fastn_unresolved::UR::Resolved(inner_name.clone()); +}