diff --git a/src/config.rs b/src/config.rs index 492d2e9..6e92e10 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,8 +8,8 @@ use crate::rawtext_stable_hack::MacroPattern; use crate::{ atoms::{CloseTag, OpenTag}, node::{CustomNode, NodeType}, + Infallible, }; -use crate::Infallible; pub type TransformBlockFn = dyn Fn(ParseStream) -> Result>; pub type ElementWildcardFn = dyn Fn(&OpenTag, &CloseTag) -> bool; @@ -251,12 +251,12 @@ impl ParserConfig { /// Example: /// /// Imagine one have macro, that used like this: - /// ``` + /// ```no_compile /// html! {some_context, provided, [ can use groups, etc], {
}, [other context]}; /// ``` /// - /// One can set `macro_call_pattern` like this: - /// ``` + /// Then one can set `macro_call_pattern` with following arguments: + /// ```no_compile /// config.macro_call_pattern(quote!(html! // macro name currently is not checked /// {ident, ident, // can use real idents, or any other /// [/* can ignore context of auxilary groups */], @@ -265,6 +265,8 @@ impl ParserConfig { /// })) /// ``` /// + /// And rstml will do the rest for you. + /// /// Panics if no `%%` token was found. /// /// If macro_call_patern is set rstml will parse input two times in order to diff --git a/src/lib.rs b/src/lib.rs index b8a8d92..a748dd1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -237,9 +237,8 @@ pub mod rawtext_stable_hack; pub mod visitor; pub use config::ParserConfig; pub use error::Error; -pub use node::atoms; +pub use node::{atoms, Infallible}; use node::{CustomNode, Node}; -pub use node::Infallible; pub use parser::{recoverable, recoverable::ParsingResult, Parser}; /// Parse the given [`proc-macro::TokenStream`] into a [`Node`] tree. diff --git a/src/node/mod.rs b/src/node/mod.rs index a062657..89738ff 100644 --- a/src/node/mod.rs +++ b/src/node/mod.rs @@ -22,7 +22,7 @@ pub use node_name::{NodeName, NodeNameFragment}; pub use node_value::{InvalidBlock, NodeBlock}; pub use self::raw_text::RawText; -use crate::recoverable::{RecoverableContext, ParseRecoverable}; +use crate::recoverable::{ParseRecoverable, RecoverableContext}; /// Node types. #[derive(Debug, Clone, PartialEq, Eq)] @@ -264,14 +264,13 @@ pub trait CustomNode: ParseRecoverable + ToTokens { /// Recieves a [`ParseStream::fork`]. /// /// [`ParseStream::fork`]: syn::parse::ParseBuffer::fork - /// fn peek_element(input: ParseStream) -> bool; } /// Newtype for `std::convert::Infallible` used to implement /// `ToTokens`` for `Infallible``. #[derive(Clone, Copy, Debug, Eq, PartialEq)] -pub struct Infallible (convert::Infallible); +pub struct Infallible(convert::Infallible); impl From for Infallible { fn from(s: convert::Infallible) -> Self { @@ -289,7 +288,7 @@ impl ParseRecoverable for Infallible { } } impl CustomNode for Infallible { - fn peek_element( _: ParseStream) -> bool { + fn peek_element(_: ParseStream) -> bool { false } -} \ No newline at end of file +} diff --git a/src/rawtext_stable_hack.rs b/src/rawtext_stable_hack.rs index 1347eb7..0586c74 100644 --- a/src/rawtext_stable_hack.rs +++ b/src/rawtext_stable_hack.rs @@ -32,7 +32,10 @@ pub fn inject_raw_text_default(source: &mut [Node]) { // Inject raw text to every raw node, recovered using proc-macro2 second // parsing; -pub fn inject_raw_text(source: &mut [Node], hacked: &[Node]) { +pub fn inject_raw_text( + source: &mut [Node], + hacked: &[Node], +) { assert_eq!( source.len(), hacked.len(), diff --git a/tests/custom_node.rs b/tests/custom_node.rs index 6f2936c..26eb4bf 100644 --- a/tests/custom_node.rs +++ b/tests/custom_node.rs @@ -2,7 +2,7 @@ use quote::{quote, TokenStreamExt}; use rstml::{ atoms::{self, OpenTag, OpenTagEnd}, node::{CustomNode, Node, NodeElement}, - recoverable::{Recoverable, ParseRecoverable}, + recoverable::{ParseRecoverable, Recoverable}, Parser, ParserConfig, }; use syn::{parse_quote, Expr, Token}; diff --git a/tests/test.rs b/tests/test.rs index 8960dd9..a1bac74 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -8,7 +8,7 @@ use rstml::{ CustomNode, KeyedAttribute, KeyedAttributeValue, Node, NodeAttribute, NodeElement, NodeType, }, parse2, - recoverable::{RecoverableContext, ParseRecoverable}, + recoverable::{ParseRecoverable, RecoverableContext}, Parser, ParserConfig, }; use syn::{ @@ -165,7 +165,6 @@ struct TestCustomNode { data: TokenStream, } - impl ToTokens for TestCustomNode { fn to_tokens(&self, tokens: &mut TokenStream) { self.bracket.surround(tokens, |c| self.data.to_tokens(c)) @@ -190,7 +189,6 @@ impl CustomNode for TestCustomNode { fn peek_element(input: ParseStream) -> bool { input.peek(Bracket) } - } macro_rules! test_unquoted {