Skip to content

Commit 24c3d64

Browse files
committed
chore: Apply fmt/tests
1 parent b6813be commit 24c3d64

File tree

9 files changed

+27
-32
lines changed

9 files changed

+27
-32
lines changed

rstml-controll-flow/Cargo.toml

+2-5
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,11 @@ proc-macro2 = "1.0.47"
1010
quote = "1.0.21"
1111
syn = "2.0.15"
1212
syn_derive = "0.1"
13-
rstml = { version = "0.11.0", path = "../", features = [
14-
"rawtext-stable-hack",
15-
] }
13+
rstml = { version = "0.11.0", path = "../", features = ["rawtext-stable-hack"] }
1614
proc-macro2-diagnostics = "0.10"
1715
derive-where = "1.2.5"
1816

1917
[features]
20-
default = ["extendable"]
18+
default = []
2119
# If feature activated Node should be parsed through `ExtendableCustomNode::parse2_with_config`
2220
extendable = []
23-

src/config.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use crate::rawtext_stable_hack::MacroPattern;
88
use crate::{
99
atoms::{CloseTag, OpenTag},
1010
node::{CustomNode, NodeType},
11+
Infallible,
1112
};
12-
use crate::Infallible;
1313

1414
pub type TransformBlockFn = dyn Fn(ParseStream) -> Result<Option<TokenStream>>;
1515
pub type ElementWildcardFn = dyn Fn(&OpenTag, &CloseTag) -> bool;
@@ -251,12 +251,12 @@ impl<C> ParserConfig<C> {
251251
/// Example:
252252
///
253253
/// Imagine one have macro, that used like this:
254-
/// ```
254+
/// ```no_compile
255255
/// html! {some_context, provided, [ can use groups, etc], {<div>}, [other context]};
256256
/// ```
257257
///
258-
/// One can set `macro_call_pattern` like this:
259-
/// ```
258+
/// Then one can set `macro_call_pattern` with following arguments:
259+
/// ```no_compile
260260
/// config.macro_call_pattern(quote!(html! // macro name currently is not checked
261261
/// {ident, ident, // can use real idents, or any other
262262
/// [/* can ignore context of auxilary groups */],
@@ -265,6 +265,8 @@ impl<C> ParserConfig<C> {
265265
/// }))
266266
/// ```
267267
///
268+
/// And rstml will do the rest for you.
269+
///
268270
/// Panics if no `%%` token was found.
269271
///
270272
/// If macro_call_patern is set rstml will parse input two times in order to

src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,8 @@ pub mod rawtext_stable_hack;
237237
pub mod visitor;
238238
pub use config::ParserConfig;
239239
pub use error::Error;
240-
pub use node::atoms;
240+
pub use node::{atoms, Infallible};
241241
use node::{CustomNode, Node};
242-
pub use node::Infallible;
243242
pub use parser::{recoverable, recoverable::ParsingResult, Parser};
244243

245244
/// Parse the given [`proc-macro::TokenStream`] into a [`Node`] tree.

src/node/mod.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub use node_name::{NodeName, NodeNameFragment};
2222
pub use node_value::{InvalidBlock, NodeBlock};
2323

2424
pub use self::raw_text::RawText;
25-
use crate::recoverable::{RecoverableContext, ParseRecoverable};
25+
use crate::recoverable::{ParseRecoverable, RecoverableContext};
2626

2727
/// Node types.
2828
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -264,14 +264,13 @@ pub trait CustomNode: ParseRecoverable + ToTokens {
264264
/// Recieves a [`ParseStream::fork`].
265265
///
266266
/// [`ParseStream::fork`]: syn::parse::ParseBuffer::fork
267-
///
268267
fn peek_element(input: ParseStream) -> bool;
269268
}
270269

271270
/// Newtype for `std::convert::Infallible` used to implement
272271
/// `ToTokens`` for `Infallible``.
273272
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
274-
pub struct Infallible (convert::Infallible);
273+
pub struct Infallible(convert::Infallible);
275274

276275
impl From<convert::Infallible> for Infallible {
277276
fn from(s: convert::Infallible) -> Self {
@@ -289,7 +288,7 @@ impl ParseRecoverable for Infallible {
289288
}
290289
}
291290
impl CustomNode for Infallible {
292-
fn peek_element( _: ParseStream) -> bool {
291+
fn peek_element(_: ParseStream) -> bool {
293292
false
294293
}
295-
}
294+
}

src/parser/mod.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,10 @@ impl<C: CustomNode + std::fmt::Debug> Parser<C> {
4949
let parser = move |input: ParseStream| Ok(self.parse_syn_stream(input));
5050
let source = parser.parse2(v.into()).expect("No errors from parser");
5151

52-
#[cfg(not(feature = "rawtext-stable-hack"))]
53-
{
54-
return source;
55-
}
56-
// re-parse using proc_macro2::fallback, only if output without error
5752
#[cfg(feature = "rawtext-stable-hack")]
58-
Self::reparse_raw_text(&self, parser, source)
53+
// re-parse using proc_macro2::fallback, only if output without error
54+
let source = Self::reparse_raw_text(&self, parser, source);
55+
source
5956
}
6057
#[cfg(feature = "rawtext-stable-hack")]
6158
fn reparse_raw_text<Parser>(

src/parser/recoverable.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,11 @@ impl RecoverableContext {
180180
/// [`proc_macro2_diagnostics::Diagnostic`]
181181
pub fn push_diagnostic(&mut self, diagnostic: impl Into<Diagnostic>) {
182182
let diag = diagnostic.into();
183-
println!(
184-
"Push diagnostic: {:?}, backtrace={}",
185-
diag,
186-
std::backtrace::Backtrace::capture()
187-
);
183+
// println!(
184+
// "Push diagnostic: {:?}, backtrace={}",
185+
// diag,
186+
// std::backtrace::Backtrace::capture()
187+
// );
188188
self.diagnostics.push(diag);
189189
}
190190
}

src/rawtext_stable_hack.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ pub fn inject_raw_text_default<C: CustomNode>(source: &mut [Node<C>]) {
3232

3333
// Inject raw text to every raw node, recovered using proc-macro2 second
3434
// parsing;
35-
pub fn inject_raw_text<C: CustomNode + std::fmt::Debug>(source: &mut [Node<C>], hacked: &[Node<C>]) {
35+
pub fn inject_raw_text<C: CustomNode + std::fmt::Debug>(
36+
source: &mut [Node<C>],
37+
hacked: &[Node<C>],
38+
) {
3639
assert_eq!(
3740
source.len(),
3841
hacked.len(),

tests/custom_node.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use quote::{quote, TokenStreamExt};
22
use rstml::{
33
atoms::{self, OpenTag, OpenTagEnd},
44
node::{CustomNode, Node, NodeElement},
5-
recoverable::{Recoverable, ParseRecoverable},
5+
recoverable::{ParseRecoverable, Recoverable},
66
Parser, ParserConfig,
77
};
88
use syn::{parse_quote, Expr, Token};

tests/test.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rstml::{
99
NodeName, NodeType,
1010
},
1111
parse2,
12-
recoverable::{RecoverableContext, ParseRecoverable},
12+
recoverable::{ParseRecoverable, RecoverableContext},
1313
Parser, ParserConfig,
1414
};
1515
use syn::{
@@ -166,7 +166,6 @@ struct TestCustomNode {
166166
data: TokenStream,
167167
}
168168

169-
170169
impl ToTokens for TestCustomNode {
171170
fn to_tokens(&self, tokens: &mut TokenStream) {
172171
self.bracket.surround(tokens, |c| self.data.to_tokens(c))
@@ -191,7 +190,6 @@ impl CustomNode for TestCustomNode {
191190
fn peek_element(input: ParseStream) -> bool {
192191
input.peek(Bracket)
193192
}
194-
195193
}
196194

197195
macro_rules! test_unquoted {

0 commit comments

Comments
 (0)