Merge branch 'macros'
This commit is contained in:
commit
6d0e1fe88c
@ -1,6 +1,7 @@
|
|||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
mod _keyword_impls;
|
mod _keyword_impls;
|
||||||
|
mod macros;
|
||||||
|
|
||||||
pub trait Predicate<C> {
|
pub trait Predicate<C> {
|
||||||
fn check(&mut self, chr: C) -> bool;
|
fn check(&mut self, chr: C) -> bool;
|
||||||
|
|||||||
38
src/macros/builder_trait_decl.rs
Normal file
38
src/macros/builder_trait_decl.rs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#[macro_export]
|
||||||
|
macro_rules! builder_trait_decl {
|
||||||
|
(
|
||||||
|
$scope:vis trait $name:ident
|
||||||
|
$(<
|
||||||
|
$generic0Name:ident $(: $generic0Bound:path)? $(, $genericNName:ident $(: $genericNBound:path)?)*
|
||||||
|
>)?
|
||||||
|
$(: $base0:path $(, $baseN:path)*)?
|
||||||
|
{ $($body:tt)* }
|
||||||
|
) => {
|
||||||
|
$scope trait $name
|
||||||
|
<
|
||||||
|
'source, 'pos, P:Pos<'pos>, CS:CollectedSubstring<'source>
|
||||||
|
$(, $generic0Name $(: $generic0Bound)? $(, $genericNName $(: $genericNBound)?)* )?
|
||||||
|
>
|
||||||
|
$(: $base0 $(, $baseN)*)?
|
||||||
|
{ $($body)* }
|
||||||
|
};
|
||||||
|
|
||||||
|
(
|
||||||
|
$scope:vis trait $name:ident
|
||||||
|
<
|
||||||
|
$lifetime0Name:lifetime $(, $lifetimeNName:lifetime)*
|
||||||
|
$(, $genericNName:ident $(: $genericNBound:path)?)*
|
||||||
|
>
|
||||||
|
$(: $base0:path $(, $baseN:path)*)?
|
||||||
|
{ $($body:tt)* }
|
||||||
|
) => {
|
||||||
|
$scope trait $name
|
||||||
|
<
|
||||||
|
'source, 'pos, $lifetime0Name $(, $lifetimeNName)*,
|
||||||
|
P: Pos<'pos>, CS: CollectedSubstring<'source>
|
||||||
|
$(, $genericNName $(: $genericNBound)?)*
|
||||||
|
>
|
||||||
|
$(: $base0 $(, $baseN)*)?
|
||||||
|
{ $($body)* }
|
||||||
|
};
|
||||||
|
}
|
||||||
58
src/macros/builder_type_t.rs
Normal file
58
src/macros/builder_type_t.rs
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#[macro_export]
|
||||||
|
macro_rules! builder_type_t {
|
||||||
|
(
|
||||||
|
$name:ident
|
||||||
|
$(<
|
||||||
|
$generic0Name:ty $(, $genericNName:ty)*
|
||||||
|
>)?
|
||||||
|
|
||||||
|
) => {
|
||||||
|
$name
|
||||||
|
<
|
||||||
|
'source, 'pos, P, CS
|
||||||
|
$(, $generic0Name $(, $genericNName)*)?
|
||||||
|
>
|
||||||
|
|
||||||
|
};
|
||||||
|
(
|
||||||
|
$name:ident
|
||||||
|
<
|
||||||
|
$lifetime0Name:lifetime $(, $lifetimeNName:lifetime)*
|
||||||
|
$(, $genericNName:ty)*
|
||||||
|
>
|
||||||
|
) => {
|
||||||
|
$name
|
||||||
|
<
|
||||||
|
'source, 'pos, $lifetime0Name $(, $lifetimeNName)*,
|
||||||
|
P, CS $(, $genericNName)*
|
||||||
|
>
|
||||||
|
};
|
||||||
|
|
||||||
|
(
|
||||||
|
impl $name:ident
|
||||||
|
$(<
|
||||||
|
$generic0Name:ty $(, $genericNName:ty)*
|
||||||
|
>)?
|
||||||
|
|
||||||
|
) => {
|
||||||
|
impl $name
|
||||||
|
<
|
||||||
|
'source, 'pos, P, CS
|
||||||
|
$(, $generic0Name $(, $genericNName)*)?
|
||||||
|
>
|
||||||
|
|
||||||
|
};
|
||||||
|
(
|
||||||
|
impl $name:ident
|
||||||
|
<
|
||||||
|
$lifetime0Name:lifetime $(, $lifetimeNName:lifetime)*
|
||||||
|
$(, $genericNName:ty)*
|
||||||
|
>
|
||||||
|
) => {
|
||||||
|
impl $name
|
||||||
|
<
|
||||||
|
'source, 'pos, $lifetime0Name $(, $lifetimeNName)*,
|
||||||
|
P, CS $(, $genericNName)*
|
||||||
|
>
|
||||||
|
};
|
||||||
|
}
|
||||||
3
src/macros/mod.rs
Normal file
3
src/macros/mod.rs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
mod builder_type_t;
|
||||||
|
mod parser_fn_decl;
|
||||||
|
mod builder_trait_decl;
|
||||||
86
src/macros/parser_fn_decl.rs
Normal file
86
src/macros/parser_fn_decl.rs
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
#[macro_export]
|
||||||
|
macro_rules! parser_fn_decl {
|
||||||
|
// only type generics | default src type -------------------------------------------------------
|
||||||
|
(
|
||||||
|
$scope:vis fn $name:ident
|
||||||
|
$(<
|
||||||
|
$generic0Name:ident $(: $generic0Bound:path)? $(, $genericNName:ident $(: $genericNBound:path)?)*
|
||||||
|
>)?
|
||||||
|
($srcName:ident : $srcType:ty $(, $argNName:ident : $argNType:ty)*)
|
||||||
|
$(-> $ret:ty)?
|
||||||
|
$body:block
|
||||||
|
) => {
|
||||||
|
$scope fn $name
|
||||||
|
<
|
||||||
|
'source, 'pos, P:Pos<'pos>, CS:CollectedSubstring<'source>
|
||||||
|
$(, $generic0Name $(: $generic0Bound)? $(, $genericNName $(: $genericNBound)?)* )?
|
||||||
|
>
|
||||||
|
($srcName: $srcType $(, $argNName : $argNType)*)
|
||||||
|
$(-> $ret)?
|
||||||
|
$body
|
||||||
|
};
|
||||||
|
|
||||||
|
// lifetime + type generics | default src type --------------------------------------------------
|
||||||
|
(
|
||||||
|
$scope:vis fn $name:ident
|
||||||
|
<
|
||||||
|
$lifetime0Name:lifetime $(, $lifetimeNName:lifetime)*
|
||||||
|
$(, $genericNName:ident $(: $genericNBound:path)?)*
|
||||||
|
>
|
||||||
|
($srcName:ident : $srcType:ty $(, $argNName:ident : $argNType:ty)*)
|
||||||
|
$(-> $ret:ty)?
|
||||||
|
$body:block
|
||||||
|
) => {
|
||||||
|
$scope fn $name
|
||||||
|
<
|
||||||
|
'source, 'pos, $lifetime0Name $(, $lifetimeNName)*,
|
||||||
|
P: Pos<'pos>, CS: CollectedSubstring<'source>
|
||||||
|
$(, $genericNName $(: $genericNBound)?)*
|
||||||
|
>
|
||||||
|
($srcName: $srcType $(, $argNName : $argNType)*)
|
||||||
|
$(-> $ret)?
|
||||||
|
$body
|
||||||
|
};
|
||||||
|
|
||||||
|
// only type generics | custom src type --------------------------------------------------------
|
||||||
|
(
|
||||||
|
$scope:vis fn $name:ident
|
||||||
|
$(<
|
||||||
|
$generic0Name:ident $(: $generic0Bound:path)? $(, $genericNName:ident $(: $genericNBound:path)?)*
|
||||||
|
>)?
|
||||||
|
($srcName:ident $(, $argNName:ident : $argNType:ty)*)
|
||||||
|
$(-> $ret:ty)?
|
||||||
|
$body:block
|
||||||
|
) => {
|
||||||
|
$scope fn $name
|
||||||
|
<
|
||||||
|
'source, 'pos, P:Pos<'pos>, CS:CollectedSubstring<'source>
|
||||||
|
$(, $generic0Name $(: $generic0Bound)? $(, $genericNName $(: $genericNBound)?)* )?
|
||||||
|
>
|
||||||
|
($srcName: &'source mut impl SourceStream<'source, 'pos, P=P, CS=CS> $(, $argNName : $argNType)*)
|
||||||
|
$(-> $ret)?
|
||||||
|
$body
|
||||||
|
};
|
||||||
|
|
||||||
|
// lifetime + type generics | custom src type --------------------------------------------------
|
||||||
|
(
|
||||||
|
$scope:vis fn $name:ident
|
||||||
|
<
|
||||||
|
$lifetime0Name:lifetime $(, $lifetimeNName:lifetime)*
|
||||||
|
$(, $genericNName:ident $(: $genericNBound:path)?)*
|
||||||
|
>
|
||||||
|
($srcName:ident $(, $argNName:ident : $argNType:ty)*)
|
||||||
|
$(-> $ret:ty)?
|
||||||
|
$body:block
|
||||||
|
) => {
|
||||||
|
$scope fn $name
|
||||||
|
<
|
||||||
|
'source, 'pos, $lifetime0Name $(, $lifetimeNName)*,
|
||||||
|
P: Pos<'pos>, CS: CollectedSubstring<'source>
|
||||||
|
$(, $genericNName $(: $genericNBound)?)*
|
||||||
|
>
|
||||||
|
($srcName: &'source mut impl SourceStream<'source, 'pos, P=P, CS=CS> $(, $argNName : $argNType)*)
|
||||||
|
$(-> $ret)?
|
||||||
|
$body
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user