From c6994ab672a37fd38cfa685821d5bc0f1ed522d3 Mon Sep 17 00:00:00 2001 From: DOOM1EM8Cover Date: Mon, 28 Aug 2023 20:10:43 +0100 Subject: [PATCH] More Work --- core_stdlib/.gitignore | 1 + examples/codegen/simple_gen.rs | 24 -- package-manager-server/.gitignore | 1 + package-manager/.gitignore | 2 + proposals/enum_variant_associated_kind.ids | 0 proposals/protocol_function_blanket_impl.ids | 0 proposals/protocol_property_discoverable.ids | 6 - .../protocol_provider_and_provenance.ids | 9 - runtime/.gitignore | 2 + src/codegen/mod.rs | 0 src/project/idl/ast.rs | 0 src/project/idl/idc.pest | 7 - src/project/idl/mod.rs | 0 src/project/idl/parser.rs | 16 - src/project/ir/mod.rs | 0 src/project/mod.rs | 0 src/schema/idl/ast/mod.rs | 3 - src/schema/idl/ast/old_unit.rs | 116 ------ src/schema/idl/ast/unit.rs | 160 -------- src/schema/idl/constants.rs | 10 - src/schema/idl/idl.pest | 248 ------------ src/schema/idl/mod.rs | 3 - src/schema/idl/parser.rs | 370 ------------------ .../ir/compiler/interpreted/frozen/blob.rs | 0 .../ir/compiler/interpreted/frozen/commit.rs | 0 .../ir/compiler/interpreted/frozen/mod.rs | 0 .../ir/compiler/interpreted/frozen/tree.rs | 0 .../ir/compiler/interpreted/frozen/unit.rs | 0 .../ir/compiler/interpreted/frozen_unit.rs | 83 ---- .../ir/compiler/interpreted/interpreter.rs | 168 -------- src/schema/ir/compiler/interpreted/mod.rs | 10 - .../ir/compiler/interpreted/primitive.rs | 71 ---- src/schema/ir/compiler/interpreted/report.rs | 43 -- .../ir/compiler/interpreted/sanitizer.rs | 12 - .../interpreted/serialization/messagepack.rs | 20 - .../compiler/interpreted/serialization/mod.rs | 13 - .../ir/compiler/interpreter/incremental.rs | 173 -------- src/schema/ir/compiler/interpreter/mod.rs | 1 - .../ir/compiler/interpreter/relations.rs | 0 src/schema/ir/compiler/mod.rs | 26 -- src/schema/ir/context.rs | 51 --- src/schema/ir/mod.rs | 4 - src/schema/mod.rs | 0 tests/idl/congregation.idc | 0 tests/idl/units/dev.ids | 27 -- tests/idl/units/mod.rs | 32 -- tests/idl/units/protocol/args.ids | 12 - tests/ir/mod.rs | 0 tests/stdlib/mod.rs | 0 tests/stdlib/validators.rs | 0 50 files changed, 6 insertions(+), 1718 deletions(-) create mode 100644 core_stdlib/.gitignore delete mode 100644 examples/codegen/simple_gen.rs create mode 100644 package-manager-server/.gitignore create mode 100644 package-manager/.gitignore delete mode 100644 proposals/enum_variant_associated_kind.ids delete mode 100644 proposals/protocol_function_blanket_impl.ids delete mode 100644 proposals/protocol_property_discoverable.ids delete mode 100644 proposals/protocol_provider_and_provenance.ids create mode 100644 runtime/.gitignore delete mode 100644 src/codegen/mod.rs delete mode 100644 src/project/idl/ast.rs delete mode 100644 src/project/idl/idc.pest delete mode 100644 src/project/idl/mod.rs delete mode 100644 src/project/idl/parser.rs delete mode 100644 src/project/ir/mod.rs delete mode 100644 src/project/mod.rs delete mode 100644 src/schema/idl/ast/mod.rs delete mode 100644 src/schema/idl/ast/old_unit.rs delete mode 100644 src/schema/idl/ast/unit.rs delete mode 100644 src/schema/idl/constants.rs delete mode 100644 src/schema/idl/idl.pest delete mode 100644 src/schema/idl/mod.rs delete mode 100644 src/schema/idl/parser.rs delete mode 100644 src/schema/ir/compiler/interpreted/frozen/blob.rs delete mode 100644 src/schema/ir/compiler/interpreted/frozen/commit.rs delete mode 100644 src/schema/ir/compiler/interpreted/frozen/mod.rs delete mode 100644 src/schema/ir/compiler/interpreted/frozen/tree.rs delete mode 100644 src/schema/ir/compiler/interpreted/frozen/unit.rs delete mode 100644 src/schema/ir/compiler/interpreted/frozen_unit.rs delete mode 100644 src/schema/ir/compiler/interpreted/interpreter.rs delete mode 100644 src/schema/ir/compiler/interpreted/mod.rs delete mode 100644 src/schema/ir/compiler/interpreted/primitive.rs delete mode 100644 src/schema/ir/compiler/interpreted/report.rs delete mode 100644 src/schema/ir/compiler/interpreted/sanitizer.rs delete mode 100644 src/schema/ir/compiler/interpreted/serialization/messagepack.rs delete mode 100644 src/schema/ir/compiler/interpreted/serialization/mod.rs delete mode 100644 src/schema/ir/compiler/interpreter/incremental.rs delete mode 100644 src/schema/ir/compiler/interpreter/mod.rs delete mode 100644 src/schema/ir/compiler/interpreter/relations.rs delete mode 100644 src/schema/ir/compiler/mod.rs delete mode 100644 src/schema/ir/context.rs delete mode 100644 src/schema/ir/mod.rs delete mode 100644 src/schema/mod.rs delete mode 100644 tests/idl/congregation.idc delete mode 100644 tests/idl/units/dev.ids delete mode 100644 tests/idl/units/mod.rs delete mode 100644 tests/idl/units/protocol/args.ids delete mode 100644 tests/ir/mod.rs delete mode 100644 tests/stdlib/mod.rs delete mode 100644 tests/stdlib/validators.rs diff --git a/core_stdlib/.gitignore b/core_stdlib/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/core_stdlib/.gitignore @@ -0,0 +1 @@ +/target diff --git a/examples/codegen/simple_gen.rs b/examples/codegen/simple_gen.rs deleted file mode 100644 index 73b1ff5..0000000 --- a/examples/codegen/simple_gen.rs +++ /dev/null @@ -1,24 +0,0 @@ - -/* -trait Registry { - fn register(message: Credentials) -> RegisterStatus; - fn my_username() -> String; - fn tell_back(message: String) -> Result; -} - -#[derive(ValidatorStringBounds<[u8; 8]>)] -struct Credentials { - -} - -struct RegisterStatus { - -} - -struct TellBackError { - -} -*/ - -fn main() { todo!() } - diff --git a/package-manager-server/.gitignore b/package-manager-server/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/package-manager-server/.gitignore @@ -0,0 +1 @@ +/target diff --git a/package-manager/.gitignore b/package-manager/.gitignore new file mode 100644 index 0000000..4fffb2f --- /dev/null +++ b/package-manager/.gitignore @@ -0,0 +1,2 @@ +/target +/Cargo.lock diff --git a/proposals/enum_variant_associated_kind.ids b/proposals/enum_variant_associated_kind.ids deleted file mode 100644 index e69de29..0000000 diff --git a/proposals/protocol_function_blanket_impl.ids b/proposals/protocol_function_blanket_impl.ids deleted file mode 100644 index e69de29..0000000 diff --git a/proposals/protocol_property_discoverable.ids b/proposals/protocol_property_discoverable.ids deleted file mode 100644 index 2eb2cf9..0000000 --- a/proposals/protocol_property_discoverable.ids +++ /dev/null @@ -1,6 +0,0 @@ - -// TODO: Think what »discoverable« should mean, just like Fuchsia IDL -@discoverable -protocol OpenWorld { -} - diff --git a/proposals/protocol_provider_and_provenance.ids b/proposals/protocol_provider_and_provenance.ids deleted file mode 100644 index acd54a3..0000000 --- a/proposals/protocol_provider_and_provenance.ids +++ /dev/null @@ -1,9 +0,0 @@ - -//#provider=Server -#provider=Multiple consumer=Multiple // TODO: These parameters need more situational introspection to be documented -protocol Feed { - // Fetches new articles since last fetch - @flexible async stream - #timeout=1000ms per_send_timeout=10s cooldown=10s - 1# function fetch_articles() -> Article[SENT_ARTICLES_MAX] -} diff --git a/runtime/.gitignore b/runtime/.gitignore new file mode 100644 index 0000000..4fffb2f --- /dev/null +++ b/runtime/.gitignore @@ -0,0 +1,2 @@ +/target +/Cargo.lock diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/project/idl/ast.rs b/src/project/idl/ast.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/project/idl/idc.pest b/src/project/idl/idc.pest deleted file mode 100644 index 6b0ea64..0000000 --- a/src/project/idl/idc.pest +++ /dev/null @@ -1,7 +0,0 @@ -// -// Created by intellij-pest on 2023-07-07 -// idc -// Author: nibunta -// - -idc = { "Hello World!" } diff --git a/src/project/idl/mod.rs b/src/project/idl/mod.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/project/idl/parser.rs b/src/project/idl/parser.rs deleted file mode 100644 index db5ccfe..0000000 --- a/src/project/idl/parser.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Standard Uses - -// Local Uses - -// External Uses -use anyhow::Result; -use pest::{iterators::Pair, Parser}; - -#[derive(Parser)] -#[grammar = "project/idl/idc.pest"] -pub struct IDLParser; - - -pub fn from_path() -> { - -} diff --git a/src/project/ir/mod.rs b/src/project/ir/mod.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/project/mod.rs b/src/project/mod.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/schema/idl/ast/mod.rs b/src/schema/idl/ast/mod.rs deleted file mode 100644 index 8835a22..0000000 --- a/src/schema/idl/ast/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -// Relative Modules -pub mod unit; -pub mod old_unit; diff --git a/src/schema/idl/ast/old_unit.rs b/src/schema/idl/ast/old_unit.rs deleted file mode 100644 index 4bac37d..0000000 --- a/src/schema/idl/ast/old_unit.rs +++ /dev/null @@ -1,116 +0,0 @@ -// Standard Uses - -// Local Uses - -// External Uses - -/* -/// Intermediate Representation Unit -#[allow(unused)] -#[derive(Debug, Eq, PartialEq)] -pub enum Unit { - Items(Vec), - Tag(String), - Namespace(String), - Imports(String), - Settings(Vec), - Consts(Vec), - Structs(Vec), - Enums(Vec), - Errors(Vec), - Protocols(Vec) -} - - -#[derive(Debug, Eq, PartialEq)] -pub struct Settings { - pub id: String, - pub parameters: Vec, -} - -#[derive(Debug, Eq, PartialEq)] -pub struct Const { - pub id: String, - pub type_: Kind, - pub default_value: Vec -} - -#[allow(unused)] -#[derive(Debug, Eq, PartialEq)] -pub struct Struct { - pub id: String, - pub parameters: Vec, - pub fields: Vec, -} - -#[allow(unused)] -#[derive(Debug, Eq, PartialEq)] -pub struct Enum { - pub id: String, - pub variants: Vec -} - -#[allow(unused)] -#[derive(Debug, Eq, PartialEq)] -pub struct EnumVariant { - pub id: String, - pub type_: Option -} - -#[allow(unused)] -#[derive(Debug, Eq, PartialEq)] -pub struct Error { - pub id: String, - pub parameters: Vec, - pub fields: Vec, -} - -#[allow(unused)] -#[derive(Debug, Eq, PartialEq)] -pub struct Parameter { - pub id: String, - pub value: Vec -} - -#[allow(unused)] -#[derive(Debug, Eq, PartialEq)] -pub struct Field { - pub index: u8, - pub optional: bool, - pub id: String, - pub type_: Kind, - pub default_value: Vec, -} - -#[allow(unused)] -#[derive(Debug, Eq, PartialEq)] -pub struct Protocol { - pub id: String, - pub parameters: Vec, - pub functions: Vec -} - -#[allow(unused)] -#[derive(Debug, Eq, PartialEq)] -pub enum Direction { Client, Server, Both } - -#[allow(unused)] -#[derive(Debug, Eq, PartialEq)] -pub struct Function { - pub index: u8, - pub id: String, - pub async_: bool, - pub direction: Direction, - pub arguments: Vec, - pub return_: Vec, - pub parameters: Vec, - pub throws: Vec -} - -#[allow(unused)] -#[derive(Debug, Eq, PartialEq)] -pub struct Argument { - pub id: Option, - pub type_: Kind -} -*/ \ No newline at end of file diff --git a/src/schema/idl/ast/unit.rs b/src/schema/idl/ast/unit.rs deleted file mode 100644 index 6a59e30..0000000 --- a/src/schema/idl/ast/unit.rs +++ /dev/null @@ -1,160 +0,0 @@ -// Standard Uses - -// Local Uses - -// External Uses - - -pub type OrderIndex = u16; - -#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)] -pub enum Direction { Client, Server, Both } - - -#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)] -pub enum ASTUnit { - /* - Schema { - tag: String, - namespace: String, - imports: Vec, - constants: Vec, - settings: Vec, - enums: Vec, - structures: Vec, - validators: Vec, - errors: Vec, - protocols: Vec - }, - */ - Tag(String), - Namespace(String), - Import(String), - Docstring { - variable: Option, - description: String - }, - Constant { - docstring: Vec, - name: String, - kind: String, - default_value: Option, - }, - Property { - name: String, - expression: Option - }, - Parameter { - name: String, - default_value: String - }, - ExpressionBlock { - function_calls: Vec - }, - // - Enum { - docstring: Vec, - name: String, - variants: Vec - }, - EnumVariant { - name: String, - kind: Option - }, - Settings { - docstring: Vec, - name: String, - parameters: Vec, - }, - Struct { - docstring: Vec, - parameters: Vec, - name: String, - fields: Vec, - }, - Protocol { - docstring: Vec, - parameters: Vec, - name: String, - functions: Vec - }, - Function { - docstring: Vec, - name: String, - synchronous: bool, - direction: Direction, - arguments: Vec, - returns: Vec, - throws: Vec - }, - Error { - docstring: Vec, - parameters: Vec, - name: String, - message: String, - fields: Vec - }, - Validator { - docstring: Vec, - properties: Vec, - name: String, - expression_block: Box - }, - Field { - docstring: Vec, - parameters: Vec, - // index: OrderIndex, - optional: bool, - name: String, - kind: String, - default_value: Option, - } -} - -pub(crate) fn namespace(vunit: &VUnit) -> &String { - let mut namespace: Option<&String> = None; - - for node in vunit { - match node { - ASTUnit::Namespace(n) => namespace = Some(n), - _ => {} - } - } - - namespace.unwrap() -} - -#[derive(PartialEq, Debug)] -pub enum UnitIndex { - Index { - path: String, - source: String, - // nodes: Vec - }, - Node { - index: u32, - start_position: u32, length: u32 - } -} - -#[derive(PartialEq, Debug)] -pub struct VIndex { - pub meta: UnitIndex, - pub nodes: Vec -} - -impl VIndex { - pub(crate) fn filename(&self) -> String { - match &self.meta { - UnitIndex::Index { path, .. } => path.clone(), - _ => panic!("Should not be here") - } - } - - pub(crate) fn provenance_details(&self) -> (String, String) { - todo!() - } -} - -pub type VUnit = Vec; -pub type WholeUnit = (VIndex, VUnit); diff --git a/src/schema/idl/constants.rs b/src/schema/idl/constants.rs deleted file mode 100644 index d7b35ab..0000000 --- a/src/schema/idl/constants.rs +++ /dev/null @@ -1,10 +0,0 @@ -// Standard Uses - -// Local Uses - -// External Uses - - -pub const CONGREGATION_EXTENSION: &str = "idc"; -pub const SCHEMA_EXTENSION: &str = "ids"; -pub const UNIT_EXTENSION: &str = "idu"; diff --git a/src/schema/idl/idl.pest b/src/schema/idl/idl.pest deleted file mode 100644 index 2557a76..0000000 --- a/src/schema/idl/idl.pest +++ /dev/null @@ -1,248 +0,0 @@ -// IDL grammar -schema = _{ - COMMENT* ~ MULTILINE_COMMENT* - ~ WS? - ~ namespace - ~ ( - COMMENT | import - | settings | constant - | validator | enumeration - | structure | error | protocol - )* -} - -namespace = { - "namespace" ~ WS ~ domain -} - -import = { - WS ~ "import" ~ WS - ~ domain_namespaced -} - -constant = { - WS ~ "const" ~ WS ~ id - ~ WS? ~ ":" ~ WS? - ~ kind ~ (WS? ~ "=" ~ WS? ~ value)? -} - -settings = { - WS? ~ docstring* - ~ WS? ~ "settings" ~ WS? ~ id? ~ WS? - ~ "{" ~ WS? ~ parameter* ~ WS? ~ "}" -} - -enumeration = { - WS? ~ docstring* ~ property* - ~ "enum" ~ WS ~ id ~ WS? - ~ "{" ~ WS? ~ enum_variant+ ~ WS? ~ "}" - ~ WS? -} -enum_variant = { - (index ~ "#")? ~ WS? - // TODO: Uncomment and replace the line below when this feature will be addressed - // ~ id ~ enum_variant_field? - ~ id - ~ WS? -} -enum_variant_field = { - "(" - ~ kind - ~ ")" -} - -validator = { - WS? ~ docstring* ~ property* - ~ "validator" ~ WS ~ id ~ WS? - ~ "{" ~ WS? ~ expression_block ~ WS? ~ "}" - ~ WS? -} - -expression = { - (operation ~ WS? ~ boolean_operator? ~ WS?)+ -} -item = { - domain_namespaced | domain | variable -} -function_call = { - item ~ WS? - ~ "(" ~ WS? - ~ function_call_arg* - ~ WS? ~ ")" ~ WS? -} -function_call_arg = { - WS? ~ ","? ~ WS? - ~ (operation | value) - ~ WS? -} - -entity = { number | variable } -operation = { - entity ~ WS? - ~ (boolean_operator | operator) - ~ WS? ~ (value | entity)+ -} -operator = { - "==" | "!=" - | "<" | ">" - | "+" | "-" | "/" - | "|" -} -boolean_operator = { - "or" | "and" -} - -structure = { - WS? ~ docstring? ~ property* - ~ "struct" ~ WS ~ id ~ WS? - ~ "{" ~ WS? ~ (constant | field)+ ~ WS? ~ "}" - ~ WS? -} -field = { - WS? ~ property* - // ~ (index ~ "#")? - ~ (WS? ~ requirement)? - ~ WS? ~ id ~ WS? ~ ":" ~ WS? ~ kind - ~ (WS? ~ "=" ~ WS? ~ value)? ~ WS? -} -index = @{ digit } -requirement = { "optional" } - -error = { - WS? ~ docstring? ~ property* - ~ "error" ~ WS ~ id ~ WS? - ~ "{" ~ WS? - ~ (parameter | field)+ - ~ WS? ~ "}" ~ WS? -} - -protocol = { - WS? ~ docstring? ~ property* - ~ "protocol" ~ WS ~ id ~ WS? - ~ "{" ~ WS? ~ function* ~ WS? ~ "}" -} -function = { - WS? ~ property* - ~ (index ~ WS? ~ "#" ~ WS?)? - ~ (asynchronous ~ WS?)? - ~ (direction ~ WS?)? - ~ "function" ~ WS ~ id ~ WS? - ~ "(" ~ WS? ~ argument* ~ WS? ~ ")" - ~ (WS? ~ "->" ~ WS? ~ returns+)? - // ~ (WS? ~ ":" ~ WS? ~ parameter+)? - ~ (WS? ~ "!" ~ WS? ~ throw+)? -} -direction = { "client" | "server" } - -asynchronous = { "async" } -argument = { - ","? ~ WS? - ~ ((id ~ WS? ~ ":" ~ WS? ~ kind) | kind) - ~ WS? -} -returns = { ","? ~ WS? ~ (kind) ~ WS? } -parameter = { - WS? ~ id ~ WS? ~ "=" ~ WS? ~ value ~ WS? -} -throw = { - ","? ~ WS? ~ value ~ WS? -} - - -// Common Rules -property = { - WS? ~ "@" - ~ WS? ~ property_domain - ~ WS? ~ "=" ~ WS? - ~ property_expression ~ WS? -} -property_domain = { - variable | domain -} -property_expression = { - (domain_namespaced | domain - | number | property_array) -} -property_array = { - "[" ~ WS? - ~ property_instance* - ~ WS? ~ "]" -} -property_instance = { - WS? ~ domain - ~ "(" ~ property_attribute* ~ ")" - ~ WS? -} -property_attribute = { - WS? ~ id ~ "=" ~ kind -} - -expression_block = { function_call* } - -variable = @{ (id | kind | ".")+ } -domain = @{ (id | "::")+ } -domain_namespaced = @{ (id | "::" | "_")+ } -number = @{ digit+ } -id = @{ (alpha | "_")+ } -kind = @{ (alpha | digit)+ } - -instantiation = { - (domain | domain_namespaced) - ~ "(" ~ domain ~ ")" -} - -docstring = { - "///" ~ - (docstring_property | docstring_description) - ~ NEWLINE -} -docstring_property = { - " "* ~ "@" ~ " "* ~ domain - ~ " "* ~ ":" - ~ " "? ~ docstring_description -} -docstring_description = @{ - (!NEWLINE ~ ANY)+ -} - -value = { - "true" | "false" | number - | string | string_interpolated - | instantiation - | variable | domain | domain_namespaced -} - -string = { - "\"" ~ string_inner ~ "\"" -} -string_interpolated = { - "f" ~ "\"" ~ string_interpolated_inner ~ "\"" -} -string_interpolated_inner = _{ - (string_interpolation | char)* -} -string_interpolation = _{ "{" ~ domain ~ "}" } - -string_inner = _{ - (string_interpolation | char)* -} -char = { - !("\"" | "\\") ~ ANY - | "\\" ~ ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t") - | "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4}) -} - - -alpha = { 'a'..'z' | 'A'..'Z' } -digit = { '0'..'9' } - -WS = _{ (" " | "\t" | "\n")+ } -COMMENT = _{ - !"///" ~ - "//" ~ (!NEWLINE ~ ANY)* ~ NEWLINE -} -MULTILINE_COMMENT = _{ - "/*" - ~ (MULTILINE_COMMENT | !"*/" ~ ANY)* - ~ "*/" -} diff --git a/src/schema/idl/mod.rs b/src/schema/idl/mod.rs deleted file mode 100644 index bac385e..0000000 --- a/src/schema/idl/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -// Relative Modules -pub mod parser; -pub mod constants; \ No newline at end of file diff --git a/src/schema/idl/parser.rs b/src/schema/idl/parser.rs deleted file mode 100644 index 2b427ca..0000000 --- a/src/schema/idl/parser.rs +++ /dev/null @@ -1,370 +0,0 @@ -// Standard Uses - -// Local Uses -use crate::ir::ast::unit::{ASTUnit, UnitIndex, VIndex, VUnit, WholeUnit}; - -// External Uses -use anyhow::Result; -use pest::{iterators::Pair, Parser}; - - - -#[derive(Parser)] -#[grammar = "idl/idl.pest"] -pub struct IDLParser; - - -pub fn from_path(path: &str) -> Result { - let raw = std::fs::read_to_string(path).unwrap(); - let vunit = parse_into_unit(raw.clone().as_str()).unwrap(); - let vindex = VIndex { - meta: UnitIndex::Index { path: path.to_string(), source: raw }, - nodes: vec![] - }; - - Ok((vindex, vunit)) -} - -pub fn parse_into_unit(content: &str) -> Result { - let pairs = IDLParser::parse(Rule::schema, content)?; - let mut unit = vec![]; - - for pair in pairs { unit.push(parse_inner(pair).unwrap()) } - - Ok(unit) -} - - -#[allow(unused)] -pub fn parse_inner(pairs: Pair) -> Result { - match pairs.as_rule() { - Rule::namespace => { - Ok(ASTUnit::Namespace(pairs.into_inner().as_str().to_owned())) - }, - Rule::import => { - Ok(ASTUnit::Import(pairs.into_inner().as_str().to_owned())) - } - Rule::constant => { - let pairs = pairs.into_inner(); - - let mut docstrings: Vec = vec![]; - let mut id: Option = None; - let mut kind: Option = None; - let mut default_value: Option = None; - - for pair in pairs { - match pair.as_rule() { - Rule::docstring => docstrings.push(to_docstring(pair)), - Rule::id => id = Some(pair.as_str().to_owned()), - Rule::kind => kind = Some(pair.as_str().to_owned()), - Rule::value => default_value = to_value_other(pair), - (r) => panic!("Rule not implemented on 'constant': {:?}", r) - } - } - - Ok(ASTUnit::Constant { - docstring: docstrings, - name: id.ok_or("Id is not present").unwrap(), - kind: kind.ok_or("Type is not present").unwrap(), - default_value, - }) - }, - Rule::settings => { - let mut pairs = pairs.into_inner(); - - let mut docstrings: Vec = vec![]; - let mut name: Option = None; - let mut parameters: Vec = vec![]; - - for pair in pairs { - match pair.as_rule() { - Rule::docstring => docstrings.push(to_docstring(pair)), - Rule::id => name = Some(pair.as_str().to_owned()), - Rule::parameter => parameters.push(to_parameter(pair)), - (r) => panic!("Rule not implemented on 'settings': {:?}", r) - } - } - - Ok(ASTUnit::Settings { - docstring: docstrings, - name: name.unwrap(), - parameters, - }) - }, - Rule::enumeration => { - let mut pairs = pairs.into_inner(); - - let mut docstrings: Vec = vec![]; - let mut name: Option = None; - let mut variants: Vec = vec![]; - - for pair in pairs { - match pair.as_rule() { - Rule::docstring => docstrings.push(to_docstring(pair)), - Rule::id => name = Some(pair.as_str().to_owned()), - Rule::enum_variant => { - let mut inner = pair.into_inner(); - let name = inner.next().unwrap().as_str().to_string(); - let kind = inner.next().map(|s| s.as_str().to_string()); - - variants.push(ASTUnit::EnumVariant { - name, kind, - }); - }, - (r) => panic!("Rule not implemented on 'enumeration': {:?}", r) - } - } - - Ok(ASTUnit::Enum { - docstring: docstrings, - name: name.unwrap(), variants, - }) - }, - Rule::structure => { - let mut pairs = pairs.into_inner(); - - let mut docstrings: Vec = vec![]; - let mut parameters: Vec = vec![]; - let mut name: Option = None; - let mut fields: Vec = vec![]; - - for pair in pairs { - match pair.as_rule() { - Rule::docstring => docstrings.push(to_docstring(pair)), - Rule::id => name = Some(pair.as_str().to_owned()), - Rule::parameter => parameters.push(to_parameter(pair)), - Rule::field => fields.push(to_field(pair)), - (r) => panic!("Rule not implemented on 'structure': {:?}", r) - } - } - - Ok(ASTUnit::Struct { - docstring: docstrings, parameters, - name: name.unwrap(), fields: vec![], - }) - }, - Rule::validator => { - let mut pairs = pairs.into_inner(); - - let mut docstrings: Vec = vec![]; - let mut properties: Vec = vec![]; - let mut name: Option = None; - let mut expression_block: Option = None; - - for pair in pairs { - match pair.as_rule() { - Rule::docstring => docstrings.push(to_docstring(pair)), - Rule::property => properties.push(to_property(pair)), - Rule::id => name = Some(pair.as_str().to_owned()), - Rule::expression_block => - expression_block = Some(to_expression_block(pair)), - (r) => panic!("Rule not implemented on 'validator': {:?}", r) - } - } - - Ok(ASTUnit::Validator { - docstring: docstrings, properties, - name: name.unwrap(), expression_block: Box::from(expression_block.unwrap()), - }) - }, - r => panic!("Rule not implemented: {:?}", r) - } -} - -pub fn to_docstring(pair: Pair) -> ASTUnit { - let pair = pair.into_inner().next().unwrap(); - - match pair.as_rule() { - Rule::docstring_property => { - let pairs = pair.into_inner(); - - let mut variable: Option = None; - let mut description: Option = None; - - for pair in pairs { - match pair.as_rule() { - Rule::domain => variable = Some(pair.as_str().to_owned()), - Rule::docstring_description => description = Some(pair.as_str().to_owned()), - r => panic!("Rule not implemented: {:?}", r) - } - } - - return ASTUnit::Docstring { - variable, description: description.unwrap(), - } - }, - Rule::docstring_description => { - return ASTUnit::Docstring { variable: None, description: pair.as_str().to_owned()} - }, - r => panic!("Rule not implemented: {:?}", r) - } -} - -/* -pub fn to_parameters(mut pairs: Pairs) -> Vec { - let mut params = vec![]; - - let t = pairs.as_str(); - while let Some(pair) = pairs.next() { - let temp = pair.as_str(); - - params.push(to_parameter(pair.into_inner())); - } - - params -} -*/ - -/* -pub fn to_parameters(mut pairs: Pairs) -> Vec { - let mut params = vec![]; - - while let Some(pair) = pairs.next() { - params.push(to_parameter(pair.into_inner())); - } - - params -} -*/ - - -pub fn to_parameter(pair: Pair) -> ASTUnit { - let mut pairs = pair.into_inner(); - - ASTUnit::Parameter { - name: pairs.next().unwrap().as_str().to_string(), - default_value: pairs.next().unwrap().as_str().to_string() - } -} - -pub fn to_value_other(pair: Pair) -> Option { - let inner = pair.into_inner().next().unwrap(); - - match inner.as_rule() { - Rule::string => Some(inner.as_str().to_string()), - Rule::string_interpolated => Some(inner.as_str().to_string()), - Rule::number => Some(inner.as_str().to_string()), - r => panic!("Rule not implemented in 'value': {:?}", r) - } - - // "".to_string() -} - -pub fn to_field(pair: Pair) -> ASTUnit { - let pairs = pair.into_inner(); - - let mut docstrings: Vec = vec![]; - let mut parameters: Vec = vec![]; - let mut optional: bool = false; - let mut name: Option = None; - let mut kind: Option = None; - let mut default_value: Option = None; - - for pair in pairs { - match pair.as_rule() { - Rule::docstring => docstrings.push(to_docstring(pair)), - Rule::parameter => parameters.push(to_parameter(pair)), - Rule::requirement => optional = true, - Rule::id => name = Some(pair.as_str().to_owned()), - Rule::kind => kind = Some(pair.as_str().to_owned()), - Rule::value => default_value = Some(pair.as_str().to_owned()), - r => panic!("Rule not implemented in 'field': {:?}", r) - } - } - - ASTUnit::Field { - docstring: docstrings, parameters, - optional, name: name.unwrap(), kind: kind.unwrap(), default_value, - } -} - -pub fn to_property(pair: Pair) -> ASTUnit { - let inner = pair.into_inner().next().unwrap(); - - let mut name: Option = None; - let mut expression: Option = None; - - match inner.as_rule() { - Rule::property_domain => name = Some(inner.as_str().to_string()), - Rule::property_expression => expression = Some(inner.as_str().to_string()), - r => panic!("Rule not implemented in 'property': {:?}", r) - } - - ASTUnit::Property { name: name.unwrap(), expression } -} - -/* -fn to_function(pairs: Pairs) -> Function { - let mut index: Option = None; - let mut async_: bool = false; - let mut direction = Direction::Both; - let mut id: Option = None; - let mut arguments: Vec = vec![]; - let parameters: Vec = vec![]; - let returns: Vec = vec![]; - let throws: Vec = vec![]; - - for pair in pairs { - match pair.as_rule() { - Rule::index => index = Some(pair.as_str().parse().unwrap()), - Rule::id => id = Some(pair.as_str().to_owned()), - Rule::direction => direction = match pair.as_str() { - "client" => Direction::Client, - "server" => Direction::Server, - dir => panic!("Direction {:#} does not exist", dir) - }, - Rule::asynchronous => async_ = true, - Rule::argument => { - arguments.push(to_argument(pair.into_inner())) - } - Rule::returns => {} - Rule::parameter => {} - Rule::throw => {} - _ => unreachable!() - } - } - - Function { - index: index.unwrap(), - id: id.unwrap(), - async_, - direction, - arguments, return_: returns, parameters, throws, - } -} -*/ - -/* -fn to_argument(pairs: Pairs) -> Argument { - let mut id: Option = None; - let mut kind: Option = None; - - for pair in pairs { - match pair.as_rule() { - Rule::id => id = Some(pair.as_str().to_owned()), - Rule::kind => kind = Some(primitive::to_type(pair.as_str())), - _ => unreachable!() - } - } - - Argument { id, type_: kind.unwrap() } -} -*/ - -pub fn to_expression_block(pair: Pair) -> ASTUnit { - let inner = pair.into_inner().next().unwrap(); - - // let mut expression = vec![]; - let function_calls: Vec = vec![]; - - match inner.as_rule() { - Rule::function_call => { - // expression.push() - }, - r => panic!("Rule not implemented in 'expression_block': {:?}", r) - } - - ASTUnit::ExpressionBlock { - function_calls - } -} diff --git a/src/schema/ir/compiler/interpreted/frozen/blob.rs b/src/schema/ir/compiler/interpreted/frozen/blob.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/schema/ir/compiler/interpreted/frozen/commit.rs b/src/schema/ir/compiler/interpreted/frozen/commit.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/schema/ir/compiler/interpreted/frozen/mod.rs b/src/schema/ir/compiler/interpreted/frozen/mod.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/schema/ir/compiler/interpreted/frozen/tree.rs b/src/schema/ir/compiler/interpreted/frozen/tree.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/schema/ir/compiler/interpreted/frozen/unit.rs b/src/schema/ir/compiler/interpreted/frozen/unit.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/schema/ir/compiler/interpreted/frozen_unit.rs b/src/schema/ir/compiler/interpreted/frozen_unit.rs deleted file mode 100644 index 6c54382..0000000 --- a/src/schema/ir/compiler/interpreted/frozen_unit.rs +++ /dev/null @@ -1,83 +0,0 @@ -// Standard Uses - -// Local Uses -use crate::ir::compiler::interpreted::primitive::KindValue; - -// External Uses - - -#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)] -pub enum FrozenUnit { - Tag(String), - Namespace(String), - Import(String), - Constant { - docstring: Option, - name: String, - kind_value: KindValue - }, - Property { - name: String, - expression: Option - }, - Parameter { - name: String, - default_value: String - }, - ExpressionBlock { - function_calls: Vec - }, - // - Enum { - docstring: Option, - name: String, - variants: Vec - }, - EnumVariant(KindValue), - Settings { - docstring: Option, - name: String, - parameters: Vec, - }, - Struct { - docstring: Option, - parameters: Vec, - name: String, - fields: Vec, - }, - Protocol { - docstring: String, - parameters: Vec, - name: String, - functions: Vec - }, - Function { - docstring: String, - name: String, - synchronous: bool, - direction: Box, - arguments: Vec, - returns: Vec, - throws: Vec - }, - Error { - docstring: Option, - parameters: Vec, - name: String, - message: String, - fields: Vec - }, - Validator { - docstring: Option, - properties: Vec, - name: String, - expression_block: Box - }, - Field { - docstring: Option, - parameters: Vec, - optional: bool, - name: String, - kind_value: KindValue, - } -} \ No newline at end of file diff --git a/src/schema/ir/compiler/interpreted/interpreter.rs b/src/schema/ir/compiler/interpreted/interpreter.rs deleted file mode 100644 index 065519f..0000000 --- a/src/schema/ir/compiler/interpreted/interpreter.rs +++ /dev/null @@ -1,168 +0,0 @@ -// Standard Uses - -// Local Uses -use crate::ir::context::Context; -use crate::ir::ast::unit::ASTUnit; -use crate::ir::ast::unit; -use crate::ir::compiler::interpreted::frozen_unit::FrozenUnit; -use crate::ir::compiler::interpreted::primitive; -use crate::ir::compiler::interpreted::primitive::KindValue; -use crate::ir::compiler::interpreted::report::ReportDetails; - -// External Uses - - - -pub fn interpret_unit(context: Context) -> Result, ReportDetails> { - let mut interpreted: Vec = vec![]; - - for unit in &context.main.1 { - use crate::ir::ast::unit::ASTUnit::*; - match unit { - Namespace(n) => { - let unit_namespace = context.find_whole_unit_by_import(n); - - if unit_namespace.is_some() { - return Err(ReportDetails { - kind: "Namespace".to_string(), - message: format!( - "Namespace {} used in another schema: {} and {}, \ - only one schema per namespace is allowed", - n, context.main.0.filename(), unit_namespace.unwrap().0.filename() - ), - start: 0, end: 0, - }) - } - - interpreted.push(FrozenUnit::Namespace(n.clone())); - }, - Import(_) => { - let import = interpret_node(&context, unit)?; - interpreted.push(import); - } - Constant { .. } => { - let constant = interpret_node(&context, unit)?; - interpreted.push(constant); - } - Enum { .. } => { - let r#enum = interpret_node(&context, unit)?; - interpreted.push(r#enum); - } - /* - Unit::Settings { .. } => {} - Unit::Struct { .. } => {} - Unit::Protocol { .. } => {} - Unit::Error { .. } => {} - Unit::Validator { .. } => {} - */ - //r => panic!("Left to impl: {:?}", r) - _ => {} - } - } - - - Ok(interpreted) -} - -pub fn interpret_node(context: &Context, node: &ASTUnit) -> Result { - use crate::ir::ast::unit::ASTUnit::*; - match node { - Tag(_) => { - - } - Namespace(n) => { - let mut found: Option<&Context> = None; - - for relative_ctx in &context.relative_contexts { - if unit::namespace(&relative_ctx.main.1) == n { - if found.is_some() { - return Err(ReportDetails { - kind: "namespace".to_string(), - message: format!( - "Found namespace {} when its already declared in {}", - &n, &relative_ctx.main.0.filename() - ), - start: 0, end: 0, - }) - } - - found = Some(relative_ctx) - } - } - } - Import(i) => { - let relative_unit = context.find_whole_unit_by_import(&i); - - if relative_unit.is_none() { - let relative_unit = relative_unit.unwrap(); - - return Err(ReportDetails { - kind: "import".to_string(), - message: format!("Could not find namespace of {}", relative_unit.0.filename()), - start: 0, end: 0, - }) - } - - return Ok(FrozenUnit::Import(i.clone())) - }, - Constant { name, kind, default_value, .. } => { - let kind_value = primitive::to_kind_value(kind, default_value); - - return Ok(FrozenUnit::Constant { - docstring: None, - name: name.clone(), kind_value - }) - } - Enum { name, variants, .. } => { - let mut frozen_variants: Vec = vec![]; - - for variant in variants { - pub(crate) fn to_variant(variant: &ASTUnit) -> KindValue { - match variant { - EnumVariant { name, kind } => { - if kind.is_none() { - return KindValue::EnumVariant( - name.clone(),None - ) - } - - return KindValue::EnumVariant( - name.clone(), None - ) - }, - _ => panic!("Should not be here") - } - } - - frozen_variants.push(FrozenUnit::EnumVariant( - to_variant(variant, ) - )); - } - - return Ok(FrozenUnit::Enum { - docstring: None, - name: name.clone(), variants: frozen_variants - }) - } - /* - EnumVariant { .. } => {} - Settings { .. } => {} - Struct { .. } => {} - Protocol { .. } => {} - Function { .. } => {} - Error { .. } => {} - Validator { .. } => {} - Field { .. } => {} - Parameter { .. } => {} - Property { .. } => {} - ExpressionBlock { .. } => {} - */ - _ => {} - } - - panic!() -} - -pub fn into_frozen_unit() -> FrozenUnit { - todo!() -} diff --git a/src/schema/ir/compiler/interpreted/mod.rs b/src/schema/ir/compiler/interpreted/mod.rs deleted file mode 100644 index 1ca2606..0000000 --- a/src/schema/ir/compiler/interpreted/mod.rs +++ /dev/null @@ -1,10 +0,0 @@ -// Relative Modules -pub mod sanitizer; -pub mod serialization; -pub mod primitive; -pub mod interpreter; -pub mod frozen_unit; -pub mod report; - - -// Standard Uses \ No newline at end of file diff --git a/src/schema/ir/compiler/interpreted/primitive.rs b/src/schema/ir/compiler/interpreted/primitive.rs deleted file mode 100644 index f8c843a..0000000 --- a/src/schema/ir/compiler/interpreted/primitive.rs +++ /dev/null @@ -1,71 +0,0 @@ -// Standard Uses - -// Local Uses - -// External Uses - - -#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)] -// #[repr(u8)] -pub enum Primitive { - U8(Option), U16(Option), - U32(Option), U64(Option), - U128(Option), - - S8(Option), S16(Option), - S32(Option), S64(Option), - S128(Option), - - // Float(f32), Double(f64), - - String(Option), - Namespaced(Option) -} - - -#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)] -pub enum KindValue { - Primitive(Primitive), - EnumVariant(String, Option>), - Union(Vec), - Namespaced(String) -} - - -pub(crate) fn to_kind_value(kind: &String, value: &Option) -> KindValue { - if value.is_none() { - return to_kind_only(kind) - } - - KindValue::Primitive(to_primitive(kind, value.clone().unwrap()).unwrap()) -} - -fn to_kind_only(kind: &str) -> KindValue { - match kind { - &_ => panic!("Cant") - } -} - -fn to_primitive(kind: &str, value: String) -> Option { - use self::Primitive::*; - let kv = match kind { - "u8" => U8(Some(value.parse().unwrap())), - "u16" => U16(Some(value.parse().unwrap())), - "u32" => U32(Some(value.parse().unwrap())), - "u64" => U64(Some(value.parse().unwrap())), - "u128" => U128(Some(value.parse().unwrap())), - - "s8" => S8(Some(value.parse().unwrap())), - "s16" => S16(Some(value.parse().unwrap())), - "s32" => S32(Some(value.parse().unwrap())), - "s64" => S64(Some(value.parse().unwrap())), - "s128" => S128(Some(value.parse().unwrap())), - - "str" => String(Some(value.to_owned())), - _ => { panic!("Got unknown type '{:#}'", kind) } - }; - - Some(kv) -} - - diff --git a/src/schema/ir/compiler/interpreted/report.rs b/src/schema/ir/compiler/interpreted/report.rs deleted file mode 100644 index 9ddc966..0000000 --- a/src/schema/ir/compiler/interpreted/report.rs +++ /dev/null @@ -1,43 +0,0 @@ -// Standard Uses - -// Local Uses -use crate::ir::context::Context; - -// External Uses -use ariadne::{Color, Fmt, Label, Report, ReportKind, Source}; - - -#[derive(Debug)] -pub struct ReportDetails { - pub(crate) kind: String, pub(crate) message: String, - pub(crate) start: usize, pub(crate) end: usize -} - -pub fn report_errors(context: Context, errors: Vec) { - let out = Color::Fixed(81); - - let provenance = context.main.0.provenance_details(); - let mut source = (&provenance.0, Source::from(provenance.1)); - - errors.into_iter().for_each(|e| { - Report::build(ReportKind::Error, &provenance.0, 12) - .with_code(3) - .with_message(e.message) - .with_label( - Label::new((&provenance.0, e.start..e.end)) - .with_message(format!("This is of type {}", e.kind.fg(out))) - .with_color(out), - ) - .finish() - .print(&mut source) - .unwrap(); - }); -} - - -#[allow(unused)] -pub fn report_warnings(context: Context, warnings: Vec) { - todo!() -} - - diff --git a/src/schema/ir/compiler/interpreted/sanitizer.rs b/src/schema/ir/compiler/interpreted/sanitizer.rs deleted file mode 100644 index f73a9a1..0000000 --- a/src/schema/ir/compiler/interpreted/sanitizer.rs +++ /dev/null @@ -1,12 +0,0 @@ -// Standard Uses - -// Local Uses -use crate::ir::context::Context; - -// External Uses - - -#[allow(unused)] -fn sanitize_context_units(context: &Context) { - todo!() -} diff --git a/src/schema/ir/compiler/interpreted/serialization/messagepack.rs b/src/schema/ir/compiler/interpreted/serialization/messagepack.rs deleted file mode 100644 index 3e5f154..0000000 --- a/src/schema/ir/compiler/interpreted/serialization/messagepack.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Standard Uses - -// Local Uses -use crate::ir::ast::unit::ASTUnit; - -// External Uses -#[allow(unused)] -use rmp; - - -// https://docs.rs/rmp/latest/rmp/ -#[allow(unused)] -fn from_bytes(raw: Vec) -> ASTUnit { - todo!() -} - -#[allow(unused)] -fn to_bytes(unit: ASTUnit) -> Vec { - todo!() -} diff --git a/src/schema/ir/compiler/interpreted/serialization/mod.rs b/src/schema/ir/compiler/interpreted/serialization/mod.rs deleted file mode 100644 index 8eaa988..0000000 --- a/src/schema/ir/compiler/interpreted/serialization/mod.rs +++ /dev/null @@ -1,13 +0,0 @@ -// Relative Modules -mod messagepack; - -// Standard Uses - -// Local Uses - -// External Uses - - -#[allow(unused)] -pub struct Origin {} - diff --git a/src/schema/ir/compiler/interpreter/incremental.rs b/src/schema/ir/compiler/interpreter/incremental.rs deleted file mode 100644 index a8fc4b2..0000000 --- a/src/schema/ir/compiler/interpreter/incremental.rs +++ /dev/null @@ -1,173 +0,0 @@ -// Standard Uses - -// Local Uses -use crate::ir::ast::unit; -use crate::ir::ast::unit::ASTUnit; -use crate::ir::compiler::Compile; -use crate::ir::compiler::interpreted::frozen_unit::FrozenUnit; -use crate::ir::compiler::interpreted::primitive; -use crate::ir::compiler::interpreted::primitive::KindValue; -use crate::ir::compiler::interpreted::report::ReportDetails; -use crate::ir::context::Context; - -// External Uses - - -#[allow(unused)] -pub struct IncrementalInterpreter { - context: Context -} - -#[allow(unused)] -impl Compile for IncrementalInterpreter { - type Output = (); - - fn from_ast(ast: Vec) -> Self::Output { - todo!() - } -} - -#[allow(unused)] -impl IncrementalInterpreter { - pub fn interpret_unit(&self) -> Result, ReportDetails> { - let mut interpreted: Vec = vec![]; - - for unit in &self.context.main.1 { - use crate::ir::ast::unit::ASTUnit::*; - match unit { - Namespace(n) => { - // let namespace = n; - interpreted.push(FrozenUnit::Namespace(n.clone())); - }, - Import(_) => { - let import = self.interpret_node( unit)?; - interpreted.push(import); - } - Constant { .. } => { - let constant = self.interpret_node(unit)?; - interpreted.push(constant); - } - Enum { .. } => { - let r#enum = self.interpret_node( unit)?; - interpreted.push(r#enum); - } - /* - Unit::Settings { .. } => {} - Unit::Struct { .. } => {} - Unit::Protocol { .. } => {} - Unit::Error { .. } => {} - Unit::Validator { .. } => {} - */ - //r => panic!("Left to impl: {:?}", r) - _ => {} - } - } - - - Ok(interpreted) - } - - pub fn interpret_node(&self, node: &ASTUnit) -> Result { - use crate::ir::ast::unit::ASTUnit::*; - match node { - Tag(_) => { - - } - Namespace(n) => { - let mut found: Option<&Context> = None; - - for relative_ctx in &self.context.relative_contexts { - if unit::namespace(&relative_ctx.main.1) == n { - if found.is_some() { - return Err(ReportDetails { - kind: "namespace".to_string(), - message: format!( - "Found namespace {} when its already declared in {}", - &n, &relative_ctx.main.0.filename() - ), - start: 0, end: 0, - }) - } - - found = Some(relative_ctx) - } - } - } - Import(i) => { - let relative_unit = self.context.find_whole_unit_by_import(&i); - - if relative_unit.is_none() { - let relative_unit = relative_unit.unwrap(); - - return Err(ReportDetails { - kind: "import".to_string(), - message: format!("Could not find namespace of {}", relative_unit.0.filename()), - start: 0, end: 0, - }) - } - - return Ok(FrozenUnit::Import(i.clone())) - }, - Constant { name, kind, default_value, .. } => { - let kind_value = primitive::to_kind_value(kind, default_value); - - return Ok(FrozenUnit::Constant { - docstring: None, - name: name.clone(), kind_value - }) - } - Enum { name, variants, .. } => { - let mut frozen_variants: Vec = vec![]; - - for variant in variants { - pub(crate) fn to_variant(variant: &ASTUnit) -> KindValue { - match variant { - EnumVariant { name, kind } => { - if kind.is_none() { - return KindValue::EnumVariant( - name.clone(),None - ) - } - - return KindValue::EnumVariant( - name.clone(), None - ) - }, - _ => panic!("Should not be here") - } - } - - frozen_variants.push(FrozenUnit::EnumVariant( - to_variant(variant, ) - )); - } - - return Ok(FrozenUnit::Enum { - docstring: None, - name: name.clone(), variants: frozen_variants - }) - } - /* - EnumVariant { .. } => {} - Settings { .. } => {} - Struct { .. } => {} - Protocol { .. } => {} - Function { .. } => {} - Error { .. } => {} - Validator { .. } => {} - Field { .. } => {} - Parameter { .. } => {} - Property { .. } => {} - ExpressionBlock { .. } => {} - */ - _ => {} - } - - panic!() - } - -} - -pub fn into_frozen_unit() -> FrozenUnit { - todo!() -} diff --git a/src/schema/ir/compiler/interpreter/mod.rs b/src/schema/ir/compiler/interpreter/mod.rs deleted file mode 100644 index b49a974..0000000 --- a/src/schema/ir/compiler/interpreter/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod incremental; \ No newline at end of file diff --git a/src/schema/ir/compiler/interpreter/relations.rs b/src/schema/ir/compiler/interpreter/relations.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/schema/ir/compiler/mod.rs b/src/schema/ir/compiler/mod.rs deleted file mode 100644 index fc0011a..0000000 --- a/src/schema/ir/compiler/mod.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Relative Modules -pub mod interpreter; -pub mod interpreted; - -// Standard Uses - -// Local Uses -use crate::idl::parser; -use crate::ir::ast::unit::ASTUnit; - -// External Uses - - - -pub trait Compile { - type Output; - - fn from_ast(ast: Vec) -> Self::Output; - - fn from_source(source: &str) -> Self::Output { - println!("Compiling source: {}", source); - let ast: Vec = parser::parse_into_unit(source).unwrap(); - println!("{:?}", ast); - Self::from_ast(ast) - } -} diff --git a/src/schema/ir/context.rs b/src/schema/ir/context.rs deleted file mode 100644 index c261413..0000000 --- a/src/schema/ir/context.rs +++ /dev/null @@ -1,51 +0,0 @@ -// Standard Uses - -// Local Uses -use crate::ir::ast::unit::WholeUnit; -use crate::stdlib; - -// External Uses - - -pub struct Context { - pub main: WholeUnit, - pub relative_contexts: Vec, - - -} - -#[allow(unused)] -impl Context { - pub fn with_main(main: WholeUnit) -> Self{ - Context { main, relative_contexts: vec![] } - } - - pub(crate) fn add_relative_unit(mut self, whole_unit: WholeUnit) { - self.relative_contexts.push( - Context::with_main(whole_unit) - ) - } - - pub(crate) fn add_relative_context(mut self, context: Context) { - todo!() - } - - pub(crate) fn sanitize_units(self) { - todo!() - } - - pub(crate) fn find_whole_unit_by_import(&self, import: &str) -> Option<&WholeUnit> { - let stdlib_unit = stdlib::find_unit(import); - - if stdlib_unit.is_some() { - return Some(stdlib_unit.unwrap()) - } - - None - } - - pub(crate) fn find_context(&self, import: &str) -> Option<&Context> { - todo!() - } -} - diff --git a/src/schema/ir/mod.rs b/src/schema/ir/mod.rs deleted file mode 100644 index 9392140..0000000 --- a/src/schema/ir/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -// Relative Modules -pub mod context; -pub mod ast; -pub mod compiler; diff --git a/src/schema/mod.rs b/src/schema/mod.rs deleted file mode 100644 index e69de29..0000000 diff --git a/tests/idl/congregation.idc b/tests/idl/congregation.idc deleted file mode 100644 index e69de29..0000000 diff --git a/tests/idl/units/dev.ids b/tests/idl/units/dev.ids deleted file mode 100644 index 5cd911e..0000000 --- a/tests/idl/units/dev.ids +++ /dev/null @@ -1,27 +0,0 @@ -namespace example - -const PROTOCOL: u8 = 0 -const SECRET: u8 = 1 - -enum Motion { - 1# Wave - 2# MoveArm -} - -struct Hello { - const SHAKE: u8 = 20 - - 1# name: u8 -} - -struct Goodbye versioned=false { - wave: bool = false -} - -protocol Greet { - function smile - function wave () - function wave_wait () -> u8 - function wave_and_go () -> str : timeout_ms=100 - function wave_with (motion: Motion) -} diff --git a/tests/idl/units/mod.rs b/tests/idl/units/mod.rs deleted file mode 100644 index 57d165d..0000000 --- a/tests/idl/units/mod.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Standard Uses - -// Local Uses - -// External Uses -use once_cell::sync::Lazy; -use comline::schema::idl; -use comline::schema::idl::ast::unit::ASTUnit; - - -// Unit with a namespace and a constant -#[allow(unused)] -static UNIT_NAMESPACE_CONST_1: Lazy> = Lazy::new( || { - vec![ - ASTUnit::Namespace("units::test".to_owned()), - ASTUnit::Constant { - docstring: vec![], - name: "VERSION".to_owned(), - kind: "u8".to_owned(), - default_value: Some("1".to_owned()), - } - ] -}); - - -#[test] -fn parse_const() { - let syntax = "const VERSION: u8 = 1"; - let ast = idl::parser::parse_into_unit(syntax).unwrap(); - - pretty_assertions::assert_eq!(*UNIT_NAMESPACE_CONST_1, ast); -} diff --git a/tests/idl/units/protocol/args.ids b/tests/idl/units/protocol/args.ids deleted file mode 100644 index ff4af56..0000000 --- a/tests/idl/units/protocol/args.ids +++ /dev/null @@ -1,12 +0,0 @@ -namespace units.protocols_args - -protocol Proposals { - function call(Args) - function call(kind: u8, name: str, message: str) -} - -struct Args { - kind: u8 - name: str - message: str -} diff --git a/tests/ir/mod.rs b/tests/ir/mod.rs deleted file mode 100644 index e69de29..0000000 diff --git a/tests/stdlib/mod.rs b/tests/stdlib/mod.rs deleted file mode 100644 index e69de29..0000000 diff --git a/tests/stdlib/validators.rs b/tests/stdlib/validators.rs deleted file mode 100644 index e69de29..0000000