[][src]Struct syn_rsx::ParserConfig

pub struct ParserConfig { /* fields omitted */ }

Configures the Parser behavior

Implementations

impl ParserConfig[src]

pub fn new() -> ParserConfig[src]

Create new ParserConfig with default config

pub fn flat_tree(self) -> Self[src]

Return flat tree instead of nested tree

pub fn number_of_top_level_nodes(self, number: usize) -> Self[src]

Exact number of required top level nodes

pub fn type_of_top_level_nodes(self, node_type: NodeType) -> Self[src]

Enforce the NodeType of top level nodes

pub fn transform_block<F>(self, callback: F) -> Self where
    F: Fn(ParseStream<'_>) -> Result<Option<TokenStream>> + 'static, 
[src]

Transforms the value of all NodeType::Blocks 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

impl Default for ParserConfig[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.