mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 20:26:42 +01:00
73 lines
2.7 KiB
Rust
73 lines
2.7 KiB
Rust
#![feature(adt_const_params)]
|
|
#![feature(type_alias_impl_trait)]
|
|
#![feature(impl_trait_in_fn_trait_return)]
|
|
mod error; pub use self::error::*;
|
|
mod token; pub use self::token::*;
|
|
mod atom; pub use self::atom::*;
|
|
mod atom_ref; pub use self::atom_ref::*;
|
|
mod atom_arc; pub use self::atom_arc::*;
|
|
mod context; pub use self::context::*;
|
|
pub(crate) use self::ParseError::*;
|
|
//pub(crate) use self::TokenKind::*;
|
|
pub(crate) use std::sync::Arc;
|
|
//pub(crate) use std::marker::ConstParamTy;
|
|
pub(crate) use itertools::join;
|
|
pub(crate) use konst::iter::{ConstIntoIter, IsIteratorKind};
|
|
pub(crate) use konst::string::{split_at, str_range, char_indices};
|
|
pub(crate) use std::error::Error;
|
|
pub(crate) use std::fmt::{Debug, Display, Formatter, Result as FormatResult, Error as FormatError};
|
|
/// Static iteration helper.
|
|
#[macro_export] macro_rules! iterate {
|
|
($expr:expr => $arg: pat => $body:expr) => {
|
|
let mut iter = $expr;
|
|
while let Some(($arg, next)) = iter.next() {
|
|
$body;
|
|
iter = next;
|
|
}
|
|
}
|
|
}
|
|
/// Implement the const iterator pattern.
|
|
#[macro_export] macro_rules! const_iter {
|
|
($(<$l:lifetime>)?|$self:ident: $Struct:ty| => $Item:ty => $expr:expr) => {
|
|
impl$(<$l>)? Iterator for $Struct {
|
|
type Item = $Item;
|
|
fn next (&mut $self) -> Option<$Item> { $expr }
|
|
}
|
|
impl$(<$l>)? ConstIntoIter for $Struct {
|
|
type Kind = IsIteratorKind;
|
|
type Item = $Item;
|
|
type IntoIter = Self;
|
|
}
|
|
}
|
|
}
|
|
#[cfg(test)] #[test] fn test_lang () -> Result<(), ParseError> {
|
|
use Atom::*;
|
|
assert_eq!(Atom::read_all("")?,
|
|
vec![]);
|
|
assert_eq!(Atom::read_all(" ")?,
|
|
vec![]);
|
|
assert_eq!(Atom::read_all("1234")?,
|
|
vec![Num(1234)]);
|
|
assert_eq!(Atom::read_all("1234 5 67")?,
|
|
vec![Num(1234), Num(5), Num(67)]);
|
|
assert_eq!(Atom::read_all("foo/bar")?,
|
|
vec![Key("foo/bar".into())]);
|
|
assert_eq!(Atom::read_all(":symbol")?,
|
|
vec![Sym(":symbol".into())]);
|
|
assert_eq!(Atom::read_all(" foo/bar :baz 456")?,
|
|
vec![Key("foo/bar".into()), Sym(":baz".into()), Num(456)]);
|
|
assert_eq!(Atom::read_all(" (foo/bar :baz 456) ")?,
|
|
vec![Exp(vec![Key("foo/bar".into()), Sym(":baz".into()), Num(456)])]);
|
|
Ok(())
|
|
}
|
|
#[cfg(test)] #[test] fn test_lang_examples () -> Result<(), ParseError> {
|
|
for example in [
|
|
include_str!("../../tui/examples/edn01.edn"),
|
|
include_str!("../../tui/examples/edn02.edn"),
|
|
] {
|
|
let items = Atom::read_all(example)?;
|
|
//panic!("{layout:?}");
|
|
//let content = <dyn ViewContext<::tek_engine::tui::Tui>>::from(&layout);
|
|
}
|
|
Ok(())
|
|
}
|