Skip to content

Commit

Permalink
83 errors left
Browse files Browse the repository at this point in the history
  • Loading branch information
Arpita-Jaiswal committed Nov 13, 2024
1 parent 0363e8b commit 74cef5e
Show file tree
Hide file tree
Showing 46 changed files with 4,594 additions and 6,401 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion design/new-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ pub struct Component {
pub name: String,
pub properties: Vec<Property>,
pub iteration: Box<Option<Loop>>,
pub condition: Box<Option<ftd::interpreter::Expression>>,
pub condition: Box<Option<fastn_type::Expression>>,
pub events: Vec<Event>,
pub children: Vec<Component>,
pub source: ComponentSource,
Expand Down
2 changes: 1 addition & 1 deletion fastn-type/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ homepage.workspace = true
[dependencies]
serde.workspace = true
# serde_json.workspace = true
# fastn-grammar.workspace = true
fastn-grammar.workspace = true
17 changes: 14 additions & 3 deletions fastn-type/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub struct Component {
pub name: String,
pub properties: Vec<Property>,
pub iteration: Box<Option<Loop>>,
// pub condition: Box<Option<fastn_type::Expression>>,
pub condition: Box<Option<fastn_type::Expression>>,
pub events: Vec<Event>,
pub children: Vec<Component>,
pub source: ComponentSource,
Expand All @@ -19,7 +19,7 @@ impl fastn_type::Component {
name: name.to_string(),
properties: vec![],
iteration: Box::new(None),
// condition: Box::new(None),
condition: Box::new(None),
events: vec![],
children: vec![],
source: Default::default(),
Expand Down Expand Up @@ -54,7 +54,7 @@ pub struct Event {
pub struct Property {
pub value: fastn_type::PropertyValue,
pub source: fastn_type::PropertySource,
// pub condition: Option<fastn_type::Expression>,
pub condition: Option<fastn_type::Expression>,
pub line_number: usize,
}

Expand Down Expand Up @@ -107,3 +107,14 @@ pub enum EventName {
RiveStateChange(String),
RivePause(String),
}

#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct ComponentDefinition {
pub name: String,
pub arguments: Vec<Argument>,
pub definition: fastn_type::Component,
pub css: Option<fastn_type::PropertyValue>,
pub line_number: usize,
}

pub type Argument = fastn_type::Field;
20 changes: 20 additions & 0 deletions fastn-type/src/expression.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize)]
pub struct Expression {
pub expression: fastn_grammar::evalexpr::ExprNode,
pub references: fastn_type::Map<fastn_type::PropertyValue>,
pub line_number: usize,
}

impl Expression {
pub fn new(
expression: fastn_grammar::evalexpr::ExprNode,
references: fastn_type::Map<fastn_type::PropertyValue>,
line_number: usize,
) -> Expression {
Expression {
expression,
references,
line_number,
}
}
}
38 changes: 38 additions & 0 deletions fastn-type/src/function.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct Function {
pub name: String,
pub return_kind: fastn_type::KindData,
pub arguments: Vec<fastn_type::Argument>,
pub expression: Vec<fastn_type::FunctionExpression>,
pub js: Option<fastn_type::PropertyValue>,
pub line_number: usize,
pub external_implementation: bool,
}

impl Function {
pub fn new(
name: &str,
return_kind: fastn_type::KindData,
arguments: Vec<fastn_type::Argument>,
expression: Vec<fastn_type::FunctionExpression>,
js: Option<fastn_type::PropertyValue>,
line_number: usize,
) -> Function {
Function {
name: name.to_string(),
return_kind,
arguments,
expression,
js,
line_number,
external_implementation: false,
}
}
}

#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct FunctionCall {
pub name: String,
Expand Down Expand Up @@ -31,3 +63,9 @@ impl FunctionCall {
}
}
}

#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct FunctionExpression {
pub expression: String,
pub line_number: usize,
}
16 changes: 14 additions & 2 deletions fastn-type/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@
extern crate self as fastn_type;

mod function;
pub use function::FunctionCall;
pub use function::{Function, FunctionCall, FunctionExpression};
mod value;
pub use value::{PropertyValue, PropertyValueSource, Value};
mod kind;
pub use kind::{Kind, KindData};

mod component;
pub use component::{Component, ComponentSource, Event, EventName, Loop, Property, PropertySource};
pub use component::{
Argument, Component, ComponentDefinition, ComponentSource, Event, EventName, Loop, Property,
PropertySource,
};

mod expression;
pub use expression::Expression;

mod record;
pub use record::{AccessModifier, Field, Record};

mod module_thing;
pub use module_thing::ModuleThing;

pub type Map<T> = std::collections::BTreeMap<String, T>;
85 changes: 85 additions & 0 deletions fastn-type/src/module_thing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
pub enum ModuleThing {
Component(ComponentModuleThing),
Variable(VariableModuleThing),
Formula(FormulaModuleThing),
}

impl ModuleThing {
pub fn component(
name: String,
kind: fastn_type::KindData,
arguments: Vec<fastn_type::Argument>,
) -> Self {
ModuleThing::Component(ComponentModuleThing::new(name, kind, arguments))
}

pub fn variable(name: String, kind: fastn_type::KindData) -> Self {
ModuleThing::Variable(VariableModuleThing::new(name, kind))
}

pub fn function(name: String, kind: fastn_type::KindData) -> Self {
ModuleThing::Formula(FormulaModuleThing::new(name, kind))
}

pub fn get_kind(&self) -> fastn_type::KindData {
match self {
fastn_type::ModuleThing::Component(c) => c.kind.clone(),
fastn_type::ModuleThing::Variable(v) => v.kind.clone(),
fastn_type::ModuleThing::Formula(f) => f.kind.clone(),
}
}

pub fn get_name(&self) -> String {
match self {
fastn_type::ModuleThing::Component(c) => c.name.clone(),
fastn_type::ModuleThing::Variable(v) => v.name.clone(),
fastn_type::ModuleThing::Formula(f) => f.name.clone(),
}
}
}

#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct ComponentModuleThing {
pub name: String,
pub kind: fastn_type::KindData,
pub arguments: Vec<fastn_type::Argument>,
}

impl ComponentModuleThing {
pub fn new(
name: String,
kind: fastn_type::KindData,
arguments: Vec<fastn_type::Argument>,
) -> Self {
ComponentModuleThing {
name,
kind,
arguments,
}
}
}

#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct FormulaModuleThing {
pub name: String,
pub kind: fastn_type::KindData,
}

impl FormulaModuleThing {
pub fn new(name: String, kind: fastn_type::KindData) -> Self {
FormulaModuleThing { name, kind }
}
}

#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct VariableModuleThing {
pub name: String,
pub kind: fastn_type::KindData,
}

impl VariableModuleThing {
pub fn new(name: String, kind: fastn_type::KindData) -> Self {
VariableModuleThing { name, kind }
}
}
122 changes: 122 additions & 0 deletions fastn-type/src/record.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#[derive(Debug, Default, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct Record {
pub name: String,
pub fields: Vec<fastn_type::Field>,
pub line_number: usize,
}

impl Record {
pub fn new(name: &str, fields: Vec<Field>, line_number: usize) -> Record {
Record {
name: name.to_string(),
fields,
line_number,
}
}
}
#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct Field {
pub name: String,
pub kind: fastn_type::KindData,
pub mutable: bool,
pub value: Option<fastn_type::PropertyValue>,
pub line_number: usize,
pub access_modifier: AccessModifier,
}

impl Field {
pub fn new(
name: &str,
kind: fastn_type::KindData,
mutable: bool,
value: Option<fastn_type::PropertyValue>,
line_number: usize,
) -> Field {
Field {
name: name.to_string(),
kind,
mutable,
value,
line_number,
access_modifier: Default::default(),
}
}

pub fn to_sources(&self) -> Vec<fastn_type::PropertySource> {
let mut sources = vec![fastn_type::PropertySource::Header {
name: self.name.to_string(),
mutable: self.mutable,
}];
if self.is_caption() {
sources.push(fastn_type::PropertySource::Caption);
}

if self.is_body() {
sources.push(fastn_type::PropertySource::Body);
}

if self.is_subsection_ui() {
sources.push(fastn_type::PropertySource::Subsection);
}

sources
}

pub fn default(name: &str, kind: fastn_type::KindData) -> fastn_type::Field {
fastn_type::Field {
name: name.to_string(),
kind,
mutable: false,
value: None,
line_number: 0,
access_modifier: Default::default(),
}
}

pub fn default_with_value(
name: &str,
kind: fastn_type::KindData,
value: fastn_type::PropertyValue,
) -> Field {
Field {
name: name.to_string(),
kind,
mutable: false,
value: Some(value),
line_number: 0,
access_modifier: Default::default(),
}
}

pub fn is_caption(&self) -> bool {
self.kind.caption
}

pub fn is_subsection_ui(&self) -> bool {
self.kind.kind.clone().inner_list().is_subsection_ui()
}

pub fn is_body(&self) -> bool {
self.kind.body
}

pub fn is_value_required(&self) -> bool {
if self.kind.is_optional() || self.kind.is_list() {
return false;
}
self.value.is_none()
}
}

#[derive(Debug, Default, PartialEq, Clone, serde::Serialize, serde::Deserialize)]
pub enum AccessModifier {
#[default]
Public,
Private,
}

impl AccessModifier {
pub fn is_public(&self) -> bool {
matches!(self, AccessModifier::Public)
}
}
Loading

0 comments on commit 74cef5e

Please sign in to comment.