Strings support and default handlers update

This commit is contained in:
Andrew Golovashevich 2025-12-07 17:56:00 +03:00
parent d6c87db64f
commit 63eaafbe8f
4 changed files with 113 additions and 51 deletions

View File

@ -1,11 +1,18 @@
use crate::dsl::{BooleanHandler, FloatHandler, IntegerHandler, NoValueHandler, NullHandler}; use crate::dsl::{BooleanHandler, FloatHandler, IntegerHandler, NoValueHandler, NullHandler};
use std::marker::PhantomData; 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, 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 { pub fn create(f: StoreFn) -> Self {
return Self { return Self {
store: f, 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> { impl<Runtime: ?Sized, Container: ?Sized, StoreFn: Fn(&mut Runtime, &mut Container, bool)>
fn handleBoolean(&self, dst: &mut S, value: bool) { BooleanHandler<Runtime, Container> for Handler_Boolean<Runtime, Container, StoreFn>
(self.store)(dst, value); {
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, 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 { pub fn create(f: StoreFn) -> Self {
return Self { return Self {
store: f, 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> { impl<Runtime: ?Sized, Container: ?Sized, StoreFn: Fn(&mut Runtime, &mut Container)>
fn handleNull(&self, dst: &mut S) { NullHandler<Runtime, Container> for Handler_Null<Runtime, Container, StoreFn>
(self.store)(dst); {
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, 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 { pub fn create(f: StoreFn) -> Self {
return Self { return Self {
store: f, 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> { impl<Runtime: ?Sized, Container: ?Sized, StoreFn: Fn(&mut Runtime, &mut Container)>
fn handleNoValue(&self, dst: &mut S) { NoValueHandler<Runtime, Container> for Handler_NoValue<Runtime, Container, StoreFn>
(self.store)(dst); {
fn handleNoValue(&self, runtime: &mut Runtime, dst: &mut Container) {
(self.store)(runtime, dst);
} }
} }

View File

@ -1,11 +1,17 @@
use crate::dsl::{FloatHandler, IntegerHandler}; use crate::dsl::{FloatHandler, IntegerHandler};
use std::marker::PhantomData; 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, 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 { pub fn create(f: StoreFn) -> Self {
return Self { return Self {
store: f, 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> { impl<Runtime: ?Sized, Container: ?Sized, StoreFn: Fn(&mut Runtime, &mut Container, f64)>
fn handleFloat(&self, dst: &mut S, value: f64) { FloatHandler<Runtime, Container> for Handler_F64<Runtime, Container, StoreFn>
(self.store)(dst, value); {
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, 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 { pub fn create(f: StoreFn) -> Self {
return Self { return Self {
store: f, 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> { impl<Runtime: ?Sized, Container: ?Sized, StoreFn: Fn(&mut Runtime, &mut Container, f32)>
fn handleFloat(&self, dst: &mut S, value: f64) { FloatHandler<Runtime, Container> for Handler_F32<Runtime, Container, StoreFn>
(self.store)(dst, value as f32); {
fn handleFloat(&self, runtime: &mut Runtime, dst: &mut Container, value: f64) {
(self.store)(runtime, dst, value as f32);
} }
} }

View File

@ -3,12 +3,20 @@ use std::marker::PhantomData;
macro_rules! defineIntegerHandler { macro_rules! defineIntegerHandler {
($vis:vis $name:ident < $int_type:ty >) => { ($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, 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 { pub fn create(f: StoreFn) -> Self {
return Self { return Self {
store: f, store: f,
@ -17,11 +25,20 @@ macro_rules! defineIntegerHandler {
} }
} }
impl <S, StoreFn: Fn(&mut S, $int_type)> IntegerHandler<S> for $name <S, StoreFn> { impl <
fn handleFixedInteger(&self, dst: &mut S, value: u64, isNegative: bool) { 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; let downcasted: $int_type;
if isNegative { if isNegative {
#[allow(unused_comparisons)]
if <$int_type>::MIN >= 0 || value > (<$int_type>::abs_diff(0, <$int_type>::MIN)) as u64 { if <$int_type>::MIN >= 0 || value > (<$int_type>::abs_diff(0, <$int_type>::MIN)) as u64 {
panic!( panic!(
"Integer underflow: expected in range {}..={}, got -{}", "Integer underflow: expected in range {}..={}, got -{}",
@ -39,7 +56,7 @@ macro_rules! defineIntegerHandler {
downcasted = value as $int_type; downcasted = value as $int_type;
} }
(self.store)(dst, downcasted); (self.store)(runtime, dst, downcasted);
return; return;
} }
} }

View File

@ -38,58 +38,62 @@ pub trait ArrayHandler<Runtime: ?Sized, ParentContainer: ?Sized, ArrayBuilder>:
fn storeArray(&self, runtime: &mut Runtime, dst: &mut ParentContainer, value: 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; type ObjectBuilder: Sized;
fn configureObject( fn configureObject(
&self, &self,
scope: &impl ObjectConfigurationScope<Runtime, Self::ObjectBuilder>, scope: &impl ObjectConfigurationScope<Runtime, Self::ObjectBuilder, String>,
) -> impl ObjectHandler<Runtime, ParentContainer, Self::ObjectBuilder>; ) -> 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; type ArrayBuilder: Sized;
fn configureArray( fn configureArray(
&self, &self,
scope: &impl ArrayConfigurationScope<Runtime, Self::ArrayBuilder>, scope: &impl ArrayConfigurationScope<Runtime, Self::ArrayBuilder, String>,
) -> impl ObjectHandler<Runtime, ParentContainer, Self::ArrayBuilder>; ) -> impl ObjectHandler<Runtime, ParentContainer, Self::ArrayBuilder>;
} }
pub trait ObjectConfigurationScope<Runtime: ?Sized, Container: ?Sized> { pub trait ObjectConfigurationScope<Runtime: ?Sized, Container: ?Sized, String> {
type Key: Sized; type Key: Sized;
fn ignoreKey_required(&mut self, name: Self::Key); fn ignoreKey_required(&mut self, name: Self::Key);
fn ignoreKey_optional(&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( fn processKey_optional(
&mut self, &mut self,
name: Self::Key, name: Self::Key,
config: impl ValueConfiguration<Runtime, Container>, config: impl ValueConfiguration<Runtime, Container, String>,
fallback: impl NoValueHandler<Runtime, Container>, 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_required(&self, start: usize, endInclusive: Option<usize>);
fn ignoreElements_optional(&self, start: usize, endInclusive: Option<usize>); fn ignoreElements_optional(&self, start: usize, endInclusive: Option<usize>);
fn processElements_required( fn processElements_required(
&self, &self,
start: usize, start: usize,
endInclusive: Option<usize>, endInclusive: Option<usize>,
config: impl ValueConfiguration<Runtime, Container>, config: impl ValueConfiguration<Runtime, Container, String>,
); );
fn processElements_optional( fn processElements_optional(
&self, &self,
start: usize, start: usize,
endInclusive: Option<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 integerHandler(&self) -> Option<impl IntegerHandler<Runtime, Container>>;
fn floatHandler(&self) -> Option<impl FloatHandler<Runtime, Container>>; fn floatHandler(&self) -> Option<impl FloatHandler<Runtime, Container>>;
fn booleanHandler(&self) -> Option<impl BooleanHandler<Runtime, Container>>; fn booleanHandler(&self) -> Option<impl BooleanHandler<Runtime, Container>>;
fn nullHandler(&self) -> Option<impl NullHandler<Runtime, Container>>; fn nullHandler(&self) -> Option<impl NullHandler<Runtime, Container>>;
fn arrayHandler(&self) -> Option<impl ObjectConfiguration<Runtime, Container>>; fn objectHandler(&self) -> Option<impl ObjectConfiguration<Runtime, Container, String>>;
fn objectHandler(&self) -> Option<impl ArrayConfiguration<Runtime, Container>>; fn arrayHandler(&self) -> Option<impl ArrayConfiguration<Runtime, Container, String>>;
// fn stringHandler(&self) -> Option<impl StringHandler<Runtime, Container>>; fn stringHandler(&self) -> Option<impl StringHandler<Runtime, Container, String>>;
} }