Strings support and default handlers update
This commit is contained in:
parent
d6c87db64f
commit
63eaafbe8f
@ -1,11 +1,18 @@
|
||||
use crate::dsl::{BooleanHandler, FloatHandler, IntegerHandler, NoValueHandler, NullHandler};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub struct Handler_Boolean<S, StoreFn: Fn(&mut S, bool)> {
|
||||
pub struct Handler_Boolean<
|
||||
Runtime: ?Sized,
|
||||
Container: ?Sized,
|
||||
StoreFn: Fn(&mut Runtime, &mut Container, bool),
|
||||
> {
|
||||
store: StoreFn,
|
||||
__phantom: PhantomData<S>,
|
||||
__phantom: PhantomData<(*const Runtime, *const Container)>,
|
||||
}
|
||||
impl<S, StoreFn: Fn(&mut S, bool)> Handler_Boolean<S, StoreFn> {
|
||||
|
||||
impl<Runtime: ?Sized, Container: ?Sized, StoreFn: Fn(&mut Runtime, &mut Container, bool)>
|
||||
Handler_Boolean<Runtime, Container, StoreFn>
|
||||
{
|
||||
pub fn create(f: StoreFn) -> Self {
|
||||
return Self {
|
||||
store: f,
|
||||
@ -13,18 +20,26 @@ impl<S, StoreFn: Fn(&mut S, bool)> Handler_Boolean<S, StoreFn> {
|
||||
};
|
||||
}
|
||||
}
|
||||
impl<S, StoreFn: Fn(&mut S, bool)> BooleanHandler<S> for Handler_Boolean<S, StoreFn> {
|
||||
fn handleBoolean(&self, dst: &mut S, value: bool) {
|
||||
(self.store)(dst, value);
|
||||
impl<Runtime: ?Sized, Container: ?Sized, StoreFn: Fn(&mut Runtime, &mut Container, bool)>
|
||||
BooleanHandler<Runtime, Container> for Handler_Boolean<Runtime, Container, StoreFn>
|
||||
{
|
||||
fn handleBoolean(&self, runtime: &mut Runtime, dst: &mut Container, value: bool) {
|
||||
(self.store)(runtime, dst, value);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Handler_Null<S, StoreFn: Fn(&mut S)> {
|
||||
pub struct Handler_Null<
|
||||
Runtime: ?Sized,
|
||||
Container: ?Sized,
|
||||
StoreFn: Fn(&mut Runtime, &mut Container),
|
||||
> {
|
||||
store: StoreFn,
|
||||
__phantom: PhantomData<S>,
|
||||
__phantom: PhantomData<(*const Runtime, *const Container)>,
|
||||
}
|
||||
|
||||
impl<S, StoreFn: Fn(&mut S)> Handler_Null<S, StoreFn> {
|
||||
impl<Runtime: ?Sized, Container: ?Sized, StoreFn: Fn(&mut Runtime, &mut Container)>
|
||||
Handler_Null<Runtime, Container, StoreFn>
|
||||
{
|
||||
pub fn create(f: StoreFn) -> Self {
|
||||
return Self {
|
||||
store: f,
|
||||
@ -33,18 +48,26 @@ impl<S, StoreFn: Fn(&mut S)> Handler_Null<S, StoreFn> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, StoreFn: Fn(&mut S)> NullHandler<S> for Handler_Null<S, StoreFn> {
|
||||
fn handleNull(&self, dst: &mut S) {
|
||||
(self.store)(dst);
|
||||
impl<Runtime: ?Sized, Container: ?Sized, StoreFn: Fn(&mut Runtime, &mut Container)>
|
||||
NullHandler<Runtime, Container> for Handler_Null<Runtime, Container, StoreFn>
|
||||
{
|
||||
fn handleNull(&self, runtime: &mut Runtime, dst: &mut Container) {
|
||||
(self.store)(runtime, dst);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Handler_NoValue<S, StoreFn: Fn(&mut S)> {
|
||||
pub struct Handler_NoValue<
|
||||
Runtime: ?Sized,
|
||||
Container: ?Sized,
|
||||
StoreFn: Fn(&mut Runtime, &mut Container),
|
||||
> {
|
||||
store: StoreFn,
|
||||
__phantom: PhantomData<S>,
|
||||
__phantom: PhantomData<(*const Runtime, *const Container)>,
|
||||
}
|
||||
|
||||
impl<S, StoreFn: Fn(&mut S)> Handler_NoValue<S, StoreFn> {
|
||||
impl<Runtime: ?Sized, Container: ?Sized, StoreFn: Fn(&mut Runtime, &mut Container)>
|
||||
Handler_NoValue<Runtime, Container, StoreFn>
|
||||
{
|
||||
pub fn create(f: StoreFn) -> Self {
|
||||
return Self {
|
||||
store: f,
|
||||
@ -53,8 +76,10 @@ impl<S, StoreFn: Fn(&mut S)> Handler_NoValue<S, StoreFn> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, StoreFn: Fn(&mut S)> NoValueHandler<S> for Handler_NoValue<S, StoreFn> {
|
||||
fn handleNoValue(&self, dst: &mut S) {
|
||||
(self.store)(dst);
|
||||
impl<Runtime: ?Sized, Container: ?Sized, StoreFn: Fn(&mut Runtime, &mut Container)>
|
||||
NoValueHandler<Runtime, Container> for Handler_NoValue<Runtime, Container, StoreFn>
|
||||
{
|
||||
fn handleNoValue(&self, runtime: &mut Runtime, dst: &mut Container) {
|
||||
(self.store)(runtime, dst);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,17 @@
|
||||
use crate::dsl::{FloatHandler, IntegerHandler};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub struct Handler_F64<S, StoreFn: Fn(&mut S, f64)> {
|
||||
pub struct Handler_F64<
|
||||
Runtime: ?Sized,
|
||||
Container: ?Sized,
|
||||
StoreFn: Fn(&mut Runtime, &mut Container, f64),
|
||||
> {
|
||||
store: StoreFn,
|
||||
__phantom: PhantomData<S>,
|
||||
__phantom: PhantomData<(*const Runtime, *const Container)>,
|
||||
}
|
||||
impl<S, StoreFn: Fn(&mut S, f64)> Handler_F64<S, StoreFn> {
|
||||
impl<Runtime: ?Sized, Container: ?Sized, StoreFn: Fn(&mut Runtime, &mut Container, f64)>
|
||||
Handler_F64<Runtime, Container, StoreFn>
|
||||
{
|
||||
pub fn create(f: StoreFn) -> Self {
|
||||
return Self {
|
||||
store: f,
|
||||
@ -13,17 +19,25 @@ impl<S, StoreFn: Fn(&mut S, f64)> Handler_F64<S, StoreFn> {
|
||||
};
|
||||
}
|
||||
}
|
||||
impl<S, StoreFn: Fn(&mut S, f64)> FloatHandler<S> for Handler_F64<S, StoreFn> {
|
||||
fn handleFloat(&self, dst: &mut S, value: f64) {
|
||||
(self.store)(dst, value);
|
||||
impl<Runtime: ?Sized, Container: ?Sized, StoreFn: Fn(&mut Runtime, &mut Container, f64)>
|
||||
FloatHandler<Runtime, Container> for Handler_F64<Runtime, Container, StoreFn>
|
||||
{
|
||||
fn handleFloat(&self, runtime: &mut Runtime, dst: &mut Container, value: f64) {
|
||||
(self.store)(runtime, dst, value);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Handler_F32<S, StoreFn: Fn(&mut S, f32)> {
|
||||
pub struct Handler_F32<
|
||||
Runtime: ?Sized,
|
||||
Container: ?Sized,
|
||||
StoreFn: Fn(&mut Runtime, &mut Container, f32),
|
||||
> {
|
||||
store: StoreFn,
|
||||
__phantom: PhantomData<S>,
|
||||
__phantom: PhantomData<(*const Runtime, *const Container)>,
|
||||
}
|
||||
impl<S, StoreFn: Fn(&mut S, f32)> Handler_F32<S, StoreFn> {
|
||||
impl<Runtime: ?Sized, Container: ?Sized, StoreFn: Fn(&mut Runtime, &mut Container, f32)>
|
||||
Handler_F32<Runtime, Container, StoreFn>
|
||||
{
|
||||
pub fn create(f: StoreFn) -> Self {
|
||||
return Self {
|
||||
store: f,
|
||||
@ -31,8 +45,10 @@ impl<S, StoreFn: Fn(&mut S, f32)> Handler_F32<S, StoreFn> {
|
||||
};
|
||||
}
|
||||
}
|
||||
impl<S, StoreFn: Fn(&mut S, f32)> FloatHandler<S> for Handler_F32<S, StoreFn> {
|
||||
fn handleFloat(&self, dst: &mut S, value: f64) {
|
||||
(self.store)(dst, value as f32);
|
||||
impl<Runtime: ?Sized, Container: ?Sized, StoreFn: Fn(&mut Runtime, &mut Container, f32)>
|
||||
FloatHandler<Runtime, Container> for Handler_F32<Runtime, Container, StoreFn>
|
||||
{
|
||||
fn handleFloat(&self, runtime: &mut Runtime, dst: &mut Container, value: f64) {
|
||||
(self.store)(runtime, dst, value as f32);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3,12 +3,20 @@ use std::marker::PhantomData;
|
||||
|
||||
macro_rules! defineIntegerHandler {
|
||||
($vis:vis $name:ident < $int_type:ty >) => {
|
||||
$vis struct $name <S, StoreFn: Fn(&mut S, $int_type)> {
|
||||
$vis struct $name <
|
||||
Runtime: ?Sized,
|
||||
Container: ?Sized,
|
||||
StoreFn: Fn(&mut Runtime, &mut Container, $int_type),
|
||||
> {
|
||||
store: StoreFn,
|
||||
__phantom: PhantomData<S>
|
||||
__phantom: PhantomData<(*const Runtime, *const Container)>
|
||||
}
|
||||
|
||||
impl <S, StoreFn: Fn(&mut S, $int_type)> $name <S, StoreFn> {
|
||||
impl <
|
||||
Runtime: ?Sized,
|
||||
Container: ?Sized,
|
||||
StoreFn: Fn(&mut Runtime, &mut Container, $int_type),
|
||||
> $name <Runtime, Container, StoreFn> {
|
||||
pub fn create(f: StoreFn) -> Self {
|
||||
return Self {
|
||||
store: f,
|
||||
@ -17,11 +25,20 @@ macro_rules! defineIntegerHandler {
|
||||
}
|
||||
}
|
||||
|
||||
impl <S, StoreFn: Fn(&mut S, $int_type)> IntegerHandler<S> for $name <S, StoreFn> {
|
||||
fn handleFixedInteger(&self, dst: &mut S, value: u64, isNegative: bool) {
|
||||
impl <
|
||||
Runtime: ?Sized,
|
||||
Container: ?Sized,
|
||||
StoreFn: Fn(&mut Runtime, &mut Container, $int_type),
|
||||
> IntegerHandler<Runtime, Container> for $name <Runtime, Container, StoreFn> {
|
||||
fn handleFixedInteger(
|
||||
&self,
|
||||
runtime: &mut Runtime, dst: &mut Container,
|
||||
value: u64, isNegative: bool
|
||||
) {
|
||||
let downcasted: $int_type;
|
||||
|
||||
if isNegative {
|
||||
#[allow(unused_comparisons)]
|
||||
if <$int_type>::MIN >= 0 || value > (<$int_type>::abs_diff(0, <$int_type>::MIN)) as u64 {
|
||||
panic!(
|
||||
"Integer underflow: expected in range {}..={}, got -{}",
|
||||
@ -39,7 +56,7 @@ macro_rules! defineIntegerHandler {
|
||||
downcasted = value as $int_type;
|
||||
}
|
||||
|
||||
(self.store)(dst, downcasted);
|
||||
(self.store)(runtime, dst, downcasted);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
32
src/dsl.rs
32
src/dsl.rs
@ -38,58 +38,62 @@ pub trait ArrayHandler<Runtime: ?Sized, ParentContainer: ?Sized, ArrayBuilder>:
|
||||
fn storeArray(&self, runtime: &mut Runtime, dst: &mut ParentContainer, value: ArrayBuilder);
|
||||
}
|
||||
|
||||
pub trait ObjectConfiguration<Runtime: ?Sized, ParentContainer: ?Sized>: Sized {
|
||||
pub trait ObjectConfiguration<Runtime: ?Sized, ParentContainer: ?Sized, String>: Sized {
|
||||
type ObjectBuilder: Sized;
|
||||
fn configureObject(
|
||||
&self,
|
||||
scope: &impl ObjectConfigurationScope<Runtime, Self::ObjectBuilder>,
|
||||
scope: &impl ObjectConfigurationScope<Runtime, Self::ObjectBuilder, String>,
|
||||
) -> impl ObjectHandler<Runtime, ParentContainer, Self::ObjectBuilder>;
|
||||
}
|
||||
|
||||
pub trait ArrayConfiguration<Runtime: ?Sized, ParentContainer: ?Sized>: Sized {
|
||||
pub trait ArrayConfiguration<Runtime: ?Sized, ParentContainer: ?Sized, String>: Sized {
|
||||
type ArrayBuilder: Sized;
|
||||
fn configureArray(
|
||||
&self,
|
||||
scope: &impl ArrayConfigurationScope<Runtime, Self::ArrayBuilder>,
|
||||
scope: &impl ArrayConfigurationScope<Runtime, Self::ArrayBuilder, String>,
|
||||
) -> impl ObjectHandler<Runtime, ParentContainer, Self::ArrayBuilder>;
|
||||
}
|
||||
|
||||
pub trait ObjectConfigurationScope<Runtime: ?Sized, Container: ?Sized> {
|
||||
pub trait ObjectConfigurationScope<Runtime: ?Sized, Container: ?Sized, String> {
|
||||
type Key: Sized;
|
||||
|
||||
fn ignoreKey_required(&mut self, name: Self::Key);
|
||||
fn ignoreKey_optional(&mut self, name: Self::Key);
|
||||
fn processKey(&mut self, name: Self::Key, config: impl ValueConfiguration<Runtime, Container>);
|
||||
fn processKey(
|
||||
&mut self,
|
||||
name: Self::Key,
|
||||
config: impl ValueConfiguration<Runtime, Container, String>,
|
||||
);
|
||||
fn processKey_optional(
|
||||
&mut self,
|
||||
name: Self::Key,
|
||||
config: impl ValueConfiguration<Runtime, Container>,
|
||||
config: impl ValueConfiguration<Runtime, Container, String>,
|
||||
fallback: impl NoValueHandler<Runtime, Container>,
|
||||
);
|
||||
}
|
||||
pub trait ArrayConfigurationScope<Runtime: ?Sized, Container: ?Sized> {
|
||||
pub trait ArrayConfigurationScope<Runtime: ?Sized, Container: ?Sized, String> {
|
||||
fn ignoreElements_required(&self, start: usize, endInclusive: Option<usize>);
|
||||
fn ignoreElements_optional(&self, start: usize, endInclusive: Option<usize>);
|
||||
fn processElements_required(
|
||||
&self,
|
||||
start: usize,
|
||||
endInclusive: Option<usize>,
|
||||
config: impl ValueConfiguration<Runtime, Container>,
|
||||
config: impl ValueConfiguration<Runtime, Container, String>,
|
||||
);
|
||||
fn processElements_optional(
|
||||
&self,
|
||||
start: usize,
|
||||
endInclusive: Option<usize>,
|
||||
config: impl ValueConfiguration<Runtime, Container>
|
||||
config: impl ValueConfiguration<Runtime, Container, String>,
|
||||
);
|
||||
}
|
||||
|
||||
pub trait ValueConfiguration<Runtime: ?Sized, Container: ?Sized>: Sized {
|
||||
pub trait ValueConfiguration<Runtime: ?Sized, Container: ?Sized, String>: Sized {
|
||||
fn integerHandler(&self) -> Option<impl IntegerHandler<Runtime, Container>>;
|
||||
fn floatHandler(&self) -> Option<impl FloatHandler<Runtime, Container>>;
|
||||
fn booleanHandler(&self) -> Option<impl BooleanHandler<Runtime, Container>>;
|
||||
fn nullHandler(&self) -> Option<impl NullHandler<Runtime, Container>>;
|
||||
fn arrayHandler(&self) -> Option<impl ObjectConfiguration<Runtime, Container>>;
|
||||
fn objectHandler(&self) -> Option<impl ArrayConfiguration<Runtime, Container>>;
|
||||
// fn stringHandler(&self) -> Option<impl StringHandler<Runtime, Container>>;
|
||||
fn objectHandler(&self) -> Option<impl ObjectConfiguration<Runtime, Container, String>>;
|
||||
fn arrayHandler(&self) -> Option<impl ArrayConfiguration<Runtime, Container, String>>;
|
||||
fn stringHandler(&self) -> Option<impl StringHandler<Runtime, Container, String>>;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user