diff --git a/Cargo.lock b/Cargo.lock index 4a57f1dfc..b503ab69e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1765,15 +1765,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "ftd-tc" -version = "0.1.0" -dependencies = [ - "ftd-ast", - "ftd-p1", - "thiserror", -] - [[package]] name = "futures" version = "0.3.31" diff --git a/Cargo.toml b/Cargo.toml index b340ddf2a..74e38ad6c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,6 @@ members = [ "ftd", "ftd-ast", "ftd-p1", - "ftd-tc", "t", # "fastn-wasm", # "fastn-runtime", @@ -102,7 +101,6 @@ fastn-expr.path = "fastn-expr" format_num = "0.1" ftd.path = "ftd" ftd-p1.path = "ftd-p1" -ftd-tc.path = "ftd-tc" ftd-ast.path = "ftd-ast" fastn-js.path = "fastn-js" ft-sys-shared = "0.1.4" diff --git a/ftd-tc/Cargo.toml b/ftd-tc/Cargo.toml deleted file mode 100644 index 5f4fcc0f1..000000000 --- a/ftd-tc/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "ftd-tc" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -description.workspace = true -license.workspace = true -repository.workspace = true -homepage.workspace = true - -[dependencies] -ftd-ast.workspace = true -ftd-p1.workspace = true -thiserror.workspace = true diff --git a/ftd-tc/src/component_invocation.rs b/ftd-tc/src/component_invocation.rs deleted file mode 100644 index dac6dc76a..000000000 --- a/ftd-tc/src/component_invocation.rs +++ /dev/null @@ -1,110 +0,0 @@ -use crate::{DocumentID, Lined, Qualified, Type}; - -#[derive(Debug)] -pub enum ComponentResolvable { - /// First step is to resolve name, to see if there is any component with this name - Name, - /// Then we check the `id`. So far we are using `id` as literal, but if id was a reference - /// we have to resolve and prove that reference is valid - Id, - Loop, - Property(String), - Argument(String), - Event(String), - Condition, - Child(i32), -} - -#[derive(Debug)] -pub struct CI { - pub inner: ftd_ast::ComponentInvocation, - pub to_resolve: Vec, - pub local_types: ftd_p1::Map, - pub js_buffer: String, - pub document_id: DocumentID, -} - -impl ftd_tc::State { - pub fn handle_ci_name( - &mut self, - ci: &mut CI, - thing: &mut ComponentResolvable, - ) -> ftd_tc::Result> { - // see if name exists in self.global_types, if so move on to verifying - // other stuff. if the name doesn't exist in global types, and belongs to - // another module, and the module is already loaded, we move to CD state, - // component definition. If the module is also not yet loaded we return - // module name to load. - match self.global_types.get(&ci.inner.name) { - Some(Qualified { - v: Type::Component(c), - .. - }) => { - // we are done with the first check, there is indeed a component with this name - // next we have to check the `id`. - ci.to_resolve.push(ComponentResolvable::Id); - // TODO: check if the v is accessible in the current document - Ok(None) - } - Some(t) => { - self.errors.push(ftd_tc::Error::NotAComponent { - name: ci.inner.name.clone(), - usage_document: ci.document_id.clone(), - usage_line: ci.inner.line_number, - found: Box::new(t.to_owned()), - }); - Ok(None) - } - None => match self.symbols.get(&ci.inner.name) { - Some(Lined { - v: ftd_ast::Ast::ComponentDefinition(c), - .. - }) => { - todo!() - } - Some(t) => { - todo!("syntax error, foo is not a component") - } - None => todo!(), - }, - } - } - - pub fn handle_ci_thing( - &mut self, - c: &mut CI, - thing: &mut ComponentResolvable, - ) -> ftd_tc::Result> { - match thing { - ComponentResolvable::Name => self.handle_ci_name(c, thing), - ComponentResolvable::Id => todo!(), - _ => Ok(None), - } - } - - pub fn resolve_component_invocation(&mut self, c: &mut CI) -> ftd_tc::Result> { - while let Some(mut thing) = c.to_resolve.pop() { - if let Some(document) = self.handle_ci_thing(c, &mut thing)? { - c.to_resolve.push(thing); - return Ok(Some(document)); - } - } - - Ok(None) - } -} - -impl ftd_tc::ContinuableThing { - pub fn from_component_invocation( - c: ftd_ast::ComponentInvocation, - document_id: ftd_tc::DocumentID, - ) -> Self { - ftd_tc::ContinuableThing::CI(ftd_tc::CI { - inner: c, - local_types: ftd_p1::Map::new(), - js_buffer: String::new(), - to_resolve: vec![ftd_tc::ComponentResolvable::Name], - document_id, - }) - } -} diff --git a/ftd-tc/src/error.rs b/ftd-tc/src/error.rs deleted file mode 100644 index 8243096f2..000000000 --- a/ftd-tc/src/error.rs +++ /dev/null @@ -1,15 +0,0 @@ -#[derive(thiserror::Error, Debug)] -pub enum Error { - #[error("ast: {0}")] - Ast(#[from] ftd_ast::Error), - - #[error("ftd-p1: {name}")] - NotAComponent { - name: String, - usage_document: ftd_tc::DocumentID, - usage_line: usize, - found: Box>, - }, -} - -pub type Result = std::result::Result; diff --git a/ftd-tc/src/lib.rs b/ftd-tc/src/lib.rs deleted file mode 100644 index 6945e303c..000000000 --- a/ftd-tc/src/lib.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![allow(unused)] -#![deny(unused_crate_dependencies)] - -extern crate self as ftd_tc; - -mod component_invocation; -mod error; -mod parser; -mod state; -mod types; - -pub use component_invocation::{ComponentResolvable, CI}; -pub use error::*; -pub use parser::parse_document_to_ast; -pub use state::{State, TCState}; -pub use types::*; diff --git a/ftd-tc/src/main.rs b/ftd-tc/src/main.rs deleted file mode 100644 index a19443721..000000000 --- a/ftd-tc/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - ftd_tc::parse_document_to_ast("-- import: foo", &ftd_tc::DocumentID::new0("foo")).unwrap(); -} diff --git a/ftd-tc/src/parser.rs b/ftd-tc/src/parser.rs deleted file mode 100644 index de4e000ad..000000000 --- a/ftd-tc/src/parser.rs +++ /dev/null @@ -1,10 +0,0 @@ -pub fn parse_document_to_ast( - source: &str, - doc_id: &ftd_tc::DocumentID, -) -> ftd_ast::Result> { - let sections = ftd_p1::parse(source, doc_id.logical.as_str())?; - let ast = ftd_ast::Ast::from_sections(sections.as_slice(), doc_id.logical.as_str())?; - println!("{:?}", ast); - - Ok(ast) -} diff --git a/ftd-tc/src/state.rs b/ftd-tc/src/state.rs deleted file mode 100644 index fe7b3f3fa..000000000 --- a/ftd-tc/src/state.rs +++ /dev/null @@ -1,119 +0,0 @@ -#[derive(Default, Debug)] -pub struct State { - /// These are the things we need to resolve. - /// - /// we start by adding every component invocation in the main document and try to resolve - /// them. If we find a reference to another document, we load that document and process it. - /// We do this in a recursive manner. - pub continuable_things: Vec, - /// Raw symbols from all documents are stored here - pub symbols: ftd_p1::Map>, - /// any type we have already resolved is stored here - pub global_types: ftd_p1::Map>, - /// js_buffer contains the generated JS when we resolve any symbol - pub js_buffer: String, - pub errors: Vec, -} - -#[derive(Debug)] -pub enum TCState { - Processing(State), - StuckOnImport { document: String, state: State }, - Done(State), -} - -impl ftd_tc::State { - fn merge_ast( - &mut self, - extend_continuable_things: bool, - ast: Vec, - doc_id: ftd_tc::DocumentID, - ) { - for ast in ast { - match ast { - ftd_ast::Ast::Import(_) - | ftd_ast::Ast::Record(_) - | ftd_ast::Ast::OrType(_) - | ftd_ast::Ast::VariableDefinition(_) - | ftd_ast::Ast::ComponentDefinition(_) - | ftd_ast::Ast::FunctionDefinition(_) - | ftd_ast::Ast::WebComponentDefinition(_) => { - self.symbols.insert( - format!("{}#{}", doc_id.logical, ast.name()), - ftd_tc::Lined { - line_number: ast.line_number(), - v: ast, - doc_id: doc_id.clone(), - }, - ); - } - ftd_ast::Ast::VariableInvocation(_) => unreachable!(), - ftd_ast::Ast::ComponentInvocation(c) => { - if extend_continuable_things { - self.continuable_things.push( - ftd_tc::ContinuableThing::from_component_invocation( - c.clone(), - doc_id.clone(), - ), - ) - } - } - } - } - } - - pub fn from_document(source: &str, doc_id: ftd_tc::DocumentID) -> ftd_tc::Result { - let ast = ftd_tc::parse_document_to_ast(source, &doc_id)?; - - let mut s = Self::default(); - s.merge_ast(false, ast, doc_id); - - Ok(s) - } - - fn resolve_record_invocation(&mut self, c: &mut ftd_tc::RI) -> ftd_tc::Result> { - Ok(None) - } - - fn resolve_function_invocation( - &mut self, - c: &mut ftd_tc::FI, - ) -> ftd_tc::Result> { - Ok(None) - } - - fn handle_thing( - &mut self, - thing: &mut ftd_tc::ContinuableThing, - ) -> ftd_tc::Result> { - match thing { - ftd_tc::ContinuableThing::CI(c) => self.resolve_component_invocation(c), - ftd_tc::ContinuableThing::RI(r) => self.resolve_record_invocation(r), - ftd_tc::ContinuableThing::FI(f) => self.resolve_function_invocation(f), - } - } - - fn r#continue(mut self) -> ftd_tc::Result { - while let Some(mut thing) = self.continuable_things.pop() { - if let Some(document) = self.handle_thing(&mut thing)? { - self.continuable_things.push(thing); - return Ok(ftd_tc::TCState::StuckOnImport { - document, - state: self, - }); - } - } - - Ok(ftd_tc::TCState::Done(self)) - } - - fn continue_after_import( - mut self, - doc_id: ftd_tc::DocumentID, - source: &str, - ) -> ftd_tc::Result { - let ast = ftd_tc::parse_document_to_ast(source, &doc_id)?; - self.merge_ast(false, ast, doc_id); - self.r#continue() - } -} diff --git a/ftd-tc/src/types.rs b/ftd-tc/src/types.rs deleted file mode 100644 index 1b0ad45a3..000000000 --- a/ftd-tc/src/types.rs +++ /dev/null @@ -1,94 +0,0 @@ -#[derive(Debug)] -pub enum ContinuableThing { - RI(RI), - CI(ftd_tc::CI), - FI(FI), -} - -#[derive(Debug)] -pub struct FI { - // -} - -#[derive(Debug, Clone)] -pub struct RI { - pub inner: ftd_ast::VariableDefinition, - pub r: Record, - pub current_field: i32, -} - -#[derive(Debug, Clone)] -pub enum Type { - Integer, - MutableInteger, - Record(Record), - Component(Component), -} - -#[derive(Debug, Clone)] -pub enum AccessibleIn { - /// accessible in the same document - Module(DocumentID), - /// accessible in the same package - Package(DocumentID), - /// accessible to anyone who adds this package as a direct dependency - Public, -} - -#[derive(Debug, Clone)] -pub struct Qualified { - pub v: T, - pub line_number: usize, - pub doc_id: DocumentID, - pub accessible_in: AccessibleIn, -} - -#[derive(Debug)] -pub struct Lined { - pub v: T, - pub line_number: usize, - pub doc_id: DocumentID, -} - -#[derive(Debug, Clone)] -pub struct DocumentID { - /// logical id is what we use to refer to a document in the code, eg `amitu.com/foo` - pub logical: String, - /// physical id is the file name, eg `.packages/amitu.com/foo/index.ftd` - pub physical: String, -} - -/// we use field to model component arguments, record fields, and function arguments etc -#[derive(Debug, Clone)] -pub struct Field { - pub name: String, - pub type_: Type, - /// if the field has a default value, we can skip passing this field in the invocation - pub has_default: bool, -} - -#[derive(Debug, Clone)] -pub struct Component { - pub args: Vec, -} - -#[derive(Debug, Clone)] -pub struct Record { - pub fields: Vec, -} - -impl DocumentID { - pub fn new(logical: &str, physical: &str) -> Self { - Self { - logical: logical.to_string(), - physical: physical.to_string(), - } - } - - pub fn new0(logical: &str) -> Self { - Self { - logical: logical.to_string(), - physical: logical.to_string(), - } - } -}