Struct syn_rsx::ParserConfig

source ·
pub struct ParserConfig { /* private fields */ }
Expand description

Configures the Parser behavior

Implementations

Create new ParserConfig with default config

Return flat tree instead of nested tree

Exact number of required top level nodes

Enforce the NodeType of top level nodes

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, meaning no tokens can be left in the stream.

If None is returned, parsing happens with the original ParseStream, since the tokens that are passend into the transform callback are a fork, which gets only advanced if Some is returned.

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

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.