Struct syn_rsx::ParserConfig
source · [−]pub struct ParserConfig { /* private fields */ }
Expand description
Configures the Parser
behavior
Implementations
sourceimpl ParserConfig
impl ParserConfig
sourcepub fn new() -> ParserConfig
pub fn new() -> ParserConfig
Create new ParserConfig
with default config
sourcepub fn number_of_top_level_nodes(self, number: usize) -> Self
pub fn number_of_top_level_nodes(self, number: usize) -> Self
Exact number of required top level nodes
sourcepub fn type_of_top_level_nodes(self, node_type: NodeType) -> Self
pub fn type_of_top_level_nodes(self, node_type: NodeType) -> Self
Enforce the NodeType
of top level nodes
sourcepub fn transform_block<F>(self, callback: F) -> Self where
F: Fn(ParseStream<'_>) -> Result<Option<TokenStream>> + 'static,
pub fn transform_block<F>(self, callback: F) -> Self where
F: Fn(ParseStream<'_>) -> Result<Option<TokenStream>> + 'static,
Transforms the value
of all NodeType::Block
s with the given closure
callback. The provided ParseStream
is the content of the block.
When Some(TokenStream)
is returned, the TokenStream
is parsed as
Rust block content. The ParseStream
must be completely consumed in
this case (no tokens left).
If None
is returned, the ParseStream
is parsed as Rust block
content. The ParseStream
isn’t forked, so partial parsing inside the
transform callback will break this mechanism - fork if you want to avoid
breaking.
An example usage might be a custom syntax inside blocks which isn’t
valid Rust. The given example simply translates the %
character into
the string percent
use quote::quote;
use syn::Token;
use syn_rsx::{parse2_with_config, ParserConfig};
let tokens = quote! {
<div>{%}</div>
};
let config = ParserConfig::new().transform_block(|input| {
input.parse::<Token![%]>()?;
Ok(Some(quote! { "percent" }))
});
parse2_with_config(tokens, config).unwrap();
Trait Implementations
sourceimpl Default for ParserConfig
impl Default for ParserConfig
sourcefn default() -> ParserConfig
fn default() -> ParserConfig
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl !RefUnwindSafe for ParserConfig
impl !Send for ParserConfig
impl !Sync for ParserConfig
impl Unpin for ParserConfig
impl !UnwindSafe for ParserConfig
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more