mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 11:46:42 +01:00
and decide how exprs gon work once and for all
This commit is contained in:
parent
9e0b7be9a9
commit
d475a4cb92
3 changed files with 140 additions and 54 deletions
101
dsl/src/dsl.rs
101
dsl/src/dsl.rs
|
|
@ -8,7 +8,8 @@ use const_panic::PanicFmt;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
pub(crate) use std::error::Error;
|
pub(crate) use std::error::Error;
|
||||||
pub(crate) use std::sync::Arc;
|
pub(crate) use std::sync::Arc;
|
||||||
pub(crate) use konst::string::{str_range, char_indices};
|
pub(crate) use konst::iter::for_each;
|
||||||
|
pub(crate) use konst::string::{str_from, str_range, char_indices};
|
||||||
pub(crate) use thiserror::Error;
|
pub(crate) use thiserror::Error;
|
||||||
pub(crate) use ::tengri_core::*;
|
pub(crate) use ::tengri_core::*;
|
||||||
pub(crate) use self::DslError::*;
|
pub(crate) use self::DslError::*;
|
||||||
|
|
@ -16,69 +17,94 @@ mod dsl_conv; pub use self::dsl_conv::*;
|
||||||
mod dsl_parse;
|
mod dsl_parse;
|
||||||
pub(crate) use self::dsl_parse::*;
|
pub(crate) use self::dsl_parse::*;
|
||||||
pub mod parse { pub use crate::dsl_parse::*; }
|
pub mod parse { pub use crate::dsl_parse::*; }
|
||||||
|
#[cfg(test)] mod dsl_test;
|
||||||
#[cfg(test)]
|
|
||||||
mod dsl_test;
|
|
||||||
|
|
||||||
flex_trait!(Dsl: Debug + Send + Sync + Sized {
|
flex_trait!(Dsl: Debug + Send + Sync + Sized {
|
||||||
fn src (&self) -> &str {
|
fn src (&self) -> DslPerhaps<&str> {
|
||||||
unreachable!("Dsl::src default impl")
|
unreachable!("Dsl::src default impl")
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
impl Dsl for Arc<str> {
|
impl Dsl for Arc<str> {
|
||||||
fn src (&self) -> &str { self.as_ref() }
|
fn src (&self) -> DslPerhaps<&str> {
|
||||||
|
Ok(Some(self.as_ref()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
impl<'s> Dsl for &'s str {
|
impl<'s> Dsl for &'s str {
|
||||||
fn src (&self) -> &str { self.as_ref() }
|
fn src (&self) -> DslPerhaps<&str> {
|
||||||
|
Ok(Some(self.as_ref()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
impl<D: Dsl> Dsl for Option<D> {
|
impl<D: Dsl> Dsl for Option<D> {
|
||||||
fn src (&self) -> &str { if let Some(dsl) = self { dsl.src() } else { "" } }
|
fn src (&self) -> DslPerhaps<&str> {
|
||||||
|
Ok(if let Some(dsl) = self { dsl.src()? } else { None })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<D: Dsl> Dsl for Result<D, DslError> {
|
||||||
|
fn src (&self) -> DslPerhaps<&str> {
|
||||||
|
match self {
|
||||||
|
Ok(dsl) => Ok(dsl.src()?),
|
||||||
|
Err(e) => Err(*e)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Dsl> DslExp for D {}
|
impl<D: Dsl> DslExp for D {}
|
||||||
pub trait DslExp: Dsl {
|
pub trait DslExp: Dsl {
|
||||||
fn exp (&self) -> DslPerhaps<&str> {
|
fn exp (&self) -> DslPerhaps<&str> {
|
||||||
Ok(exp_peek(self.src())?)
|
Ok(self.src()?
|
||||||
|
.map(exp_peek)
|
||||||
|
.transpose()?
|
||||||
|
.flatten())
|
||||||
}
|
}
|
||||||
fn head (&self) -> DslPerhaps<&str> {
|
fn head (&self) -> DslPerhaps<&str> {
|
||||||
let start = 1;
|
Ok(self.src()?
|
||||||
let src = self.src();
|
.map(peek) //|src|Ok(if src.len() > 0 { return peek(&src)) } else { None }))
|
||||||
let src = &src[start.min(src.len().saturating_sub(1))..];
|
.transpose()?
|
||||||
peek(src)
|
.flatten())
|
||||||
}
|
}
|
||||||
fn tail (&self) -> DslPerhaps<&str> {
|
fn tail (&self) -> DslPerhaps<&str> {
|
||||||
let start = 1;
|
Ok(self.src()?
|
||||||
let src = self.src();
|
.map(|src|Ok(if let Some(next) = self.head()? {
|
||||||
let src = &src[start.min(src.len().saturating_sub(1))..];
|
let src = &src[src.len().min(1 + next.len() + 1)..];
|
||||||
Ok(if let Some((head_start, head_len)) = seek(src)? {
|
if src.len() > 2 {
|
||||||
let start = 1 + head_start + head_len;
|
return peek(&src)
|
||||||
let src = self.src();
|
} else {
|
||||||
let src = &src[start.min(src.len().saturating_sub(1))..];
|
None
|
||||||
peek(src)?
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
})
|
}))
|
||||||
|
.transpose()?
|
||||||
|
.flatten())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Dsl> DslSym for D {}
|
impl<D: Dsl> DslSym for D {}
|
||||||
pub trait DslSym: Dsl {
|
pub trait DslSym: Dsl {
|
||||||
fn sym (&self) -> DslPerhaps<&str> { crate::parse::sym_peek(self.src()) }
|
fn sym (&self) -> DslPerhaps<&str> {
|
||||||
|
Ok(self.src()?.map(crate::parse::sym_peek).transpose()?.flatten())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Dsl> DslKey for D {}
|
impl<D: Dsl> DslKey for D {}
|
||||||
pub trait DslKey: Dsl {
|
pub trait DslKey: Dsl {
|
||||||
fn key (&self) -> DslPerhaps<&str> { crate::parse::key_peek(self.src()) }
|
fn key (&self) -> DslPerhaps<&str> {
|
||||||
|
Ok(self.src()?.map(crate::parse::key_peek).transpose()?.flatten())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Dsl> DslText for D {}
|
impl<D: Dsl> DslText for D {}
|
||||||
pub trait DslText: Dsl {
|
pub trait DslText: Dsl {
|
||||||
fn text (&self) -> DslPerhaps<&str> { crate::parse::text_peek(self.src()) }
|
fn text (&self) -> DslPerhaps<&str> {
|
||||||
|
Ok(self.src()?.map(crate::parse::text_peek).transpose()?.flatten())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Dsl> DslNum for D {}
|
impl<D: Dsl> DslNum for D {}
|
||||||
pub trait DslNum: Dsl {
|
pub trait DslNum: Dsl {
|
||||||
fn num (&self) -> DslPerhaps<&str> { crate::parse::num_peek(self.src()) }
|
fn num (&self) -> DslPerhaps<&str> {
|
||||||
|
Ok(self.src()?.map(crate::parse::num_peek).transpose()?.flatten())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// DSL-specific result type.
|
/// DSL-specific result type.
|
||||||
|
|
@ -97,3 +123,22 @@ pub enum DslError {
|
||||||
#[error("parse failed: error #{0}")] Code(u8),
|
#[error("parse failed: error #{0}")] Code(u8),
|
||||||
#[error("end reached")] End
|
#[error("end reached")] End
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export] macro_rules! dsl_for_each (($dsl:expr => |$next:ident|$body:expr)=>{
|
||||||
|
let mut dsl: Arc<str> = $dsl.src().into();
|
||||||
|
let mut $next: Option<Arc<str>> = dsl.next()?.map(Into::into);
|
||||||
|
let mut rest: Option<Arc<str>> = dsl.rest()?.map(Into::into);
|
||||||
|
loop {
|
||||||
|
if let Some($next) = $next {
|
||||||
|
$body;
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if let Some(next) = rest {
|
||||||
|
$next = next.next()?.map(Into::into);
|
||||||
|
rest = next.rest()?.map(Into::into);
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,33 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
macro_rules! iter_chars(($source:expr => |$i:ident, $c:ident|$val:expr)=>{
|
|
||||||
while let Some((($i, $c), next)) = char_indices($source).next() {
|
|
||||||
$source = next.as_str(); $val } });
|
|
||||||
|
|
||||||
macro_rules! def_peek_seek(($peek:ident, $seek:ident, $seek_start:ident, $seek_length:ident)=>{
|
macro_rules! def_peek_seek(($peek:ident, $seek:ident, $seek_start:ident, $seek_length:ident)=>{
|
||||||
/// Find a slice corrensponding to a syntax token.
|
/// Find a slice corrensponding to a syntax token.
|
||||||
pub const fn $peek (source: &str) -> DslPerhaps<&str> {
|
pub const fn $peek (source: &str) -> DslPerhaps<&str> {
|
||||||
match $seek(source) {
|
match $seek(source) {
|
||||||
Ok(Some((start, length))) => Ok(Some(str_range(source, start, start + length))),
|
Ok(Some((start, length))) => Ok(Some(str_range(source, start, start + length))),
|
||||||
Ok(None) => Ok(None),
|
Ok(None) => Ok(None),
|
||||||
Err(e) => Err(e) } }
|
Err(e) => Err(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
/// Find a start and length corresponding to a syntax token.
|
/// Find a start and length corresponding to a syntax token.
|
||||||
pub const fn $seek (source: &str) -> DslPerhaps<(usize, usize)> {
|
pub const fn $seek (source: &str) -> DslPerhaps<(usize, usize)> {
|
||||||
match $seek_start(source) {
|
match $seek_start(source) {
|
||||||
Ok(Some(start)) => match $seek_length(str_range(source, start, source.len() - start)) {
|
Ok(Some(start)) => match $seek_length(str_from(source, start)) {
|
||||||
Ok(Some(length)) => Ok(Some((start, length))),
|
Ok(Some(length)) => Ok(Some((start, length))),
|
||||||
Ok(None) => Ok(None),
|
Ok(None) => Ok(None),
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
},
|
},
|
||||||
Ok(None) => Ok(None),
|
Ok(None) => Ok(None),
|
||||||
Err(e) => Err(e) } } });
|
Err(e) => Err(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
def_peek_seek!(exp_peek, exp_seek, exp_seek_start, exp_seek_length);
|
def_peek_seek!(exp_peek, exp_seek, exp_seek_start, exp_seek_length);
|
||||||
pub const fn is_exp_start (c: char) -> bool { matches!(c, '(') }
|
pub const fn is_exp_start (c: char) -> bool { c == '(' }
|
||||||
pub const fn is_exp_end (c: char) -> bool { matches!(c, ')') }
|
pub const fn is_exp_end (c: char) -> bool { c == ')' }
|
||||||
pub const fn exp_seek_start (mut source: &str) -> DslPerhaps<usize> {
|
pub const fn exp_seek_start (mut source: &str) -> DslPerhaps<usize> {
|
||||||
iter_chars!(source => |i, c| if is_exp_start(c) {
|
for_each!((i, c) in char_indices(source) => if is_exp_start(c) {
|
||||||
return Ok(Some(i))
|
return Ok(Some(i))
|
||||||
} else if !is_whitespace(c) {
|
} else if !is_whitespace(c) {
|
||||||
return Err(Unexpected(c))
|
return Err(Unexpected(c))
|
||||||
|
|
@ -35,18 +36,18 @@ pub const fn exp_seek_start (mut source: &str) -> DslPerhaps<usize> {
|
||||||
}
|
}
|
||||||
pub const fn exp_seek_length (mut source: &str) -> DslPerhaps<usize> {
|
pub const fn exp_seek_length (mut source: &str) -> DslPerhaps<usize> {
|
||||||
let mut depth = 0;
|
let mut depth = 0;
|
||||||
iter_chars!(source => |i, c| if is_exp_start(c) {
|
for_each!((i, c) in char_indices(source) => if is_exp_start(c) {
|
||||||
depth += 1;
|
depth += 1;
|
||||||
} else if is_exp_end(c) {
|
} else if is_exp_end(c) {
|
||||||
if depth == 0 {
|
if depth == 0 {
|
||||||
return Err(Unexpected(c))
|
return Err(Unexpected(c))
|
||||||
} else if depth == 1 {
|
} else if depth == 1 {
|
||||||
return Ok(Some(i))
|
return Ok(Some(i + 1))
|
||||||
} else {
|
} else {
|
||||||
depth -= 1;
|
depth -= 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Ok(None)
|
Err(Incomplete)
|
||||||
}
|
}
|
||||||
|
|
||||||
def_peek_seek!(sym_peek, sym_seek, sym_seek_start, sym_seek_length);
|
def_peek_seek!(sym_peek, sym_seek, sym_seek_start, sym_seek_length);
|
||||||
|
|
@ -54,7 +55,7 @@ pub const fn is_sym_start (c: char) -> bool { matches!(c, ':'|'@') }
|
||||||
pub const fn is_sym_char (c: char) -> bool { matches!(c, 'a'..='z'|'A'..='Z'|'0'..='9'|'-') }
|
pub const fn is_sym_char (c: char) -> bool { matches!(c, 'a'..='z'|'A'..='Z'|'0'..='9'|'-') }
|
||||||
pub const fn is_sym_end (c: char) -> bool { matches!(c, ' '|'\n'|'\r'|'\t'|')') }
|
pub const fn is_sym_end (c: char) -> bool { matches!(c, ' '|'\n'|'\r'|'\t'|')') }
|
||||||
pub const fn sym_seek_start (mut source: &str) -> DslPerhaps<usize> {
|
pub const fn sym_seek_start (mut source: &str) -> DslPerhaps<usize> {
|
||||||
iter_chars!(source => |i, c| if is_sym_start(c) {
|
for_each!((i, c) in char_indices(source) => if is_sym_start(c) {
|
||||||
return Ok(Some(i))
|
return Ok(Some(i))
|
||||||
} else if !is_whitespace(c) {
|
} else if !is_whitespace(c) {
|
||||||
return Err(Unexpected(c))
|
return Err(Unexpected(c))
|
||||||
|
|
@ -62,20 +63,20 @@ pub const fn sym_seek_start (mut source: &str) -> DslPerhaps<usize> {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
pub const fn sym_seek_length (mut source: &str) -> DslPerhaps<usize> {
|
pub const fn sym_seek_length (mut source: &str) -> DslPerhaps<usize> {
|
||||||
iter_chars!(source => |i, c| if is_sym_end(c) {
|
for_each!((i, c) in char_indices(source) => if is_sym_end(c) {
|
||||||
return Ok(Some(i))
|
return Ok(Some(i))
|
||||||
} else if !is_sym_char(c) {
|
} else if !is_sym_char(c) {
|
||||||
return Err(Unexpected(c))
|
return Err(Unexpected(c))
|
||||||
});
|
});
|
||||||
Ok(None)
|
Ok(Some(source.len()))
|
||||||
}
|
}
|
||||||
|
|
||||||
def_peek_seek!(key_peek, key_seek, key_seek_start, key_seek_length);
|
def_peek_seek!(key_peek, key_seek, key_seek_start, key_seek_length);
|
||||||
pub const fn is_key_start (c: char) -> bool { matches!(c, '/'|'a'..='z') }
|
pub const fn is_key_start (c: char) -> bool { matches!(c, '/'|('a'..='z')) }
|
||||||
pub const fn is_key_char (c: char) -> bool { matches!(c, 'a'..='z'|'0'..='9'|'-'|'/') }
|
pub const fn is_key_char (c: char) -> bool { matches!(c, 'a'..='z'|'0'..='9'|'-'|'/') }
|
||||||
pub const fn is_key_end (c: char) -> bool { matches!(c, ' '|'\n'|'\r'|'\t'|')') }
|
pub const fn is_key_end (c: char) -> bool { matches!(c, ' '|'\n'|'\r'|'\t'|')') }
|
||||||
pub const fn key_seek_start (mut source: &str) -> DslPerhaps<usize> {
|
pub const fn key_seek_start (mut source: &str) -> DslPerhaps<usize> {
|
||||||
iter_chars!(source => |i, c| if is_key_start(c) {
|
for_each!((i, c) in char_indices(source) => if is_key_start(c) {
|
||||||
return Ok(Some(i))
|
return Ok(Some(i))
|
||||||
} else if !is_whitespace(c) {
|
} else if !is_whitespace(c) {
|
||||||
return Err(Unexpected(c))
|
return Err(Unexpected(c))
|
||||||
|
|
@ -83,19 +84,19 @@ pub const fn key_seek_start (mut source: &str) -> DslPerhaps<usize> {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
pub const fn key_seek_length (mut source: &str) -> DslPerhaps<usize> {
|
pub const fn key_seek_length (mut source: &str) -> DslPerhaps<usize> {
|
||||||
iter_chars!(source => |i, c| if is_key_end(c) {
|
for_each!((i, c) in char_indices(source) => if is_key_end(c) {
|
||||||
return Ok(Some(i))
|
return Ok(Some(i))
|
||||||
} else if !is_key_char(c) {
|
} else if !is_key_char(c) {
|
||||||
return Err(Unexpected(c))
|
return Err(Unexpected(c))
|
||||||
});
|
});
|
||||||
Ok(None)
|
Ok(Some(source.len()))
|
||||||
}
|
}
|
||||||
|
|
||||||
def_peek_seek!(text_peek, text_seek, text_seek_start, text_seek_length);
|
def_peek_seek!(text_peek, text_seek, text_seek_start, text_seek_length);
|
||||||
pub const fn is_text_start (c: char) -> bool { matches!(c, '"') }
|
pub const fn is_text_start (c: char) -> bool { matches!(c, '"') }
|
||||||
pub const fn is_text_end (c: char) -> bool { matches!(c, '"') }
|
pub const fn is_text_end (c: char) -> bool { matches!(c, '"') }
|
||||||
pub const fn text_seek_start (mut source: &str) -> DslPerhaps<usize> {
|
pub const fn text_seek_start (mut source: &str) -> DslPerhaps<usize> {
|
||||||
iter_chars!(source => |i, c| if is_text_start(c) {
|
for_each!((i, c) in char_indices(source) => if is_text_start(c) {
|
||||||
return Ok(Some(i))
|
return Ok(Some(i))
|
||||||
} else if !is_whitespace(c) {
|
} else if !is_whitespace(c) {
|
||||||
return Err(Unexpected(c))
|
return Err(Unexpected(c))
|
||||||
|
|
@ -103,13 +104,13 @@ pub const fn text_seek_start (mut source: &str) -> DslPerhaps<usize> {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
pub const fn text_seek_length (mut source: &str) -> DslPerhaps<usize> {
|
pub const fn text_seek_length (mut source: &str) -> DslPerhaps<usize> {
|
||||||
iter_chars!(source => |i, c| if is_text_end(c) { return Ok(Some(i)) });
|
for_each!((i, c) in char_indices(source) => if is_text_end(c) { return Ok(Some(i)) });
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
def_peek_seek!(num_peek, num_seek, num_seek_start, num_seek_length);
|
def_peek_seek!(num_peek, num_seek, num_seek_start, num_seek_length);
|
||||||
pub const fn num_seek_start (mut source: &str) -> DslPerhaps<usize> {
|
pub const fn num_seek_start (mut source: &str) -> DslPerhaps<usize> {
|
||||||
iter_chars!(source => |i, c| if is_digit(c) {
|
for_each!((i, c) in char_indices(source) => if is_digit(c) {
|
||||||
return Ok(Some(i));
|
return Ok(Some(i));
|
||||||
} else if !is_whitespace(c) {
|
} else if !is_whitespace(c) {
|
||||||
return Err(Unexpected(c))
|
return Err(Unexpected(c))
|
||||||
|
|
@ -117,7 +118,7 @@ pub const fn num_seek_start (mut source: &str) -> DslPerhaps<usize> {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
pub const fn num_seek_length (mut source: &str) -> DslPerhaps<usize> {
|
pub const fn num_seek_length (mut source: &str) -> DslPerhaps<usize> {
|
||||||
iter_chars!(source => |i, c| if is_num_end(c) {
|
for_each!((i, c) in char_indices(source) => if is_num_end(c) {
|
||||||
return Ok(Some(i))
|
return Ok(Some(i))
|
||||||
} else if !is_digit(c) {
|
} else if !is_digit(c) {
|
||||||
return Err(Unexpected(c))
|
return Err(Unexpected(c))
|
||||||
|
|
@ -154,7 +155,7 @@ pub const fn peek (mut src: &str) -> DslPerhaps<&str> {
|
||||||
_ if let Ok(Some(num)) = num_peek(src) => num,
|
_ if let Ok(Some(num)) = num_peek(src) => num,
|
||||||
_ if let Ok(Some(text)) = text_peek(src) => text,
|
_ if let Ok(Some(text)) = text_peek(src) => text,
|
||||||
_ => {
|
_ => {
|
||||||
iter_chars!(src => |_i, c| if !is_whitespace(c) {
|
for_each!((i, c) in char_indices(src) => if !is_whitespace(c) {
|
||||||
return Err(Unexpected(c))
|
return Err(Unexpected(c))
|
||||||
});
|
});
|
||||||
return Ok(None)
|
return Ok(None)
|
||||||
|
|
@ -170,7 +171,7 @@ pub const fn seek (mut src: &str) -> DslPerhaps<(usize, usize)> {
|
||||||
_ if let Ok(Some(num)) = num_seek(src) => num,
|
_ if let Ok(Some(num)) = num_seek(src) => num,
|
||||||
_ if let Ok(Some(text)) = text_seek(src) => text,
|
_ if let Ok(Some(text)) = text_seek(src) => text,
|
||||||
_ => {
|
_ => {
|
||||||
iter_chars!(src => |_i, c| if !is_whitespace(c) {
|
for_each!((i, c) in char_indices(src) => if !is_whitespace(c) {
|
||||||
return Err(Unexpected(c))
|
return Err(Unexpected(c))
|
||||||
});
|
});
|
||||||
return Ok(None)
|
return Ok(None)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
use crate::*;
|
||||||
|
#[test] fn test_exp () -> Result<(), DslError> {
|
||||||
|
assert_eq!(is_whitespace(' '), true);
|
||||||
|
|
||||||
|
assert_eq!(is_key_start(' '), false);
|
||||||
|
assert_eq!(is_key_start('f'), true);
|
||||||
|
assert_eq!(key_seek_start("foo"), Ok(Some(0)));
|
||||||
|
assert_eq!(key_seek_start("foo "), Ok(Some(0)));
|
||||||
|
assert_eq!(key_seek_start(" foo "), Ok(Some(1)));
|
||||||
|
assert_eq!(key_seek_length(&" foo "[1..]), Ok(Some(3)));
|
||||||
|
assert_eq!(key_seek("foo"), Ok(Some((0, 3))));
|
||||||
|
assert_eq!(key_peek("foo"), Ok(Some("foo")));
|
||||||
|
assert_eq!(key_seek("foo "), Ok(Some((0, 3))));
|
||||||
|
assert_eq!(key_peek("foo "), Ok(Some("foo")));
|
||||||
|
assert_eq!(key_seek(" foo "), Ok(Some((1, 3))));
|
||||||
|
assert_eq!(key_peek(" foo "), Ok(Some("foo")));
|
||||||
|
|
||||||
|
assert_eq!("foo".key(), Ok(Some("foo")));
|
||||||
|
assert_eq!(" foo".key(), Ok(Some("foo")));
|
||||||
|
assert_eq!(" foo ".key(), Ok(Some("foo")));
|
||||||
|
|
||||||
|
assert_eq!(" foo ".head(), Ok(Some("foo")));
|
||||||
|
assert_eq!(" foo ".head().head(), Ok(Some("foo")));
|
||||||
|
assert_eq!(" foo ".head().tail(), Ok(None));
|
||||||
|
assert_eq!(" foo ".tail(), Ok(None));
|
||||||
|
assert_eq!(" foo ".tail().head(), Ok(None));
|
||||||
|
assert_eq!(" foo ".tail().tail(), Ok(None));
|
||||||
|
|
||||||
|
assert_eq!(" (foo) ".head(), Ok(Some("(foo)")));
|
||||||
|
assert_eq!(" (foo) ".head().head(), Ok(Some("foo")));
|
||||||
|
assert_eq!(" (foo) ".head().head().head(), Ok(None));
|
||||||
|
assert_eq!(" (foo) ".tail(), Ok(None));
|
||||||
|
|
||||||
|
assert_eq!(" (foo bar baz) ".head(), Ok(Some("(foo bar baz)")));
|
||||||
|
assert_eq!(" (foo bar baz) ".head().head(), Ok(Some("foo")));
|
||||||
|
assert_eq!(" (foo bar baz) ".head().tail(), Ok(Some("bar baz")));
|
||||||
|
assert_eq!(" (foo bar baz) ".head().tail().head(), Ok(Some("bar")));
|
||||||
|
assert_eq!(" (foo bar baz) ".head().tail().tail(), Ok(Some("baz")));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue