Skip to content

Commit

Permalink
chore: Apply fmt/tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vldm committed Jan 8, 2024
1 parent 5169819 commit 8c683c1
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
10 changes: 6 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<TokenStream>>;
pub type ElementWildcardFn = dyn Fn(&OpenTag, &CloseTag) -> bool;
Expand Down Expand Up @@ -251,12 +251,12 @@ impl<C> ParserConfig<C> {
/// Example:
///
/// Imagine one have macro, that used like this:
/// ```
/// ```no_compile
/// html! {some_context, provided, [ can use groups, etc], {<div>}, [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 */],
Expand All @@ -265,6 +265,8 @@ impl<C> ParserConfig<C> {
/// }))
/// ```
///
/// 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
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 4 additions & 5 deletions src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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<convert::Infallible> for Infallible {
fn from(s: convert::Infallible) -> Self {
Expand All @@ -289,7 +288,7 @@ impl ParseRecoverable for Infallible {
}
}
impl CustomNode for Infallible {
fn peek_element( _: ParseStream) -> bool {
fn peek_element(_: ParseStream) -> bool {
false
}
}
}
5 changes: 4 additions & 1 deletion src/rawtext_stable_hack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ pub fn inject_raw_text_default<C: CustomNode>(source: &mut [Node<C>]) {

// Inject raw text to every raw node, recovered using proc-macro2 second
// parsing;
pub fn inject_raw_text<C: CustomNode + std::fmt::Debug>(source: &mut [Node<C>], hacked: &[Node<C>]) {
pub fn inject_raw_text<C: CustomNode + std::fmt::Debug>(
source: &mut [Node<C>],
hacked: &[Node<C>],
) {
assert_eq!(
source.len(),
hacked.len(),
Expand Down
2 changes: 1 addition & 1 deletion tests/custom_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
4 changes: 1 addition & 3 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rstml::{
CustomNode, KeyedAttribute, KeyedAttributeValue, Node, NodeAttribute, NodeElement, NodeType,
},
parse2,
recoverable::{RecoverableContext, ParseRecoverable},
recoverable::{ParseRecoverable, RecoverableContext},
Parser, ParserConfig,
};
use syn::{
Expand Down Expand Up @@ -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))
Expand All @@ -190,7 +189,6 @@ impl CustomNode for TestCustomNode {
fn peek_element(input: ParseStream) -> bool {
input.peek(Bracket)
}

}

macro_rules! test_unquoted {
Expand Down

0 comments on commit 8c683c1

Please sign in to comment.