From 8921decb22996d7d6070cbfe0d91a8835e215189 Mon Sep 17 00:00:00 2001 From: Serge Latyntcev Date: Tue, 27 Dec 2022 11:08:25 +1300 Subject: [PATCH] Fix codestyle, remove redundant comments, implement Chord for IncognitumValue --- src/book/extractor/mod.rs | 15 ++- src/composer.rs | 137 ++++++++++++------------- src/face.rs | 42 ++++---- src/model/renderer.rs | 67 ------------ src/model/schema/core.rs | 1 - src/model/yaml/str.rs | 6 +- src/model/yamlette/incognitum.rs | 4 +- src/orchestra/chord.rs | 23 +++++ tests/examples/composer.rs | 145 ++++++++++---------------- tests/examples/face.rs | 171 ++++++++++++++----------------- 10 files changed, 251 insertions(+), 360 deletions(-) diff --git a/src/book/extractor/mod.rs b/src/book/extractor/mod.rs index 3cacf37..25ec2d9 100644 --- a/src/book/extractor/mod.rs +++ b/src/book/extractor/mod.rs @@ -1,19 +1,16 @@ pub mod pointer; pub mod traits; - pub use self::pointer::Pointer; pub use self::traits::FromPointer; - - #[macro_export] macro_rules! yamlette_reckon { ( book ; $book:expr ; [ $( $rules:tt ),* ] ) => { let mut _counter: usize = 0; $( let volume = $book.volumes.get (_counter); - yamlette_reckon! ( volume ; volume ; $rules ); + $crate::yamlette_reckon! ( volume ; volume ; $rules ); _counter += 1; )* }; @@ -22,7 +19,7 @@ macro_rules! yamlette_reckon { ( volume ; $volume:expr ; [ $( $rules:tt ),* ] ) => { let _pointer = if let Some (volume) = $volume { $crate::book::extractor::pointer::Pointer::new (volume) } else { None }; $( - yamlette_reckon! ( ptr ; _pointer ; $rules ); + $crate::yamlette_reckon! ( ptr ; _pointer ; $rules ); let _pointer = if let Some (p) = _pointer { p.next_sibling () } else { None }; )* }; @@ -31,7 +28,7 @@ macro_rules! yamlette_reckon { ( ptr ; $pointer:expr ; [ $( $v:tt ),* ] ) => { let _pointer = if let Some (p) = $pointer { p.into_seq () } else { None }; $( - yamlette_reckon! ( ptr ; _pointer ; $v ); + $crate::yamlette_reckon! ( ptr ; _pointer ; $v ); let _pointer = if let Some (p) = _pointer { p.next_sibling () } else { None }; )* }; @@ -40,9 +37,9 @@ macro_rules! yamlette_reckon { ( ptr ; $pointer:expr ; { $( $k:tt > $v:tt ),* } ) => { let _pointer = if let Some (p) = $pointer { p.into_map () } else { None }; $( - yamlette_reckon! ( ptr ; _pointer ; $k ); + $crate::yamlette_reckon! ( ptr ; _pointer ; $k ); let _pointer = if let Some (p) = _pointer { p.next_sibling () } else { None }; - yamlette_reckon! ( ptr ; _pointer ; $v ); + $crate::yamlette_reckon! ( ptr ; _pointer ; $v ); let _pointer = if let Some (p) = _pointer { p.next_sibling () } else { None }; )* }; @@ -70,7 +67,7 @@ macro_rules! yamlette_reckon { if !found { _pointer = None; } } - yamlette_reckon! ( ptr ; _pointer ; $v ); + $crate::yamlette_reckon! ( ptr ; _pointer ; $v ); )* }; diff --git a/src/composer.rs b/src/composer.rs index d54903c..b91cb84 100644 --- a/src/composer.rs +++ b/src/composer.rs @@ -2,48 +2,46 @@ macro_rules! yamlette_compose { ( ignore ; $ignored:tt ; $expr:tt ) => { $expr }; + ( orchestra ; $orchestra:expr ; $volumes:tt ) => {{ $crate::yamlette_compose! ( volumes ; &$orchestra ; $volumes ; [ ] ; [ ] ) }}; - ( orchestra ; $orchestra:expr ; $volumes:tt ) => {{ yamlette_compose! ( volumes ; &$orchestra ; $volumes ; [ ] ; [ ] ) }}; - - - ( size ; [# $( $style:expr ),* => $( $element:tt ),* ] ) => {{ yamlette_compose! ( size ; [ $( $element ),* ] ) }}; + ( size ; [# $( $style:expr ),* => $( $element:tt ),* ] ) => {{ $crate::yamlette_compose! ( size ; [ $( $element ),* ] ) }}; ( size ; [ $( $element:tt ),* ] ) => {{ let mut _size = 1; $( - _size += yamlette_compose! ( size ; $element ); + _size += $crate::yamlette_compose! ( size ; $element ); )* _size }}; - ( size ; {# $( $style:expr ),* => $( $key:tt : $val:tt ),* } ) => {{ yamlette_compose! ( size ; { $( $key : $val ),* } ) }}; + ( size ; {# $( $style:expr ),* => $( $key:tt : $val:tt ),* } ) => {{ $crate::yamlette_compose! ( size ; { $( $key : $val ),* } ) }}; ( size ; { $( $key:tt : $val:tt ),* } ) => {{ let mut _size = 1; $( - _size += yamlette_compose! ( size ; $key ); - _size += yamlette_compose! ( size ; $val ); + _size += $crate::yamlette_compose! ( size ; $key ); + _size += $crate::yamlette_compose! ( size ; $val ); )* _size }}; - ( size ; ( # $( $style:expr ),* => $elem:tt ) ) => {{ yamlette_compose! ( size ; $elem ) }}; + ( size ; ( # $( $style:expr ),* => $elem:tt ) ) => {{ $crate::yamlette_compose! ( size ; $elem ) }}; - ( size ; ( # $( $style:expr ),* => $elem:expr ) ) => {{ yamlette_compose! ( size ; $elem ) }}; + ( size ; ( # $( $style:expr ),* => $elem:expr ) ) => {{ $crate::yamlette_compose! ( size ; $elem ) }}; - ( size ; ( & $alias:ident $elem:tt ) ) => {{ yamlette_compose! ( size ; $elem ) }}; + ( size ; ( & $alias:ident $elem:tt ) ) => {{ $crate::yamlette_compose! ( size ; $elem ) }}; - ( size ; ( & $alias:ident $elem:expr ) ) => {{ yamlette_compose! ( size ; $elem ) }}; + ( size ; ( & $alias:ident $elem:expr ) ) => {{ $crate::yamlette_compose! ( size ; $elem ) }}; ( size ; ( * $link:ident ) ) => {{ 1 }}; - ( size ; ( $elem:tt ) ) => {{ yamlette_compose! ( size ; $elem ) }}; + ( size ; ( $elem:tt ) ) => {{ $crate::yamlette_compose! ( size ; $elem ) }}; - ( size ; ( $elem:expr ) ) => {{ yamlette_compose! ( size ; $elem ) }}; + ( size ; ( $elem:expr ) ) => {{ $crate::yamlette_compose! ( size ; $elem ) }}; ( size ; $element:expr ) => {{ use $crate::orchestra::chord::Chord; @@ -52,33 +50,33 @@ macro_rules! yamlette_compose { ( directives ; $orchestra:expr ; $directives:tt ) => {{ - let _tags_count = yamlette_compose! ( directives ; tags count ; $directives ); + let _tags_count = $crate::yamlette_compose! ( directives ; tags count ; $directives ); if _tags_count > 0 { use std::borrow::Cow; let mut _tags: Vec<(Cow<'static, str>, Cow<'static, str>)> = Vec::with_capacity (_tags_count); - yamlette_compose! ( directives ; collect tags ; _tags ; $directives ); + $crate::yamlette_compose! ( directives ; collect tags ; _tags ; $directives ); $orchestra.directive_tags (_tags).ok ().unwrap (); } - yamlette_compose! ( directives ; others ; $orchestra ; $directives ); + $crate::yamlette_compose! ( directives ; others ; $orchestra ; $directives ); }}; ( directives ; tags count ; [ $( $directive:tt ),* ] ) => {{ let mut _size = 0; - $( _size += yamlette_compose! ( directives ; tag count ; $directive ); )* + $( _size += $crate::yamlette_compose! ( directives ; tag count ; $directive ); )* _size }}; ( directives ; tag count ; (TAG ; $shortcut:expr , $handle:expr ) ) => { 1 }; ( directives ; tag count ; $directive:tt ) => { 0 }; - ( directives ; collect tags ; $vec:expr ; [ $( $directive:tt ),* ] ) => { $( yamlette_compose! ( directive ; collect tags ; $vec ; $directive ); )* }; + ( directives ; collect tags ; $vec:expr ; [ $( $directive:tt ),* ] ) => { $( $crate::yamlette_compose! ( directive ; collect tags ; $vec ; $directive ); )* }; ( directive ; collect tags ; $vec:expr ; (TAG ; $shortcut:expr , $handle:expr ) ) => { $vec.push ( (Cow::from ($shortcut) , Cow::from ($handle)) ); }; ( directive ; collect tags ; $vec:expr ; $directive:tt ) => {{ }}; - ( directives ; others ; $orchestra:expr ; [ $( $directive:tt ),* ] ) => {{ $( yamlette_compose! ( directive ; others ; $orchestra ; $directive ); )* }}; + ( directives ; others ; $orchestra:expr ; [ $( $directive:tt ),* ] ) => {{ $( $crate::yamlette_compose! ( directive ; others ; $orchestra ; $directive ); )* }}; ( directive ; others ; $orchestra:expr ; YAML ) => {{ $orchestra.directive_yaml (true).ok ().unwrap (); }}; ( directive ; others ; $orchestra:expr ; NO_YAML ) => {{ $orchestra.directive_yaml (false).ok ().unwrap (); }}; ( directive ; others ; $orchestra:expr ; BORDER_TOP ) => {{ $orchestra.volume_border_top (true).ok ().unwrap (); }}; @@ -93,7 +91,7 @@ macro_rules! yamlette_compose { ( styles ; apply to common ; $common_styles:expr ; $styles:tt ) => {{ let mut cstyles = $common_styles; - let styles: &mut [ &mut dyn $crate::model::style::Style ] = &mut yamlette_compose! ( styles ; $styles ); + let styles: &mut [ &mut dyn $crate::model::style::Style ] = &mut $crate::yamlette_compose! ( styles ; $styles ); for style in styles { style.common_styles_apply (&mut cstyles); @@ -104,31 +102,31 @@ macro_rules! yamlette_compose { ( volumes ; $orchestra:expr ; [ # $( $style:expr ),* => % $( $directive:tt ),* => $( $volume:tt ),* ] ; [ ] ; [ ] ) => {{ - yamlette_compose! ( volumes ; $orchestra ; [ $( $volume ),* ] ; [ $( $style ),* ] ; [ $( $directive ),* ] ) + $crate::yamlette_compose! ( volumes ; $orchestra ; [ $( $volume ),* ] ; [ $( $style ),* ] ; [ $( $directive ),* ] ) }}; ( volumes ; $orchestra:expr ; [ % $( $directive:tt ),* => $( $volume:tt ),* ] ; [ ] ; [ ] ) => {{ - yamlette_compose! ( volumes ; $orchestra ; [ $( $volume ),* ] ; [ ] ; [ $( $directive ),* ] ) + $crate::yamlette_compose! ( volumes ; $orchestra ; [ $( $volume ),* ] ; [ ] ; [ $( $directive ),* ] ) }}; ( volumes ; $orchestra:expr ; [ # $( $style:expr ),* => $( $volume:tt ),* ] ; [ ] ; [ ] ) => {{ - yamlette_compose! ( volumes ; $orchestra ; [ $( $volume ),* ] ; [ $( $style ),* ] ; [ ] ) + $crate::yamlette_compose! ( volumes ; $orchestra ; [ $( $volume ),* ] ; [ $( $style ),* ] ; [ ] ) }}; ( volumes ; $orchestra:expr ; [ $( $volume:tt ),* ] ; $styles:tt ; $directives:tt ) => {{ let mut _size = 0; - $( yamlette_compose! ( ignore ; $volume ; { _size += 1; } ); )* + $( $crate::yamlette_compose! ( ignore ; $volume ; { _size += 1; } ); )* $orchestra.volumes (_size).ok ().unwrap (); let _common_styles = $orchestra.get_styles (); $( - yamlette_compose! ( volume ; $orchestra ; _common_styles ; $volume ; $styles ; $directives ); + $crate::yamlette_compose! ( volume ; $orchestra ; _common_styles ; $volume ; $styles ; $directives ); $orchestra.vol_end ().ok ().unwrap (); )* @@ -138,41 +136,41 @@ macro_rules! yamlette_compose { ( volume ; $orchestra:expr ; $common_styles:expr ; [ # $( $style:expr ),+ => % $( $directive:tt ),+ => $( $rule:tt ),* ] ; [ ] ; [ ] ) => {{ - yamlette_compose! ( volume ; $orchestra ; $common_styles ; [ $( $rule ),* ] ; [ $( $style ),* ] ; [ $( $directive ),* ] ); + $crate::yamlette_compose! ( volume ; $orchestra ; $common_styles ; [ $( $rule ),* ] ; [ $( $style ),* ] ; [ $( $directive ),* ] ); }}; ( volume ; $orchestra:expr ; $common_styles:expr ; [ # $( $style:expr ),+ => % $( $directive:tt ),+ => $( $rule:tt ),* ] ; [ $( $parent_style:expr ),* ] ; [ ] ) => {{ - yamlette_compose! ( volume ; $orchestra ; $common_styles ; [ $( $rule ),* ] ; [ $( $parent_style ),* , $( $style ),* ] ; [ $( $directive ),* ] ); + $crate::yamlette_compose! ( volume ; $orchestra ; $common_styles ; [ $( $rule ),* ] ; [ $( $parent_style ),* , $( $style ),* ] ; [ $( $directive ),* ] ); }}; ( volume ; $orchestra:expr ; $common_styles:expr ; [ # $( $style:expr ),+ => % $( $directive:tt ),+ => $( $rule:tt ),* ] ; [ ] ; [ $( $parent_directive:tt ),* ] ) => {{ - yamlette_compose! ( volume ; $orchestra ; $common_styles ; [ $( $rule ),* ] ; [ $( $style ),* ] ; [ $( $parent_directive ),* , $( $directive ),* ] ); + $crate::yamlette_compose! ( volume ; $orchestra ; $common_styles ; [ $( $rule ),* ] ; [ $( $style ),* ] ; [ $( $parent_directive ),* , $( $directive ),* ] ); }}; ( volume ; $orchestra:expr ; $common_styles:expr ; [ # $( $style:expr ),+ => % $( $directive:tt ),+ => $( $rule:tt ),* ] ; [ $( $parent_style:expr ),* ] ; [ $( $parent_directive:tt ),* ] ) => {{ - yamlette_compose! ( volume ; $orchestra ; $common_styles ; [ $( $rule ),* ] ; [ $( $parent_style ),* , $( $style ),* ] ; [ $( $parent_directive ),* , $( $directive ),* ] ); + $crate::yamlette_compose! ( volume ; $orchestra ; $common_styles ; [ $( $rule ),* ] ; [ $( $parent_style ),* , $( $style ),* ] ; [ $( $parent_directive ),* , $( $directive ),* ] ); }}; ( volume ; $orchestra:expr ; $common_styles:expr ; [ % $( $directive:tt ),* => $( $rule:tt ),* ] ; $styles:tt ; [ ] ) => {{ - yamlette_compose! ( volume ; $orchestra ; $common_styles ; [ $( $rule ),* ] ; $styles ; [ $( $directive ),* ] ); + $crate::yamlette_compose! ( volume ; $orchestra ; $common_styles ; [ $( $rule ),* ] ; $styles ; [ $( $directive ),* ] ); }}; ( volume ; $orchestra:expr ; $common_styles:expr ; [ % $( $directive:tt ),* => $( $rule:tt ),* ] ; $styles:tt ; [ $( $parent_directive:tt ),* ] ) => {{ - yamlette_compose! ( volume ; $orchestra ; $common_styles ; [ $( $rule ),* ] ; $styles ; [ $( $parent_directive ),* , $( $directive ),* ] ); + $crate::yamlette_compose! ( volume ; $orchestra ; $common_styles ; [ $( $rule ),* ] ; $styles ; [ $( $parent_directive ),* , $( $directive ),* ] ); }}; ( volume ; $orchestra:expr ; $common_styles:expr ; [ # $( $style:expr ),* => $( $rule:tt ),* ] ; [ ] ; $directives:tt ) => {{ - yamlette_compose! ( volume ; $orchestra ; $common_styles ; [ $( $rule ),* ] ; [ $( $style ),* ] ; $directives ); + $crate::yamlette_compose! ( volume ; $orchestra ; $common_styles ; [ $( $rule ),* ] ; [ $( $style ),* ] ; $directives ); }}; ( volume ; $orchestra:expr ; $common_styles:expr ; [ # $( $style:expr ),* => $( $rule:tt ),* ] ; [ $( $parent_style:expr ),* ] ; $directives:tt ) => {{ - yamlette_compose! ( volume ; $orchestra ; $common_styles ; [ $( $rule ),* ] ; [ $( $parent_style ),* , $( $style ),* ] ; $directives ); + $crate::yamlette_compose! ( volume ; $orchestra ; $common_styles ; [ $( $rule ),* ] ; [ $( $parent_style ),* , $( $style ),* ] ; $directives ); }}; @@ -181,103 +179,103 @@ macro_rules! yamlette_compose { $orchestra.vol_next ().ok ().unwrap (); - yamlette_compose! ( directives ; $orchestra ; $directives ); + $crate::yamlette_compose! ( directives ; $orchestra ; $directives ); - $( yamlette_compose! ( ignore ; $rules ; { _size += yamlette_compose! ( size ; $rules ); } ); )* + $( $crate::yamlette_compose! ( ignore ; $rules ; { _size += $crate::yamlette_compose! ( size ; $rules ); } ); )* $orchestra.vol_reserve (_size).ok ().unwrap (); - let _common_styles = yamlette_compose! ( styles ; apply to common ; $common_styles ; $styles ); + let _common_styles = $crate::yamlette_compose! ( styles ; apply to common ; $common_styles ; $styles ); $( - yamlette_compose! ( play ; $orchestra ; 0 ; $rules ; _common_styles ; $styles ; None ); + $crate::yamlette_compose! ( play ; $orchestra ; 0 ; $rules ; _common_styles ; $styles ; None ); )* }}; ( play ; $orchestra:expr ; $level:expr ; [ # $( $style:expr ),* => $( $element:tt ),* ] ; $common_styles:expr ; [] ; $alias:expr ) => {{ - yamlette_compose! ( play ; $orchestra ; $level ; [ $( $element ),* ] ; $common_styles ; [ $( $style ),* ] ; $alias ) + $crate::yamlette_compose! ( play ; $orchestra ; $level ; [ $( $element ),* ] ; $common_styles ; [ $( $style ),* ] ; $alias ) }}; ( play ; $orchestra:expr ; $level:expr ; [ # $( $style:expr ),* => $( $element:tt ),* ] ; $common_styles:expr ; [ $( $parent_style:expr ),+ ] ; $alias:expr ) => {{ - yamlette_compose! ( play ; $orchestra ; $level ; [ $( $element ),* ] ; $common_styles ; [ $( $parent_style ),* , $( $style ),* ] ; $alias ) + $crate::yamlette_compose! ( play ; $orchestra ; $level ; [ $( $element ),* ] ; $common_styles ; [ $( $parent_style ),* , $( $style ),* ] ; $alias ) }}; ( play ; $orchestra:expr ; $level:expr ; [ $( $element:tt ),* ] ; $common_styles:expr ; $styles:tt ; $alias:expr ) => {{ use $crate::orchestra::chord::{ Chord, EmptyList }; - let styles: &mut [ &mut dyn $crate::model::style::Style ] = &mut yamlette_compose! ( styles ; $styles ); + let styles: &mut [ &mut dyn $crate::model::style::Style ] = &mut $crate::yamlette_compose! ( styles ; $styles ); Chord::play (EmptyList, $orchestra, $level, $alias, $common_styles, styles).ok ().unwrap (); - let _common_styles = yamlette_compose! ( styles ; apply to common ; $common_styles ; $styles ); + let _common_styles = $crate::yamlette_compose! ( styles ; apply to common ; $common_styles ; $styles ); $( - yamlette_compose! ( play ; $orchestra ; $level + 1 ; $element ; _common_styles ; $styles ; None ); + $crate::yamlette_compose! ( play ; $orchestra ; $level + 1 ; $element ; _common_styles ; $styles ; None ); )* }}; ( play ; $orchestra:expr ; $level:expr ; { # $( $style:expr ),* => $( $key:tt : $val:tt ),* } ; $common_styles:expr ; [] ; $alias:expr ) => {{ - yamlette_compose! ( play ; $orchestra ; $level ; { $( $key : $val ),* } ; $common_styles ; [ $( $style ),* ] ; $alias ) + $crate::yamlette_compose! ( play ; $orchestra ; $level ; { $( $key : $val ),* } ; $common_styles ; [ $( $style ),* ] ; $alias ) }}; ( play ; $orchestra:expr ; $level:expr ; { # $( $style:expr ),* => $( $key:tt : $val:tt ),* } ; $common_styles:expr ; [ $( $parent_style:expr ),+ ] ; $alias:expr ) => {{ - yamlette_compose! ( play ; $orchestra ; $level ; { $( $key : $val ),* } ; $common_styles ; [ $( $parent_style ),* , $( $style ),* ] ; $alias ) + $crate::yamlette_compose! ( play ; $orchestra ; $level ; { $( $key : $val ),* } ; $common_styles ; [ $( $parent_style ),* , $( $style ),* ] ; $alias ) }}; ( play ; $orchestra:expr ; $level:expr ; { $( $key:tt : $val:tt ),* } ; $common_styles:expr ; $styles:tt ; $alias:expr ) => {{ use $crate::orchestra::chord::{ Chord, EmptyDict }; - let styles: &mut [ &mut dyn $crate::model::style::Style ] = &mut yamlette_compose! ( styles ; $styles ); + let styles: &mut [ &mut dyn $crate::model::style::Style ] = &mut $crate::yamlette_compose! ( styles ; $styles ); Chord::play (EmptyDict, $orchestra, $level, $alias, $common_styles, styles).ok ().unwrap (); - let _common_styles = yamlette_compose! ( styles ; apply to common ; $common_styles ; $styles ); + let _common_styles = $crate::yamlette_compose! ( styles ; apply to common ; $common_styles ; $styles ); $( - yamlette_compose! ( play ; $orchestra ; $level + 1 ; $key ; _common_styles ; $styles ; None ); - yamlette_compose! ( play ; $orchestra ; $level + 1 ; $val ; _common_styles ; $styles ; None ); + $crate::yamlette_compose! ( play ; $orchestra ; $level + 1 ; $key ; _common_styles ; $styles ; None ); + $crate::yamlette_compose! ( play ; $orchestra ; $level + 1 ; $val ; _common_styles ; $styles ; None ); )* }}; ( play ; $orchestra:expr ; $level:expr ; ( # $( $style:expr ),* => $element:tt ) ; $common_styles:expr ; [ ] ; $alias:expr ) => {{ - let _common_styles = yamlette_compose! ( styles ; apply to common ; $common_styles ; [ $( $style ),* ] ); + let _common_styles = $crate::yamlette_compose! ( styles ; apply to common ; $common_styles ; [ $( $style ),* ] ); - yamlette_compose! ( play ; $orchestra ; $level ; $element ; _common_styles ; [ $( $style ),* ] ; $alias ); + $crate::yamlette_compose! ( play ; $orchestra ; $level ; $element ; _common_styles ; [ $( $style ),* ] ; $alias ); }}; ( play ; $orchestra:expr ; $level:expr ; ( # $( $style:expr ),* => $element:tt ) ; $common_styles:expr ; [ $( $parent_style:expr ),* ] ; $alias:expr ) => {{ - let _common_styles = yamlette_compose! ( styles ; apply to common ; $common_styles ; [ $( $style ),* ] ); + let _common_styles = $crate::yamlette_compose! ( styles ; apply to common ; $common_styles ; [ $( $style ),* ] ); - yamlette_compose! ( play ; $orchestra ; $level ; $element ; _common_styles ; [ $( $parent_style ),* , $( $style ),* ] ; $alias ); + $crate::yamlette_compose! ( play ; $orchestra ; $level ; $element ; _common_styles ; [ $( $parent_style ),* , $( $style ),* ] ; $alias ); }}; ( play ; $orchestra:expr ; $level:expr ; ( # $( $style:expr ),* => $element:expr ) ; $common_styles:expr ; [ ] ; $alias:expr ) => {{ - let _common_styles = yamlette_compose! ( styles ; apply to common ; $common_styles ; [ $( $style ),* ] ); + let _common_styles = $crate::yamlette_compose! ( styles ; apply to common ; $common_styles ; [ $( $style ),* ] ); - yamlette_compose! ( play ; $orchestra ; $level ; $element ; _common_styles ; [ $( $style ),* ] ; $alias ); + $crate::yamlette_compose! ( play ; $orchestra ; $level ; $element ; _common_styles ; [ $( $style ),* ] ; $alias ); }}; ( play ; $orchestra:expr ; $level:expr ; ( # $( $style:expr ),* => $element:expr ) ; $common_styles:expr ; [ $( $parent_style:expr ),* ] ; $alias:expr ) => {{ - let _common_styles = yamlette_compose! ( styles ; apply to common ; $common_styles ; [ $( $style ),* ] ); + let _common_styles = $crate::yamlette_compose! ( styles ; apply to common ; $common_styles ; [ $( $style ),* ] ); - yamlette_compose! ( unit ; $orchestra ; $level ; $element ; _common_styles ; [ $( $parent_style ),* , $( $style ),* ] ; $alias ); + $crate::yamlette_compose! ( unit ; $orchestra ; $level ; $element ; _common_styles ; [ $( $parent_style ),* , $( $style ),* ] ; $alias ); }}; ( play ; $orchestra:expr ; $level:expr ; ( & $new_alias:ident $element:tt ) ; $common_styles:expr ; $styles:tt ; $alias:expr ) => {{ use std::borrow::Cow; - yamlette_compose! ( play ; $orchestra ; $level ; $element ; $common_styles ; $styles ; Some (Cow::from (stringify! ($new_alias))) ); + $crate::yamlette_compose! ( play ; $orchestra ; $level ; $element ; $common_styles ; $styles ; Some (Cow::from (stringify! ($new_alias))) ); }}; ( play ; $orchestra:expr ; $level:expr ; ( & $new_alias:ident $element:expr ) ; $common_styles:expr ; $styles:tt ; $alias:expr ) => {{ use std::borrow::Cow; - yamlette_compose! ( play ; $orchestra ; $level ; $element ; $common_styles ; $styles ; Some (Cow::from (stringify! ($new_alias))) ); + $crate::yamlette_compose! ( play ; $orchestra ; $level ; $element ; $common_styles ; $styles ; Some (Cow::from (stringify! ($new_alias))) ); }}; ( play ; $orchestra:expr ; $level:expr ; ( * $link:ident ) ; $common_styles:expr ; $styles:tt ; $alias:expr ) => {{ @@ -287,42 +285,39 @@ macro_rules! yamlette_compose { }}; ( play ; $orchestra:expr ; $level:expr ; ( $element:tt ) ; $common_styles:expr ; $styles:tt ; $alias:expr ) => {{ - yamlette_compose! ( play ; $orchestra ; $level ; $element ; $common_styles ; $styles ; $alias ); + $crate::yamlette_compose! ( play ; $orchestra ; $level ; $element ; $common_styles ; $styles ; $alias ); }}; ( play ; $orchestra:expr ; $level:expr ; ( $element:expr ) ; $common_styles:expr ; $styles:tt ; $alias:expr ) => {{ - yamlette_compose! ( unit ; $orchestra ; $level ; $element ; $common_styles ; $styles ; $alias ); + $crate::yamlette_compose! ( unit ; $orchestra ; $level ; $element ; $common_styles ; $styles ; $alias ); }}; ( play ; $orchestra:expr ; $level:expr ; $element:expr ; $common_styles:expr ; $styles:tt ; $alias:expr ) => {{ - yamlette_compose! ( unit ; $orchestra ; $level ; $element ; $common_styles ; $styles ; $alias ); + $crate::yamlette_compose! ( unit ; $orchestra ; $level ; $element ; $common_styles ; $styles ; $alias ); }}; ( unit ; $orchestra:expr ; $level:expr ; $element:expr ; $common_styles:expr ; $styles:tt ; $alias:expr ) => {{ use $crate::orchestra::chord::Chord; - let styles: &mut [ &mut dyn $crate::model::style::Style ] = &mut yamlette_compose! ( styles ; $styles ); + let styles: &mut [ &mut dyn $crate::model::style::Style ] = &mut $crate::yamlette_compose! ( styles ; $styles ); Chord::play ($element, $orchestra, $level, $alias, $common_styles, styles).ok ().unwrap () }}; } - - - -#[cfg (all (test, not (feature = "dev")))] +#[cfg(all(test, not(feature = "dev")))] mod tests { #[test] - fn size () { + fn size() { let size = yamlette_compose! ( size ; "halo" ); - assert_eq! (1, size); + assert_eq!(1, size); let size = yamlette_compose! ( size ; () ); - assert_eq! (1, size); + assert_eq!(1, size); let size = yamlette_compose! ( size ; [ (), 1, "2", [ 4, { "a": 1, "b": 4 }, 3 ], () ] ); - assert_eq! (13, size); + assert_eq!(13, size); } } diff --git a/src/face.rs b/src/face.rs index 46bfbcb..7575b80 100644 --- a/src/face.rs +++ b/src/face.rs @@ -32,12 +32,12 @@ where #[macro_export] macro_rules! yamlette { - ( read ; $source:expr ; $rules:tt ) => { yamlette! ( read ; $source ; $rules ; {} ) }; + ( read ; $source:expr ; $rules:tt ) => { $crate::yamlette! ( read ; $source ; $rules ; {} ) }; ( read ; $source:expr ; $rules:tt ; $options:tt ) => { - let mut rs = yamlette! ( init ; reader ; $options ); + let mut rs = $crate::yamlette! ( init ; reader ; $options ); - yamlette! ( read ; warm ; &mut rs ; $source ; $rules ; $options ); + $crate::yamlette! ( read ; warm ; &mut rs ; $source ; $rules ; $options ); }; ( read ; warm ; $rs:expr ; $source:expr ; $rules:tt ; $options:tt ) => { @@ -59,17 +59,17 @@ macro_rules! yamlette { Err (ref mut err) => Err (Ok (::std::mem::replace (err, $crate::sage::SageError::Error (::std::borrow::Cow::from (String::with_capacity (0)))))) }; - yamlette_reckon! ( book ; _book ; $rules ); + $crate::yamlette_reckon! ( book ; _book ; $rules ); - yamlette! ( options moveout ; _book ; _result ; $options ); + $crate::yamlette! ( options moveout ; _book ; _result ; $options ); }; - ( sage ; $source:expr ; $rules:tt ) => { yamlette! ( sage ; $source ; $rules ; {} ) }; + ( sage ; $source:expr ; $rules:tt ) => { $crate::yamlette! ( sage ; $source ; $rules ; {} ) }; ( sage ; $source:expr ; $rules:tt ; $options:tt ) => { - let mut rs = yamlette! ( init ; sage ; $options ); + let mut rs = $crate::yamlette! ( init ; sage ; $options ); - yamlette! ( sage ; warm ; &mut rs ; $source ; $rules ; $options ); + $crate::yamlette! ( sage ; warm ; &mut rs ; $source ; $rules ; $options ); }; ( sage ; warm ; $rs:expr ; $source:expr ; $rules:tt ; $options:tt ) => { @@ -91,22 +91,22 @@ macro_rules! yamlette { Err (ref mut err) => Err (Ok (::std::mem::replace (err, $crate::sage::SageError::Error (::std::borrow::Cow::from (String::with_capacity (0)))))) }; - yamlette_reckon! ( book ; _book ; $rules ); + $crate::yamlette_reckon! ( book ; _book ; $rules ); - yamlette! ( options moveout ; _book ; _result ; $options ); + $crate::yamlette! ( options moveout ; _book ; _result ; $options ); }; - ( write ; $rules:tt ) => {{ yamlette! ( write ; $rules ; {} ) }}; + ( write ; $rules:tt ) => {{ $crate::yamlette! ( write ; $rules ; {} ) }}; ( write ; $rules:tt ; $options:tt ) => {{ - match yamlette! ( init ; writer ; $options ) { + match $crate::yamlette! ( init ; writer ; $options ) { Ok ( mut orch ) => yamlette! ( write ; warm ; &mut orch ; $rules ), Err ( err ) => Err ( err ) } }}; ( write ; warm ; $orchestra:expr ; $rules:tt ) => {{ - yamlette_compose! ( orchestra ; $orchestra ; $rules ); + $crate::yamlette_compose! ( orchestra ; $orchestra ; $rules ); match $orchestra.listen () { Ok (music) => Ok (unsafe { String::from_utf8_unchecked (music) }), @@ -115,10 +115,10 @@ macro_rules! yamlette { }}; - ( init ; reader ) => {{ yamlette! ( init ; reader ; {} ) }}; + ( init ; reader ) => {{ $crate::yamlette! ( init ; reader ; {} ) }}; ( init ; reader ; $options:tt ) => {{ - yamlette! ( options ; $options ; options ); + $crate::yamlette! ( options ; $options ; options ); let schema = options.schema.take ().unwrap (); @@ -129,10 +129,10 @@ macro_rules! yamlette { }}; - ( init ; sage ) => {{ yamlette! ( init ; sage ; {} ) }}; + ( init ; sage ) => {{ $crate::yamlette! ( init ; sage ; {} ) }}; ( init ; sage ; $options:tt ) => {{ - yamlette! ( options ; $options ; options ); + $crate::yamlette! ( options ; $options ; options ); let schema = options.schema.take ().unwrap (); @@ -146,10 +146,10 @@ macro_rules! yamlette { } }}; - ( init ; writer ) => {{ yamlette! ( init ; writer ; {} ) }}; + ( init ; writer ) => {{ $crate::yamlette! ( init ; writer ; {} ) }}; ( init ; writer ; $options:tt ) => {{ - yamlette! ( options ; $options ; options ); + $crate::yamlette! ( options ; $options ; options ); match $crate::orchestra::Orchestra::new (options.schema.take ().unwrap ()) { Ok ( orch ) => Ok ( orch ), @@ -161,7 +161,7 @@ macro_rules! yamlette { let mut $var: $crate::face::Options<$crate::model::schema::core::Core> = $crate::face::Options::new (); $( - $var = yamlette! ( option ; $var ; $key ; $val ); + $var = $crate::yamlette! ( option ; $var ; $key ; $val ); )* $var = if $var.schema.is_none () { @@ -182,7 +182,7 @@ macro_rules! yamlette { ( options moveout ; $book:expr ; $result:expr ; { $( $key:ident : $val:ident ),* } ) => { $( - yamlette! ( option moveout ; $book ; $result ; $key ; $val ); + $crate::yamlette! ( option moveout ; $book ; $result ; $key ; $val ); )* }; diff --git a/src/model/renderer.rs b/src/model/renderer.rs index 6df3430..9b5703b 100644 --- a/src/model/renderer.rs +++ b/src/model/renderer.rs @@ -239,209 +239,149 @@ impl Renderer { match *node { Node::Empty => (), - // Node::Indent (size) => { dst_ptr = self.space.copy_to_ptr_times (dst_ptr, size); } Node::Indent(size) => { dst_ptr = copy_to_ptr_times(b' ', dst_ptr, size); } Node::NewlineIndent(size) => { - // dst_ptr = self.newline.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'\n', dst_ptr); - // dst_ptr = self.space.copy_to_ptr_times (dst_ptr, size); dst_ptr = copy_to_ptr_times(b' ', dst_ptr, size); } Node::IndentHyphenSpace(size) => { - // dst_ptr = self.space.copy_to_ptr_times (dst_ptr, size); dst_ptr = copy_to_ptr_times(b' ', dst_ptr, size); - // dst_ptr = self.hyphen.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'-', dst_ptr); - // dst_ptr = self.space.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b' ', dst_ptr); } Node::NewlineIndentHyphenSpace(size) => { - // dst_ptr = self.newline.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'\n', dst_ptr); - // dst_ptr = self.space.copy_to_ptr_times (dst_ptr, size); dst_ptr = copy_to_ptr_times(b' ', dst_ptr, size); - // dst_ptr = self.hyphen.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'-', dst_ptr); - // dst_ptr = self.space.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b' ', dst_ptr); } Node::IndentQuestionSpace(size) => { - // dst_ptr = self.space.copy_to_ptr_times (dst_ptr, size); dst_ptr = copy_to_ptr_times(b' ', dst_ptr, size); - // dst_ptr = self.question.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'?', dst_ptr); - // dst_ptr = self.space.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b' ', dst_ptr); } Node::NewlineIndentQuestionSpace(size) => { - // dst_ptr = self.newline.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'\n', dst_ptr); - // dst_ptr = self.space.copy_to_ptr_times (dst_ptr, size); dst_ptr = copy_to_ptr_times(b' ', dst_ptr, size); - // dst_ptr = self.question.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'?', dst_ptr); - // dst_ptr = self.space.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b' ', dst_ptr); } Node::CommaNewlineIndent(size) => { - // dst_ptr = self.comma.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b',', dst_ptr); - // dst_ptr = self.newline.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'\n', dst_ptr); - // dst_ptr = self.space.copy_to_ptr_times (dst_ptr, size); dst_ptr = copy_to_ptr_times(b' ', dst_ptr, size); } Node::CommaSpace => { - // dst_ptr = self.comma.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b',', dst_ptr); - // dst_ptr = self.space.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b' ', dst_ptr); } Node::ColonSpace => { - // dst_ptr = self.colon.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b':', dst_ptr); - // dst_ptr = self.space.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b' ', dst_ptr); } Node::QuestionNewline => { - // dst_ptr = self.question.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'?', dst_ptr); - // dst_ptr = self.newline.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'\n', dst_ptr); } Node::QuestionNewlineIndent(size) => { - // dst_ptr = self.question.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'?', dst_ptr); - // dst_ptr = self.newline.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'\n', dst_ptr); - // dst_ptr = self.space.copy_to_ptr_times (dst_ptr, size); dst_ptr = copy_to_ptr_times(b' ', dst_ptr, size); } Node::QuestionSpace => { - // dst_ptr = self.question.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'?', dst_ptr); - // dst_ptr = self.space.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b' ', dst_ptr); } Node::ColonNewline => { - // dst_ptr = self.colon.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b':', dst_ptr); - // dst_ptr = self.newline.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'\n', dst_ptr); } Node::ColonNewlineIndent(size) => { - // dst_ptr = self.colon.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b':', dst_ptr); - // dst_ptr = self.newline.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'\n', dst_ptr); - // dst_ptr = self.space.copy_to_ptr_times (dst_ptr, size); dst_ptr = copy_to_ptr_times(b' ', dst_ptr, size); } Node::HyphenSpace => { - // dst_ptr = self.hyphen.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'-', dst_ptr); - // dst_ptr = self.space.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b' ', dst_ptr); } Node::SquareBrackets => { - // dst_ptr = self.square_bracket_open.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'[', dst_ptr); - // dst_ptr = self.square_bracket_close.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b']', dst_ptr); } - // Node::SquareBracketOpen => { dst_ptr = self.square_bracket_open.copy_to_ptr (dst_ptr); } Node::SquareBracketOpen => { dst_ptr = copy_to_ptr(b'[', dst_ptr); } - // Node::SquareBracketClose => { dst_ptr = self.square_bracket_close.copy_to_ptr (dst_ptr); } Node::SquareBracketClose => { dst_ptr = copy_to_ptr(b']', dst_ptr); } Node::CurlyBrackets => { - // dst_ptr = self.curly_bracket_open.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'{', dst_ptr); - // dst_ptr = self.curly_bracket_close.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'}', dst_ptr); } - // Node::CurlyBracketOpen => { dst_ptr = self.curly_bracket_open.copy_to_ptr (dst_ptr); } Node::CurlyBracketOpen => { dst_ptr = copy_to_ptr(b'{', dst_ptr); } - // Node::CurlyBracketClose => { dst_ptr = self.curly_bracket_close.copy_to_ptr (dst_ptr); } Node::CurlyBracketClose => { dst_ptr = copy_to_ptr(b'}', dst_ptr); } - // Node::Hyphen => { dst_ptr = self.hyphen.copy_to_ptr (dst_ptr); } Node::Hyphen => { dst_ptr = copy_to_ptr(b'-', dst_ptr); } - // Node::Dot => { dst_ptr = self.dot.copy_to_ptr (dst_ptr); } Node::Dot => { dst_ptr = copy_to_ptr(b'.', dst_ptr); } - // Node::Question => { dst_ptr = self.question.copy_to_ptr (dst_ptr); } Node::Question => { dst_ptr = copy_to_ptr(b'?', dst_ptr); } - // Node::Comma => { dst_ptr = self.comma.copy_to_ptr (dst_ptr); } Node::Comma => { dst_ptr = copy_to_ptr(b',', dst_ptr); } - // Node::Colon => { dst_ptr = self.colon.copy_to_ptr (dst_ptr); } Node::Colon => { dst_ptr = copy_to_ptr(b':', dst_ptr); } - // Node::Space => { dst_ptr = self.space.copy_to_ptr (dst_ptr); } Node::Space => { dst_ptr = copy_to_ptr(b' ', dst_ptr); } - // Node::Newline => { dst_ptr = self.newline.copy_to_ptr (dst_ptr); } Node::Newline => { dst_ptr = copy_to_ptr(b'\n', dst_ptr); } Node::TripleHyphenNewline => { - // dst_ptr = self.hyphen.copy_to_ptr_times (dst_ptr, 3); dst_ptr = copy_to_ptr_times(b'-', dst_ptr, 3); - // dst_ptr = self.newline.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'\n', dst_ptr); } Node::TripleDotNewline => { - // dst_ptr = self.dot.copy_to_ptr_times (dst_ptr, 3); dst_ptr = copy_to_ptr_times(b'.', dst_ptr, 3); - // dst_ptr = self.newline.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'\n', dst_ptr); } Node::StringSpecificTag(ref vec) => { - // dst_ptr = self.exclamation.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'!', dst_ptr); - // dst_ptr = self.lt.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'<', dst_ptr); let len = vec.len(); ptr::copy_nonoverlapping(vec.as_ptr(), dst_ptr, len); dst_ptr = dst_ptr.offset(len as isize); - // dst_ptr = self.gt.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'>', dst_ptr); } @@ -464,37 +404,30 @@ impl Renderer { let len = s.len(); ptr::copy_nonoverlapping(s.as_ptr(), dst_ptr, len); dst_ptr = dst_ptr.offset(len as isize); - // dst_ptr = self.newline.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'\n', dst_ptr); } Node::SingleQuotedString(ref s) => { - // dst_ptr = self.apostrophe.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'\'', dst_ptr); let len = s.len(); ptr::copy_nonoverlapping(s.as_ptr(), dst_ptr, len); dst_ptr = dst_ptr.offset(len as isize); - // dst_ptr = self.apostrophe.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'\'', dst_ptr); } Node::DoubleQuotedString(ref s) => { - // dst_ptr = self.quotation.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'"', dst_ptr); let len = s.len(); ptr::copy_nonoverlapping(s.as_ptr(), dst_ptr, len); dst_ptr = dst_ptr.offset(len as isize); - // dst_ptr = self.quotation.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'"', dst_ptr); } Node::AmpersandString(ref s) => { - // dst_ptr = self.ampersand.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'&', dst_ptr); let len = s.len(); ptr::copy_nonoverlapping(s.as_ptr(), dst_ptr, len); dst_ptr = dst_ptr.offset(len as isize); } Node::AsteriskString(ref s) => { - // dst_ptr = self.asterisk.copy_to_ptr (dst_ptr); dst_ptr = copy_to_ptr(b'*', dst_ptr); let len = s.len(); ptr::copy_nonoverlapping(s.as_ptr(), dst_ptr, len); diff --git a/src/model/schema/core.rs b/src/model/schema/core.rs index deada1b..55618f0 100644 --- a/src/model/schema/core.rs +++ b/src/model/schema/core.rs @@ -28,7 +28,6 @@ use std::borrow::Cow; use std::clone::Clone; use std::default::Default; -// #[derive (Clone)] pub struct Core { styles: CommonStyles, tag_handles: [(Cow<'static, str>, Cow<'static, str>); 3], diff --git a/src/model/yaml/str.rs b/src/model/yaml/str.rs index bb53f11..cb7838b 100644 --- a/src/model/yaml/str.rs +++ b/src/model/yaml/str.rs @@ -1097,14 +1097,14 @@ pub struct StrValue { impl StrValue { pub fn new( - val: Cow<'static, str>, + value: Cow<'static, str>, styles: CommonStyles, alias: Option>, ) -> StrValue { StrValue { style: if styles.issue_tag() { 1 } else { 0 }, - alias: alias, - value: val, + alias, + value, } } diff --git a/src/model/yamlette/incognitum.rs b/src/model/yamlette/incognitum.rs index eb1b77e..5477d75 100644 --- a/src/model/yamlette/incognitum.rs +++ b/src/model/yamlette/incognitum.rs @@ -121,7 +121,7 @@ impl Model for Incognitum { } } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct IncognitumValue { tag: Option, anchor: Option, @@ -133,7 +133,7 @@ impl IncognitumValue { IncognitumValue { tag: None, anchor: None, - value: value, + value, } } diff --git a/src/orchestra/chord.rs b/src/orchestra/chord.rs index baee221..bda6694 100644 --- a/src/orchestra/chord.rs +++ b/src/orchestra/chord.rs @@ -19,6 +19,8 @@ use crate::model::yaml::seq::SeqValue; use crate::model::yaml::set::SetValue; use crate::model::yaml::str::StrValue; +use crate::model::yamlette::incognitum::IncognitumValue; + use crate::orchestra::{OrchError, Orchestra}; use std::borrow::{Borrow, Cow}; @@ -51,6 +53,27 @@ pub trait Chord { ) -> Result<(), OrchError>; } +impl Chord for IncognitumValue { + fn chord_size(&self) -> usize { + 1 + } + + fn play( + self, + orchestra: &Orchestra, + level: usize, + _alias: Option>, + _cs: CommonStyles, + vs: &mut [&mut dyn Style], + ) -> Result<(), OrchError> { + + let mut val = self.clone(); + apply_styles(&mut val, vs); + + orchestra.play(level, TaggedValue::from(val)) + } +} + impl Chord for EmptyList { fn chord_size(&self) -> usize { 1 diff --git a/tests/examples/composer.rs b/tests/examples/composer.rs index 372edbb..1c55c8b 100644 --- a/tests/examples/composer.rs +++ b/tests/examples/composer.rs @@ -1,41 +1,43 @@ macro_rules! composer { ($src:expr) => {{ - let charset = get_charset_utf8 (); - let (sender, receiver) = channel (); + let charset = get_charset_utf8(); + let (sender, receiver) = channel(); - let composer = Composer::new (&charset, receiver, build_complete_schema ()); - let mut reader = Reader::new (SliceReader::new ($src.as_bytes ()), Tokenizer::new (charset), sender); + let composer = Composer::new(&charset, receiver, build_complete_schema()); + let mut reader = Reader::new( + SliceReader::new($src.as_bytes()), + Tokenizer::new(charset), + sender, + ); - reader.read ().unwrap_or_else (|err| { assert! (false, "Unexpected result: {}, :{}", err, err.position); }); + reader.read().unwrap_or_else(|err| { + assert!(false, "Unexpected result: {}, :{}", err, err.position); + }); - let composer = composer.unwrap (); + let composer = composer.unwrap(); composer - }} + }}; } - - - macro_rules! wait { ($composer:expr) => {{ - let result = $composer.join (); - assert! (result.is_ok ()); // check the thread didn't panic + let result = $composer.join(); + assert!(result.is_ok()); // check the thread didn't panic - let result = result.unwrap (); - if let Err (ref err) = result { println! ("Composing error: {:?}", err); } + let result = result.unwrap(); + if let Err(ref err) = result { + println!("Composing error: {:?}", err); + } - assert! (result.is_ok ()); // documents have been built + assert!(result.is_ok()); // documents have been built - let book = result.ok ().unwrap (); + let book = result.ok().unwrap(); book - }} + }}; } - - - macro_rules! chapter { ($book:expr, $chapter_idx:expr, collection, seq, $collection_len:expr) => {{ if let Some (chapter) = $book.get_chapter ($chapter_idx) { @@ -54,9 +56,6 @@ macro_rules! chapter { }} } - - - macro_rules! book { ($book:expr, chapter = $chapter:expr, children = $children:expr, children_cnt = $children_cnt:expr, value = ($tag:expr => $value:expr)) => {{ @@ -75,30 +74,10 @@ macro_rules! book { $children_cnt += 1; }}; - -/* - ($book:expr, chapter = $chapter:expr, children = $children:expr, children_cnt = $children_cnt:expr, value = (($tag1:expr => $val1:expr), ($tag2:expr => $value2:expr))) => {{ - if let Some (children_index) = $children.get ($children_cnt) { - - - - if let Some ( &(_, Node::Scalar ("tag:yaml.org,2002:str", Scalar::Str (ref string))) ) = $chapter.get_node_by_index (*children_index) { - assert_eq! (string, $value); - } else { assert! (false, "cannot extract a child. Expected !str, got {:?}", $chapter.get_node_by_index (*children_index)) } - } else { assert! (false, "not enough children") } - - $children_cnt += 1; - }}; -*/ - - - ($book:expr, chapter = $chapter:expr, children = $children:expr, children_cnt = $children_cnt:expr, value = [$($value:tt),*]) => {{ $(book! ($book, chapter = $chapter, children = $children, children_cnt = $children_cnt, value = $value);)* }}; - - ($book:expr, chapter = $chapter:expr, chapter_tree = ($tag:expr => $value:tt)) => {{ match $tag { "tag:yaml.org,2002:seq" => { @@ -110,17 +89,6 @@ macro_rules! book { assert_eq! (children_cnt, children.len ()); } else { assert! (false, "Incorrect root node of the chapter") } } -/* - "tag:yaml.org,2002:map" => { - if let Some ( &(_, Node::Collection ("tag:yaml.org,2002:map", Collection::Map (ref children))) ) = $chapter.get_root_node () { - let mut children_cnt = 0; - - book! ($book, chapter = $chapter, children = children, children_cnt = children_cnt, value = $value); - - assert_eq! (children_cnt, children.len ()); - } else { assert! (false, "Incorrect root node of the chapter") } - } -*/ _ => assert! (false, "Unimplemented tag type for a chapter '{}'", $tag) } @@ -143,10 +111,7 @@ macro_rules! book { }}; } - - - -#[cfg (test)] +#[cfg(test)] mod stable { extern crate fraction; extern crate skimmer; @@ -156,28 +121,25 @@ mod stable { use self::skimmer::reader::SliceReader; - use self::yamlette::txt::get_charset_utf8; - use self::yamlette::tokenizer::Tokenizer; - use self::yamlette::reader::Reader; - use self::yamlette::composer::Composer; use self::yamlette::book::Node; - use self::yamlette::schema::{ Collection, Scalar }; + use self::yamlette::composer::Composer; + use self::yamlette::reader::Reader; + use self::yamlette::schema::{Collection, Scalar}; + use self::yamlette::tokenizer::Tokenizer; + use self::yamlette::txt::get_charset_utf8; use self::yamlette::schema::build_complete_schema; use std::sync::mpsc::channel; - - #[test] - fn example_2_01 () { - let src = -r"- Mark McGwire + fn example_2_01() { + let src = r"- Mark McGwire - Sammy Sosa - Ken Griffey"; - let composer = composer! (src); - let book = wait! (composer); + let composer = composer!(src); + let book = wait!(composer); book! ( &book, ("tag:yaml.org,2002:seq" => [ @@ -188,26 +150,25 @@ r"- Mark McGwire ) } - -/* - #[test] - fn example_2_02 () { - let src = -r"hr: 65 # Home runs -avg: 0.278 # Batting average -rbi: 147 # Runs Batted In"; - - let composer = composer! (src); - let book = wait! (composer); - - - book! ( &book, - ("tag:yaml.org,2002:map", [ - (("tag:yaml.org,2002:str" => "hr"), ("tag:yaml.org,2002:int" => 65)), - (("tag:yaml.org,2002:str" => "avg"), ("tag:yaml.org,2002:float" => Fraction::new (278, 1000))), - (("tag:yaml.org,2002:str" => "rbi"), ("tag:yaml.org,2002:int" => 147)) - ]) - ) - } -*/ + /* + #[test] + fn example_2_02 () { + let src = + r"hr: 65 # Home runs + avg: 0.278 # Batting average + rbi: 147 # Runs Batted In"; + + let composer = composer! (src); + let book = wait! (composer); + + + book! ( &book, + ("tag:yaml.org,2002:map", [ + (("tag:yaml.org,2002:str" => "hr"), ("tag:yaml.org,2002:int" => 65)), + (("tag:yaml.org,2002:str" => "avg"), ("tag:yaml.org,2002:float" => Fraction::new (278, 1000))), + (("tag:yaml.org,2002:str" => "rbi"), ("tag:yaml.org,2002:int" => 147)) + ]) + ) + } + */ } diff --git a/tests/examples/face.rs b/tests/examples/face.rs index 78b070c..452a8dc 100644 --- a/tests/examples/face.rs +++ b/tests/examples/face.rs @@ -1,33 +1,34 @@ -#[cfg (all (test, not (feature = "dev")))] +#[cfg(test)] mod stable { extern crate yamlette; #[test] - fn example_extra_yaml_rust () { - let should_be = Some (r#"foo: + fn example_extra_yaml_rust() { + let should_be = Some( + r#"foo: - list1 - list2 bar: - 1 - - 2.0"#); + - 2.0"#, + ); yamlette! ( read ; should_be.as_ref ().unwrap ().clone () ; [[ { "foo" => [ (list1:&str), (list2:&str) ], "bar" => [ (unu:u8), (dua:f32) ] } ]] ; { book: book, result: result } ); - assert! (result.is_ok ()); - assert_eq! (1, book.volumes.len ()); + assert!(result.is_ok()); + assert_eq!(1, book.volumes.len()); - assert_eq! (list1, Some ("list1")); - assert_eq! (list2, Some ("list2")); - assert_eq! (unu, Some (1u8)); - assert_eq! (dua, Some (2.0)); + assert_eq!(list1, Some("list1")); + assert_eq!(list2, Some("list2")); + assert_eq!(unu, Some(1u8)); + assert_eq!(dua, Some(2.0)); } - #[test] - fn example_extra_yaml_rust_lazy () { + fn example_extra_yaml_rust_lazy() { let should_be = r#"foo: - list1 - list2 @@ -42,152 +43,134 @@ bar: "bar" => [ (unu:u8), (dua:f32) ] } ]] ; {} ); - assert_eq! (list1, Some ("list1")); - assert_eq! (list2, Some ("list2")); - assert_eq! (unu, Some (1u8)); - assert_eq! (dua, Some (2.0)); + assert_eq!(list1, Some("list1")); + assert_eq!(list2, Some("list2")); + assert_eq!(unu, Some(1u8)); + assert_eq!(dua, Some(2.0)); yamlette! ( read ; warm ; &mut payload ; should_be ; [[ { "foo" => [ (two_list1:&str), (two_list2:&str) ], "bar" => [ (two_unu:u8), (two_dua:f32) ] } ]] ; {} ); - assert_eq! (two_list1, Some ("list1")); - assert_eq! (two_list2, Some ("list2")); - assert_eq! (two_unu, Some (1u8)); - assert_eq! (two_dua, Some (2.0)); + assert_eq!(two_list1, Some("list1")); + assert_eq!(two_list2, Some("list2")); + assert_eq!(two_unu, Some(1u8)); + assert_eq!(two_dua, Some(2.0)); } #[test] - fn example_02_01_block () { - let should_be = - Some (r#"- Mark McGwire + fn example_02_01_block() { + let should_be = Some( + r#"- Mark McGwire - Sammy Sosa - Ken Griffey -"#); +"#, + ); yamlette! ( read ; should_be.as_ref ().unwrap ().clone () ; [[ [ (mark:&str), (sammy:&str), (ken:&str) ] ]] ; { book: book, result: result } ); - assert! (result.is_ok ()); - assert_eq! (1, book.volumes.len ()); + assert!(result.is_ok()); + assert_eq!(1, book.volumes.len()); - assert_eq! (mark, Some ("Mark McGwire")); - assert_eq! (sammy, Some ("Sammy Sosa")); - assert_eq! (ken, Some ("Ken Griffey")); + assert_eq!(mark, Some("Mark McGwire")); + assert_eq!(sammy, Some("Sammy Sosa")); + assert_eq!(ken, Some("Ken Griffey")); let result = yamlette! ( write ; [[ [ (mark.unwrap ().to_string ()), (sammy.unwrap ().to_string ()), (ken.unwrap ().to_string ()) ] ]] ).ok (); - assert_eq! (should_be.map (|b| b.to_string ()), result); + assert_eq!(should_be.map(|b| b.to_string()), result); } - #[test] - fn example_02_01_block_sage () { - let should_be = - Some (r#"- Mark McGwire + fn example_02_01_block_sage() { + let should_be = Some( + r#"- Mark McGwire - Sammy Sosa - Ken Griffey -"#); +"#, + ); yamlette! ( sage ; should_be.as_ref ().unwrap ().clone () ; [[ [ (mark:&str), (sammy:&str), (ken:&str) ] ]] ; { book: book, result: result } ); - assert! (result.is_ok ()); - assert_eq! (1, book.volumes.len ()); + assert!(result.is_ok()); + assert_eq!(1, book.volumes.len()); - assert_eq! (mark, Some ("Mark McGwire")); - assert_eq! (sammy, Some ("Sammy Sosa")); - assert_eq! (ken, Some ("Ken Griffey")); + assert_eq!(mark, Some("Mark McGwire")); + assert_eq!(sammy, Some("Sammy Sosa")); + assert_eq!(ken, Some("Ken Griffey")); let result = yamlette! ( write ; [[ [ (mark.unwrap ().to_string ()), (sammy.unwrap ().to_string ()), (ken.unwrap ().to_string ()) ] ]] ).ok (); - assert_eq! (should_be.map (|b| b.to_string ()), result); + assert_eq!(should_be.map(|b| b.to_string()), result); } - #[test] - fn example_02_01_block_ignore_result () { - let should_be = - Some (r#"- Mark McGwire + fn example_02_01_block_ignore_result() { + let should_be = Some( + r#"- Mark McGwire - Sammy Sosa - Ken Griffey -"#); +"#, + ); yamlette! ( read ; should_be.as_ref ().unwrap ().clone () ; [[ [ (mark:&str), (sammy:&str), (ken:&str) ] ]] ); - assert_eq! (mark, Some ("Mark McGwire")); - assert_eq! (sammy, Some ("Sammy Sosa")); - assert_eq! (ken, Some ("Ken Griffey")); + assert_eq!(mark, Some("Mark McGwire")); + assert_eq!(sammy, Some("Sammy Sosa")); + assert_eq!(ken, Some("Ken Griffey")); let result = yamlette! ( write ; [[ [ (mark.unwrap ().to_string ()), (sammy.unwrap ().to_string ()), (ken.unwrap ().to_string ()) ] ]] ).ok (); - assert_eq! (should_be.map (|b| b.to_string ()), result); + assert_eq!(should_be.map(|b| b.to_string()), result); } - #[test] - fn example_02_01_block_ignore_result_sage () { - let should_be = - Some (r#"- Mark McGwire + fn example_02_01_block_ignore_result_sage() { + let should_be = Some( + r#"- Mark McGwire - Sammy Sosa - Ken Griffey -"#); +"#, + ); yamlette! ( sage ; should_be.as_ref ().unwrap ().clone () ; [[ [ (mark:&str), (sammy:&str), (ken:&str) ] ]] ); - assert_eq! (mark, Some ("Mark McGwire")); - assert_eq! (sammy, Some ("Sammy Sosa")); - assert_eq! (ken, Some ("Ken Griffey")); + assert_eq!(mark, Some("Mark McGwire")); + assert_eq!(sammy, Some("Sammy Sosa")); + assert_eq!(ken, Some("Ken Griffey")); let result = yamlette! ( write ; [[ [ (mark.unwrap ().to_string ()), (sammy.unwrap ().to_string ()), (ken.unwrap ().to_string ()) ] ]] ).ok (); - assert_eq! (should_be.map (|b| b.to_string ()), result); + assert_eq!(should_be.map(|b| b.to_string()), result); } - -/* #[test] - fn example_02_01_block_custom_charset () { - let should_be = - Some (r#"- Mark McGwire + fn example_02_01_block_custom_schema() { + let should_be = Some( + r#"- Mark McGwire - Sammy Sosa - Ken Griffey -"#.to_string ()); +"#, + ); - let result = yamlette! ( write ; [[ [ "Mark McGwire", "Sammy Sosa", "Ken Griffey" ] ]] ; { charset: yamlette::txt::get_charset_utf8 () } ).ok (); + let schema = yamlette::model::schema::core::Core::new(); + let result = yamlette! ( write ; [[ [ "Mark McGwire", "Sammy Sosa", "Ken Griffey" ] ]] ; { schema: schema } ).ok (); - assert_eq! (should_be, result); + assert_eq!(should_be.map(|b| b.to_string()), result); } -*/ - -/* #[test] - fn example_02_01_block_custom_encoding () { - let should_be = - Some (r#"- Mark McGwire -- Sammy Sosa -- Ken Griffey -"#.to_string ()); + fn custom_00_tagged_incognitum() { + let should_be = Some("- ! Value\n"); - let result = yamlette! ( write ; [[ [ "Mark McGwire", "Sammy Sosa", "Ken Griffey" ] ]] ; { encoding: UTF8 } ).ok (); + let value = + yamlette::model::yamlette::incognitum::IncognitumValue::new(String::from("Value")) + .set_tag(String::from("env")); - assert_eq! (should_be, result); - } -*/ - - - #[test] - fn example_02_01_block_custom_schema () { - let should_be = - Some (r#"- Mark McGwire -- Sammy Sosa -- Ken Griffey -"#); - - // let cset = yamlette::txt::charset::get_charset_utf8 (); - let schema = yamlette::model::schema::core::Core::new (); - let result = yamlette! ( write ; [[ [ "Mark McGwire", "Sammy Sosa", "Ken Griffey" ] ]] ; { schema: schema } ).ok (); + let schema = yamlette::model::schema::core::Core::new(); + let result = yamlette! ( write ; [[ [ value ] ]] ; { schema: schema } ).ok(); - assert_eq! (should_be.map (|b| b.to_string ()), result); + assert_eq!(should_be.map(|b| b.to_string()), result); } }