The prelude library, coming from basegl, in preparation for AST. (#342)

This commit is contained in:
Michał Wawrzyniec Urbańczyk 2019-11-19 22:26:54 +01:00 committed by GitHub
parent 427e784663
commit d1796345a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 77 additions and 8 deletions

View File

@ -1,5 +1,6 @@
[workspace]
members = [
"common/rust/parser"
"common/rust/parser",
"common/rust/prelude"
]

View File

@ -10,7 +10,8 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
failure = "0.1"
matches = "0.1"
serde = { version = "1.0", features = ["derive"] }
prelude = { version = "0.1.0", path = "../prelude" }
serde = { version = "1.0" , features = ["derive"] }
serde_json = "1.0"
shrinkwraprs = "0.2.1"
wasm-bindgen = "0.2"

View File

@ -1,4 +1,4 @@
use failure::Fail;
use prelude::*;
// ============
// == Parser ==

View File

@ -1,5 +1,5 @@
use crate::{api, api::IsParser};
use failure::Fail;
use prelude::*;
pub type Result<T> = std::result::Result<T, Error>;

View File

@ -1,16 +1,17 @@
pub mod api;
use prelude::*;
mod jsclient;
mod wsclient;
use std::ops::DerefMut;
/// Handle to a parser implementation.
///
/// Currently this component is implemented as a wrapper over parser written
/// in Scala. Depending on compilation target (native or wasm) it uses either
/// implementation provided by `wsclient` or `jsclient`.
#[derive(shrinkwraprs::Shrinkwrap)]
#[derive(Shrinkwrap)]
#[shrinkwrap(mutable)]
pub struct Parser(pub Box<dyn api::IsParser>);

View File

@ -1,7 +1,7 @@
#![cfg(not(target_arch = "wasm32"))]
use failure::Fail;
use std::default::Default;
use prelude::*;
use websocket::{
stream::sync::TcpStream, ClientBuilder, Message, OwnedMessage,
};

View File

@ -0,0 +1,16 @@
[package]
name = "prelude"
version = "0.1.0"
authors = ["Wojciech Danilo <wojciech.danilo@luna-lang.org>"]
edition = "2018"
[lib]
[dependencies]
failure = "0.1.5"
derive_more = "0.15.0"
shrinkwraprs = "0.2.1"
itertools = "0.8"
derivative = "1.0.3"
num = "0.2.0"
boolinator = "2.4.0"

View File

@ -0,0 +1,50 @@
#![feature(trait_alias)]
pub use boolinator::Boolinator;
pub use core::{any::type_name, fmt::Debug};
pub use derivative::Derivative;
pub use derive_more::*;
pub use failure::Fail;
pub use itertools::Itertools;
pub use num::Num;
pub use shrinkwraprs::Shrinkwrap;
pub use std::{
cell::{Ref, RefCell},
collections::{HashMap, HashSet},
convert::{identity, TryFrom, TryInto},
fmt::Display,
hash::Hash,
iter,
iter::FromIterator,
marker::PhantomData,
ops::{Deref, DerefMut, Index, IndexMut},
rc::{Rc, Weak},
slice,
slice::SliceIndex,
};
pub trait Str = AsRef<str>;
pub fn default<T: Default>() -> T {
Default::default()
}
#[derive(Derivative, Shrinkwrap)]
#[shrinkwrap(mutable)]
#[derivative(Clone(bound = "T: Clone"))]
pub struct WithPhantomType<T, P = ()> {
#[shrinkwrap(main_field)]
pub t: T,
phantom: PhantomData<P>,
}
impl<T, P> WithPhantomType<T, P> {
pub fn new(t: T) -> Self {
let phantom = PhantomData;
Self { t, phantom }
}
}
pub fn with<T, F: FnOnce(T) -> Out, Out>(t: T, f: F) -> Out {
f(t)
}