mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 03:36:42 +01:00
parent
ddd162f225
commit
1ef898ac32
2 changed files with 1 additions and 24 deletions
|
|
@ -242,29 +242,6 @@ dsl_type!(DslText {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
pub const fn is_key_start (c: char) -> bool { matches!(c, '/'|('a'..='z')) }
|
|
||||||
pub const fn is_key_char (c: char) -> bool { is_key_start(c) || matches!(c, '0'..='9'|'-') }
|
|
||||||
pub const fn is_key_end (c: char) -> bool { !is_key_char(c) }
|
|
||||||
dsl_type!(DslKey {
|
|
||||||
fn key (&self) -> DslPerhaps<&str> { ok_flat(self.src()?.map(key_peek_only)) }
|
|
||||||
} {
|
|
||||||
pub const fn key_peek [generated];
|
|
||||||
pub const fn key_peek_only [generated];
|
|
||||||
pub const fn key_seek [generated];
|
|
||||||
pub const fn key_seek_start (src) {
|
|
||||||
for_each!((i, c) in char_indices(src) =>
|
|
||||||
if is_key_start(c) { return Ok(Some(i)) } else
|
|
||||||
if !is_space(c) { return Err(Unexpected(c, Some(i), None)) });
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
pub const fn key_seek_length (src) {
|
|
||||||
for_each!((i, c) in char_indices(src) =>
|
|
||||||
if is_key_end(c) { return Ok(Some(i)) } else
|
|
||||||
if !is_key_char(c) { return Err(Unexpected(c, Some(i), None)) });
|
|
||||||
Ok(Some(src.len()))
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
dsl_type!(DslNum {
|
dsl_type!(DslNum {
|
||||||
fn num (&self) -> DslPerhaps<&str> {ok_flat(self.src()?.map(num_peek_only))}
|
fn num (&self) -> DslPerhaps<&str> {ok_flat(self.src()?.map(num_peek_only))}
|
||||||
} {
|
} {
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ impl ExposeImpl {
|
||||||
/// Generated by [tengri_proc::expose].
|
/// Generated by [tengri_proc::expose].
|
||||||
impl ::tengri::dsl::FromDsl<#state> for #t {
|
impl ::tengri::dsl::FromDsl<#state> for #t {
|
||||||
fn from_dsl (state: &#state, dsl: &impl Dsl) -> Perhaps<Self> {
|
fn from_dsl (state: &#state, dsl: &impl Dsl) -> Perhaps<Self> {
|
||||||
match dsl.key()? {
|
match dsl.word()? {
|
||||||
Some("true") => Ok(Some(true)),
|
Some("true") => Ok(Some(true)),
|
||||||
Some("false") => Ok(Some(false)),
|
Some("false") => Ok(Some(false)),
|
||||||
_ => match dsl.word()? { #(#variants)* _ => Ok(None) }
|
_ => match dsl.word()? { #(#variants)* _ => Ok(None) }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue