More Work

This commit is contained in:
DOOM1EM8Cover 2023-08-28 20:10:43 +01:00
parent 965058def2
commit c6994ab672
50 changed files with 6 additions and 1718 deletions

1
core_stdlib/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

View file

@ -1,24 +0,0 @@
/*
trait Registry {
fn register(message: Credentials) -> RegisterStatus;
fn my_username() -> String;
fn tell_back(message: String) -> Result<String, TellBackError>;
}
#[derive(ValidatorStringBounds<[u8; 8]>)]
struct Credentials {
}
struct RegisterStatus {
}
struct TellBackError {
}
*/
fn main() { todo!() }

1
package-manager-server/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

2
package-manager/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/target
/Cargo.lock

View file

@ -1,6 +0,0 @@
// TODO: Think what »discoverable« should mean, just like Fuchsia IDL
@discoverable
protocol OpenWorld {
}

View file

@ -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]
}

2
runtime/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/target
/Cargo.lock

View file

View file

View file

@ -1,7 +0,0 @@
//
// Created by intellij-pest on 2023-07-07
// idc
// Author: nibunta
//
idc = { "Hello World!" }

View file

View file

@ -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() -> {
}

View file

View file

View file

@ -1,3 +0,0 @@
// Relative Modules
pub mod unit;
pub mod old_unit;

View file

@ -1,116 +0,0 @@
// Standard Uses
// Local Uses
// External Uses
/*
/// Intermediate Representation Unit
#[allow(unused)]
#[derive(Debug, Eq, PartialEq)]
pub enum Unit {
Items(Vec<Unit>),
Tag(String),
Namespace(String),
Imports(String),
Settings(Vec<Settings>),
Consts(Vec<Const>),
Structs(Vec<Struct>),
Enums(Vec<Enum>),
Errors(Vec<Error>),
Protocols(Vec<Protocol>)
}
#[derive(Debug, Eq, PartialEq)]
pub struct Settings {
pub id: String,
pub parameters: Vec<Parameter>,
}
#[derive(Debug, Eq, PartialEq)]
pub struct Const {
pub id: String,
pub type_: Kind,
pub default_value: Vec<u8>
}
#[allow(unused)]
#[derive(Debug, Eq, PartialEq)]
pub struct Struct {
pub id: String,
pub parameters: Vec<Parameter>,
pub fields: Vec<Field>,
}
#[allow(unused)]
#[derive(Debug, Eq, PartialEq)]
pub struct Enum {
pub id: String,
pub variants: Vec<EnumVariant>
}
#[allow(unused)]
#[derive(Debug, Eq, PartialEq)]
pub struct EnumVariant {
pub id: String,
pub type_: Option<Kind>
}
#[allow(unused)]
#[derive(Debug, Eq, PartialEq)]
pub struct Error {
pub id: String,
pub parameters: Vec<Parameter>,
pub fields: Vec<Field>,
}
#[allow(unused)]
#[derive(Debug, Eq, PartialEq)]
pub struct Parameter {
pub id: String,
pub value: Vec<u8>
}
#[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<u8>,
}
#[allow(unused)]
#[derive(Debug, Eq, PartialEq)]
pub struct Protocol {
pub id: String,
pub parameters: Vec<Parameter>,
pub functions: Vec<Function>
}
#[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<Argument>,
pub return_: Vec<Kind>,
pub parameters: Vec<Parameter>,
pub throws: Vec<String>
}
#[allow(unused)]
#[derive(Debug, Eq, PartialEq)]
pub struct Argument {
pub id: Option<String>,
pub type_: Kind
}
*/

View file

@ -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<String>,
constants: Vec<Unit>,
settings: Vec<Unit>,
enums: Vec<Unit>,
structures: Vec<Unit>,
validators: Vec<Unit>,
errors: Vec<Unit>,
protocols: Vec<Unit>
},
*/
Tag(String),
Namespace(String),
Import(String),
Docstring {
variable: Option<String>,
description: String
},
Constant {
docstring: Vec<ASTUnit>,
name: String,
kind: String,
default_value: Option<String>,
},
Property {
name: String,
expression: Option<String>
},
Parameter {
name: String,
default_value: String
},
ExpressionBlock {
function_calls: Vec<String>
},
//
Enum {
docstring: Vec<ASTUnit>,
name: String,
variants: Vec<ASTUnit>
},
EnumVariant {
name: String,
kind: Option<String>
},
Settings {
docstring: Vec<ASTUnit>,
name: String,
parameters: Vec<ASTUnit>,
},
Struct {
docstring: Vec<ASTUnit>,
parameters: Vec<ASTUnit>,
name: String,
fields: Vec<ASTUnit>,
},
Protocol {
docstring: Vec<ASTUnit>,
parameters: Vec<ASTUnit>,
name: String,
functions: Vec<ASTUnit>
},
Function {
docstring: Vec<ASTUnit>,
name: String,
synchronous: bool,
direction: Direction,
arguments: Vec<ASTUnit>,
returns: Vec<ASTUnit>,
throws: Vec<ASTUnit>
},
Error {
docstring: Vec<ASTUnit>,
parameters: Vec<ASTUnit>,
name: String,
message: String,
fields: Vec<ASTUnit>
},
Validator {
docstring: Vec<ASTUnit>,
properties: Vec<ASTUnit>,
name: String,
expression_block: Box<ASTUnit>
},
Field {
docstring: Vec<ASTUnit>,
parameters: Vec<ASTUnit>,
// index: OrderIndex,
optional: bool,
name: String,
kind: String,
default_value: Option<String>,
}
}
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<Unit>
},
Node {
index: u32,
start_position: u32, length: u32
}
}
#[derive(PartialEq, Debug)]
pub struct VIndex {
pub meta: UnitIndex,
pub nodes: Vec<UnitIndex>
}
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<ASTUnit>;
pub type WholeUnit = (VIndex, VUnit);

View file

@ -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";

View file

@ -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)*
~ "*/"
}

View file

@ -1,3 +0,0 @@
// Relative Modules
pub mod parser;
pub mod constants;

View file

@ -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<WholeUnit> {
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<VUnit> {
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<Rule>) -> Result<ASTUnit> {
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<ASTUnit> = vec![];
let mut id: Option<String> = None;
let mut kind: Option<String> = None;
let mut default_value: Option<String> = 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<ASTUnit> = vec![];
let mut name: Option<String> = None;
let mut parameters: Vec<ASTUnit> = 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<ASTUnit> = vec![];
let mut name: Option<String> = None;
let mut variants: Vec<ASTUnit> = 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<ASTUnit> = vec![];
let mut parameters: Vec<ASTUnit> = vec![];
let mut name: Option<String> = None;
let mut fields: Vec<ASTUnit> = 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<ASTUnit> = vec![];
let mut properties: Vec<ASTUnit> = vec![];
let mut name: Option<String> = None;
let mut expression_block: Option<ASTUnit> = 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<Rule>) -> ASTUnit {
let pair = pair.into_inner().next().unwrap();
match pair.as_rule() {
Rule::docstring_property => {
let pairs = pair.into_inner();
let mut variable: Option<String> = None;
let mut description: Option<String> = 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<Rule>) -> Vec<Unit> {
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<Rule>) -> Vec<Parameter> {
let mut params = vec![];
while let Some(pair) = pairs.next() {
params.push(to_parameter(pair.into_inner()));
}
params
}
*/
pub fn to_parameter(pair: Pair<Rule>) -> 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<Rule>) -> Option<String> {
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<Rule>) -> ASTUnit {
let pairs = pair.into_inner();
let mut docstrings: Vec<ASTUnit> = vec![];
let mut parameters: Vec<ASTUnit> = vec![];
let mut optional: bool = false;
let mut name: Option<String> = None;
let mut kind: Option<String> = None;
let mut default_value: Option<String> = 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<Rule>) -> ASTUnit {
let inner = pair.into_inner().next().unwrap();
let mut name: Option<String> = None;
let mut expression: Option<String> = 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<Rule>) -> Function {
let mut index: Option<u8> = None;
let mut async_: bool = false;
let mut direction = Direction::Both;
let mut id: Option<String> = None;
let mut arguments: Vec<Argument> = vec![];
let parameters: Vec<Parameter> = vec![];
let returns: Vec<TypeValue> = vec![];
let throws: Vec<String> = 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<Rule>) -> Argument {
let mut id: Option<String> = None;
let mut kind: Option<TypeValue> = 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<Rule>) -> ASTUnit {
let inner = pair.into_inner().next().unwrap();
// let mut expression = vec![];
let function_calls: Vec<String> = vec![];
match inner.as_rule() {
Rule::function_call => {
// expression.push()
},
r => panic!("Rule not implemented in 'expression_block': {:?}", r)
}
ASTUnit::ExpressionBlock {
function_calls
}
}

View file

@ -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<String>,
name: String,
kind_value: KindValue
},
Property {
name: String,
expression: Option<String>
},
Parameter {
name: String,
default_value: String
},
ExpressionBlock {
function_calls: Vec<String>
},
//
Enum {
docstring: Option<String>,
name: String,
variants: Vec<FrozenUnit>
},
EnumVariant(KindValue),
Settings {
docstring: Option<String>,
name: String,
parameters: Vec<FrozenUnit>,
},
Struct {
docstring: Option<String>,
parameters: Vec<FrozenUnit>,
name: String,
fields: Vec<FrozenUnit>,
},
Protocol {
docstring: String,
parameters: Vec<FrozenUnit>,
name: String,
functions: Vec<FrozenUnit>
},
Function {
docstring: String,
name: String,
synchronous: bool,
direction: Box<FrozenUnit>,
arguments: Vec<FrozenUnit>,
returns: Vec<FrozenUnit>,
throws: Vec<FrozenUnit>
},
Error {
docstring: Option<String>,
parameters: Vec<FrozenUnit>,
name: String,
message: String,
fields: Vec<FrozenUnit>
},
Validator {
docstring: Option<String>,
properties: Vec<FrozenUnit>,
name: String,
expression_block: Box<FrozenUnit>
},
Field {
docstring: Option<String>,
parameters: Vec<FrozenUnit>,
optional: bool,
name: String,
kind_value: KindValue,
}
}

View file

@ -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<Vec<FrozenUnit>, ReportDetails> {
let mut interpreted: Vec<FrozenUnit> = 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<FrozenUnit, ReportDetails> {
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<FrozenUnit> = 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!()
}

View file

@ -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

View file

@ -1,71 +0,0 @@
// Standard Uses
// Local Uses
// External Uses
#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
// #[repr(u8)]
pub enum Primitive {
U8(Option<u8>), U16(Option<u16>),
U32(Option<u32>), U64(Option<u64>),
U128(Option<u128>),
S8(Option<u8>), S16(Option<u16>),
S32(Option<u32>), S64(Option<u64>),
S128(Option<u128>),
// Float(f32), Double(f64),
String(Option<String>),
Namespaced(Option<String>)
}
#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
pub enum KindValue {
Primitive(Primitive),
EnumVariant(String, Option<Box<KindValue>>),
Union(Vec<KindValue>),
Namespaced(String)
}
pub(crate) fn to_kind_value(kind: &String, value: &Option<String>) -> 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<Primitive> {
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)
}

View file

@ -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<ReportDetails>) {
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<ReportDetails>) {
todo!()
}

View file

@ -1,12 +0,0 @@
// Standard Uses
// Local Uses
use crate::ir::context::Context;
// External Uses
#[allow(unused)]
fn sanitize_context_units(context: &Context) {
todo!()
}

View file

@ -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<u8>) -> ASTUnit {
todo!()
}
#[allow(unused)]
fn to_bytes(unit: ASTUnit) -> Vec<u8> {
todo!()
}

View file

@ -1,13 +0,0 @@
// Relative Modules
mod messagepack;
// Standard Uses
// Local Uses
// External Uses
#[allow(unused)]
pub struct Origin {}

View file

@ -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<ASTUnit>) -> Self::Output {
todo!()
}
}
#[allow(unused)]
impl IncrementalInterpreter {
pub fn interpret_unit(&self) -> Result<Vec<FrozenUnit>, ReportDetails> {
let mut interpreted: Vec<FrozenUnit> = 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<FrozenUnit, ReportDetails> {
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<FrozenUnit> = 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!()
}

View file

@ -1 +0,0 @@
pub mod incremental;

View file

@ -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<ASTUnit>) -> Self::Output;
fn from_source(source: &str) -> Self::Output {
println!("Compiling source: {}", source);
let ast: Vec<ASTUnit> = parser::parse_into_unit(source).unwrap();
println!("{:?}", ast);
Self::from_ast(ast)
}
}

View file

@ -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<Context>,
}
#[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!()
}
}

View file

@ -1,4 +0,0 @@
// Relative Modules
pub mod context;
pub mod ast;
pub mod compiler;

View file

View file

@ -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)
}

View file

@ -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<Vec<ASTUnit>> = 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);
}

View file

@ -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
}

View file

View file