Skip to content

Commit

Permalink
fastn-type 0.1.1 and more UR<> wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Nov 15, 2024
1 parent 0afa4be commit f7abd18
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 37 deletions.
2 changes: 1 addition & 1 deletion fastn-type/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fastn-type"
version = "0.1.0"
version = "0.1.1"
authors.workspace = true
edition.workspace = true
description.workspace = true
Expand Down
39 changes: 20 additions & 19 deletions fastn-type/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub use web_component::WebComponentDefinition;
pub type Map<T> = std::collections::BTreeMap<String, T>;

#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
pub enum Thing {
pub enum Definition {
Record(fastn_type::Record),
OrType(fastn_type::OrType),
OrTypeWithVariant {
Expand All @@ -43,43 +43,44 @@ pub enum Thing {
Component(fastn_type::ComponentDefinition),
WebComponent(fastn_type::WebComponentDefinition),
Function(fastn_type::Function),
/// what is this?
Export {
from: String,
to: String,
line_number: usize,
},
}

impl Thing {
impl Definition {
pub fn name(&self) -> String {
match self {
fastn_type::Thing::Record(r) => r.name.clone(),
fastn_type::Thing::OrType(o) => o.name.clone(),
fastn_type::Thing::OrTypeWithVariant { or_type, .. } => or_type.clone(),
fastn_type::Thing::Variable(v) => v.name.to_string(),
fastn_type::Thing::Component(c) => c.name.to_string(),
fastn_type::Thing::Function(f) => f.name.to_string(),
fastn_type::Thing::WebComponent(w) => w.name.to_string(),
fastn_type::Thing::Export { to, .. } => to.to_string(),
fastn_type::Definition::Record(r) => r.name.clone(),
fastn_type::Definition::OrType(o) => o.name.clone(),
fastn_type::Definition::OrTypeWithVariant { or_type, .. } => or_type.clone(),
fastn_type::Definition::Variable(v) => v.name.to_string(),
fastn_type::Definition::Component(c) => c.name.to_string(),
fastn_type::Definition::Function(f) => f.name.to_string(),
fastn_type::Definition::WebComponent(w) => w.name.to_string(),
fastn_type::Definition::Export { to, .. } => to.to_string(),
}
}

pub fn line_number(&self) -> usize {
match self {
Thing::Record(r) => r.line_number,
Thing::Variable(v) => v.line_number,
Thing::Component(c) => c.line_number,
Thing::Function(f) => f.line_number,
Thing::OrType(o) => o.line_number,
Thing::OrTypeWithVariant { variant, .. } => variant.line_number(),
Thing::WebComponent(w) => w.line_number,
Thing::Export { line_number, .. } => *line_number,
Definition::Record(r) => r.line_number,
Definition::Variable(v) => v.line_number,
Definition::Component(c) => c.line_number,
Definition::Function(f) => f.line_number,
Definition::OrType(o) => o.line_number,
Definition::OrTypeWithVariant { variant, .. } => variant.line_number(),
Definition::WebComponent(w) => w.line_number,
Definition::Export { line_number, .. } => *line_number,
}
}

pub fn component(self) -> Option<fastn_type::ComponentDefinition> {
match self {
fastn_type::Thing::Component(v) => Some(v),
fastn_type::Definition::Component(v) => Some(v),
_ => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion ftd/src/interpreter/things/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub(crate) mod value;
pub(crate) mod variable;
pub(crate) mod web_component;

pub type Thing = fastn_type::Thing;
pub type Thing = fastn_type::Definition;

pub trait ThingExt {
fn variable(
Expand Down
2 changes: 1 addition & 1 deletion v0.5/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ homepage = "https://fastn.com"
# using the latest dependency, and what is the plan to move to the latest version.

fastn-lang = { path = "fastn-lang" }
fastn-type = "0.1.0"
fastn-type = "0.1.1"
fastn-section = { path = "fastn-section" }
fastn-static = { path = "fastn-static" }
fastn-core = { path = "fastn-core" }
Expand Down
39 changes: 24 additions & 15 deletions v0.5/fastn-unresolved/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub use parser::parse;
pub struct Document {
pub module_doc: Option<fastn_section::Span>,
pub imports: Vec<fastn_unresolved::Import>,
pub definitions: Vec<Definition>,
pub definitions: Vec<UR<Definition, fastn_type::Definition>>,
pub content: Vec<UR<ComponentInvocation, fastn_type::ComponentInvocation>>,
pub errors: Vec<fastn_section::Spanned<fastn_section::Error>>,
pub warnings: Vec<fastn_section::Spanned<fastn_section::Warning>>,
Expand All @@ -26,35 +26,44 @@ pub struct Document {
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Definition {
pub doc: Option<fastn_section::Span>,
pub name: Identifier,
/// resolving an identifier means making sure it is unique in the document, and performing
/// other checks.
pub name: UR<Identifier, Identifier>,
pub visibility: fastn_section::Visibility,
pub kind: Kind,
pub inner: InnerDefinition,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum InnerDefinition {
Component {
properties: Vec<Argument>,
body: Vec<ComponentInvocation>,
properties: Vec<UR<Argument, fastn_type::Argument>>,
body: Vec<UR<ComponentInvocation, fastn_type::ComponentInvocation>>,
},
Variable {
arguments: Vec<Property>,
caption: Vec<fastn_section::Tes>,
kind: UR<Kind, fastn_type::Kind>,
properties: Vec<UR<Property, fastn_type::Property>>,
/// resolved caption goes to properties
caption: UR<Vec<fastn_section::Tes>, ()>,
/// resolved body goes to properties
body: UR<Vec<fastn_section::Tes>, ()>,
},
Function {
properties: Vec<Argument>,
return_type: Option<Kind>,
body: Vec<fastn_section::Tes>,
arguments: Vec<UR<Argument, fastn_type::Argument>>,
return_type: Option<UR<Kind, fastn_type::Kind>>,
/// this one is a little interesting, the number of expressions can be more than the number
/// of Tes, this because we can have multiple expressions in a single Tes.
body: Vec<UR<fastn_section::Tes, fastn_type::FunctionExpression>>,
},
// -- type foo: person
// name: foo ;; we are updating / setting the default value
TypeAlias {
kind: Kind,
arguments: Vec<Property>,
kind: UR<Kind, fastn_type::Kind>,
/// ```ftd
/// -- type foo: person
/// name: foo ;; we are updating / setting the default value
/// ```
arguments: Vec<UR<Property, fastn_type::Property>>,
},
Record {
properties: Vec<Argument>,
properties: Vec<UR<Argument, fastn_type::Argument>>,
},
// TODO: OrType(fastn_section::Section),
// TODO: Module(fastn_section::Section),
Expand Down

0 comments on commit f7abd18

Please sign in to comment.