mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 03:36:42 +01:00
This commit is contained in:
parent
2b208e3c49
commit
0d4ba4a54e
3 changed files with 43 additions and 25 deletions
|
|
@ -86,6 +86,8 @@ pub const fn peek_src <'a> (source: &'a str) -> Option<Token<'a>> {
|
||||||
token.grow(),
|
token.grow(),
|
||||||
'(' =>
|
'(' =>
|
||||||
Token::new(source, start, 1, Exp(1, TokenIter::new(str_range(source, start, start + 1)))),
|
Token::new(source, start, 1, Exp(1, TokenIter::new(str_range(source, start, start + 1)))),
|
||||||
|
'"' =>
|
||||||
|
Token::new(source, start, 1, Str(str_range(source, start, start + 1))),
|
||||||
':'|'@' =>
|
':'|'@' =>
|
||||||
Token::new(source, start, 1, Sym(str_range(source, start, start + 1))),
|
Token::new(source, start, 1, Sym(str_range(source, start, start + 1))),
|
||||||
'/'|'a'..='z' =>
|
'/'|'a'..='z' =>
|
||||||
|
|
@ -97,6 +99,10 @@ pub const fn peek_src <'a> (source: &'a str) -> Option<Token<'a>> {
|
||||||
}),
|
}),
|
||||||
_ => token.error(Unexpected(c))
|
_ => token.error(Unexpected(c))
|
||||||
},
|
},
|
||||||
|
Str(s) => match c {
|
||||||
|
'"' => return Some(token),
|
||||||
|
_ => token.grow_str(),
|
||||||
|
},
|
||||||
Num(n) => match c {
|
Num(n) => match c {
|
||||||
'0'..='9' => token.grow_num(n, c),
|
'0'..='9' => token.grow_num(n, c),
|
||||||
' '|'\n'|'\r'|'\t'|')' => return Some(token),
|
' '|'\n'|'\r'|'\t'|')' => return Some(token),
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ use crate::*;
|
||||||
Num(usize),
|
Num(usize),
|
||||||
Sym(&'a str),
|
Sym(&'a str),
|
||||||
Key(&'a str),
|
Key(&'a str),
|
||||||
|
Str(&'a str),
|
||||||
Exp(usize, TokenIter<'a>),
|
Exp(usize, TokenIter<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,6 +81,11 @@ impl<'a> Token<'a> {
|
||||||
token.value = Sym(token.slice_source(self.source));
|
token.value = Sym(token.slice_source(self.source));
|
||||||
token
|
token
|
||||||
}
|
}
|
||||||
|
pub const fn grow_str (self) -> Self {
|
||||||
|
let mut token = self.grow();
|
||||||
|
token.value = Str(token.slice_source(self.source));
|
||||||
|
token
|
||||||
|
}
|
||||||
pub const fn grow_exp (self) -> Self {
|
pub const fn grow_exp (self) -> Self {
|
||||||
let mut token = self.grow();
|
let mut token = self.grow();
|
||||||
if let Exp(depth, _) = token.value {
|
if let Exp(depth, _) = token.value {
|
||||||
|
|
|
||||||
|
|
@ -14,31 +14,6 @@ mod dsl_iter; pub use self::dsl_iter::*;
|
||||||
mod dsl_context; pub use self::dsl_context::*;
|
mod dsl_context; pub use self::dsl_context::*;
|
||||||
mod dsl_macros;
|
mod dsl_macros;
|
||||||
|
|
||||||
//#[cfg(test)] #[test] fn test_examples () -> Result<(), ParseError> {
|
|
||||||
//// Let's pretend to render some view.
|
|
||||||
//let source = include_str!("../../tek/src/view_arranger.edn");
|
|
||||||
//// The token iterator allows you to get the tokens represented by the source text.
|
|
||||||
//let mut view = TokenIter(source);
|
|
||||||
//// The token iterator wraps a const token+source iterator.
|
|
||||||
//assert_eq!(view.0.0, source);
|
|
||||||
//let mut expr = view.peek();
|
|
||||||
//assert_eq!(view.0.0, source);
|
|
||||||
//assert_eq!(expr, Some(Token {
|
|
||||||
//source, start: 0, length: source.len() - 1, value: Exp(0, SourceIter(&source[1..]))
|
|
||||||
//}));
|
|
||||||
////panic!("{view:?}");
|
|
||||||
////panic!("{:#?}", expr);
|
|
||||||
////for example in [
|
|
||||||
////include_str!("../../tui/examples/edn01.edn"),
|
|
||||||
////include_str!("../../tui/examples/edn02.edn"),
|
|
||||||
////] {
|
|
||||||
//////let items = Dsl::read_all(example)?;
|
|
||||||
//////panic!("{layout:?}");
|
|
||||||
//////let content = <dyn ViewContext<::tengri_engine::tui::Tui>>::from(&layout);
|
|
||||||
////}
|
|
||||||
//Ok(())
|
|
||||||
//}
|
|
||||||
|
|
||||||
#[cfg(test)] mod test_token_iter {
|
#[cfg(test)] mod test_token_iter {
|
||||||
use crate::*;
|
use crate::*;
|
||||||
//use proptest::prelude::*;
|
//use proptest::prelude::*;
|
||||||
|
|
@ -130,5 +105,36 @@ mod dsl_macros;
|
||||||
let src = "foo/bar";
|
let src = "foo/bar";
|
||||||
assert_eq!(Key("foo/bar"), SourceIter(src).next().unwrap().0.value);
|
assert_eq!(Key("foo/bar"), SourceIter(src).next().unwrap().0.value);
|
||||||
|
|
||||||
|
let src = "\"foo/bar\"";
|
||||||
|
assert_eq!(Str("foo/bar"), SourceIter(src).next().unwrap().0.value);
|
||||||
|
|
||||||
|
let src = " \"foo/bar\" ";
|
||||||
|
assert_eq!(Str("foo/bar"), SourceIter(src).next().unwrap().0.value);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#[cfg(test)] #[test] fn test_examples () -> Result<(), ParseError> {
|
||||||
|
//// Let's pretend to render some view.
|
||||||
|
//let source = include_str!("../../tek/src/view_arranger.edn");
|
||||||
|
//// The token iterator allows you to get the tokens represented by the source text.
|
||||||
|
//let mut view = TokenIter(source);
|
||||||
|
//// The token iterator wraps a const token+source iterator.
|
||||||
|
//assert_eq!(view.0.0, source);
|
||||||
|
//let mut expr = view.peek();
|
||||||
|
//assert_eq!(view.0.0, source);
|
||||||
|
//assert_eq!(expr, Some(Token {
|
||||||
|
//source, start: 0, length: source.len() - 1, value: Exp(0, SourceIter(&source[1..]))
|
||||||
|
//}));
|
||||||
|
////panic!("{view:?}");
|
||||||
|
////panic!("{:#?}", expr);
|
||||||
|
////for example in [
|
||||||
|
////include_str!("../../tui/examples/edn01.edn"),
|
||||||
|
////include_str!("../../tui/examples/edn02.edn"),
|
||||||
|
////] {
|
||||||
|
//////let items = Dsl::read_all(example)?;
|
||||||
|
//////panic!("{layout:?}");
|
||||||
|
//////let content = <dyn ViewContext<::tengri_engine::tui::Tui>>::from(&layout);
|
||||||
|
////}
|
||||||
|
//Ok(())
|
||||||
|
//}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue