Struct rstml::ParserConfig
source · pub struct ParserConfig<C = Infallible> { /* private fields */ }
Expand description
Configures the Parser
behavior
Implementations§
source§impl ParserConfig
impl ParserConfig
sourcepub fn new() -> ParserConfig
pub fn new() -> ParserConfig
Create new ParserConfig
with default config
source§impl<C> ParserConfig<C>
impl<C> ParserConfig<C>
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 recover_block(self, recover_block: bool) -> Self
pub fn recover_block(self, recover_block: bool) -> Self
Try to parse invalid syn::Block
.
If set tot true, NodeBlock
can return Invalid
variant.
If NodeBlock
is failed to parse as syn::Block
it still usefull to emit it as expression.
It will enhance IDE compatibility, and provide completion in cases of
invalid blocks, for example {x.}
is invalid expression, because
after dot token }
is unexpected. But for ide it is a marker that
quick completion should be provided.
sourcepub fn always_self_closed_elements(
self,
elements: HashSet<&'static str>,
) -> Self
pub fn always_self_closed_elements( self, elements: HashSet<&'static str>, ) -> Self
Set array of nodes that is known to be self closed, it also known as void element. Void elements has no child and must not have closing tag. Parser will not search for it closing tag, even if no slash at end of it open part was found.
Because we work in proc-macro context, we expect it as ’static refs.
Examples:
sourcepub fn raw_text_elements(self, elements: HashSet<&'static str>) -> Self
pub fn raw_text_elements(self, elements: HashSet<&'static str>) -> Self
Set array of nodes that is known to be parsed in two-phases, Parser will skip parsing of children nodes. and provide one child with RawText instead.
This is usefull when parsing <script>
or <style>
tags elements.
If you need fragment to be used in this context, empty string(“”) should be inserted.
Raw texts has few limitations, check out RawText
documentation.
sourcepub fn transform_block<F>(self, callback: F) -> Self
pub fn transform_block<F>(self, callback: F) -> Self
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, 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 rstml::{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();
sourcepub fn element_close_wildcard<F>(self, predicate: F) -> Self
pub fn element_close_wildcard<F>(self, predicate: F) -> Self
Allows unmatched tag pairs where close tag matches a specified wildcard.
For example:
use quote::quote;
use rstml::{
node::{Node, NodeElement},
Parser, ParserConfig,
};
use syn::{Expr, ExprRange, RangeLimits, Stmt};
let config = ParserConfig::new()
.element_close_wildcard(|_open_tag, close_tag| close_tag.name.is_wildcard());
let tokens = quote! {
<{"OpenTag"}>{"Content"}</_>
};
Parser::new(config).parse_simple(tokens).unwrap();
sourcepub fn element_close_use_default_wildcard_ident(
self,
open_tag_should_be_block: bool,
) -> Self
pub fn element_close_use_default_wildcard_ident( self, open_tag_should_be_block: bool, ) -> Self
Allows unmatched tag pairs where close tag matches a specified wildcard.
Uses default wildcard ident (_
), and optionally check whenewer
open_tag name is block.
sourcepub fn custom_node<CN: CustomNode>(self) -> ParserConfig<CN>
pub fn custom_node<CN: CustomNode>(self) -> ParserConfig<CN>
Enables parsing for [Node::Custom
] using a type implementing
CustomNode
.
Trait Implementations§
source§impl<C> Clone for ParserConfig<C>
impl<C> Clone for ParserConfig<C>
source§impl<C> Debug for ParserConfig<C>
impl<C> Debug for ParserConfig<C>
source§impl Default for ParserConfig
impl Default for ParserConfig
source§impl<C: CustomNode> From<ParserConfig<C>> for RecoveryConfig
impl<C: CustomNode> From<ParserConfig<C>> for RecoveryConfig
source§fn from(config: ParserConfig<C>) -> Self
fn from(config: ParserConfig<C>) -> Self
Auto Trait Implementations§
impl<C> Freeze for ParserConfig<C>
impl<C = Infallible> !RefUnwindSafe for ParserConfig<C>
impl<C = Infallible> !Send for ParserConfig<C>
impl<C = Infallible> !Sync for ParserConfig<C>
impl<C> Unpin for ParserConfig<C>where
C: Unpin,
impl<C = Infallible> !UnwindSafe for ParserConfig<C>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightBlack
.
§Example
println!("{}", value.bright_black());
source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightGreen
.
§Example
println!("{}", value.bright_green());
source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightYellow
.
§Example
println!("{}", value.bright_yellow());
source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightMagenta
.
§Example
println!("{}", value.bright_magenta());
source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightWhite
.
§Example
println!("{}", value.bright_white());
source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightBlack
.
§Example
println!("{}", value.on_bright_black());
source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightGreen
.
§Example
println!("{}", value.on_bright_green());
source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightYellow
.
§Example
println!("{}", value.on_bright_yellow());
source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightBlue
.
§Example
println!("{}", value.on_bright_blue());
source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightMagenta
.
§Example
println!("{}", value.on_bright_magenta());
source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightCyan
.
§Example
println!("{}", value.on_bright_cyan());
source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightWhite
.
§Example
println!("{}", value.on_bright_white());
source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute
value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
source§fn underline(&self) -> Painted<&T>
fn underline(&self) -> Painted<&T>
Returns self
with the
attr()
set to
Attribute::Underline
.
§Example
println!("{}", value.underline());
source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Returns self
with the
attr()
set to
Attribute::RapidBlink
.
§Example
println!("{}", value.rapid_blink());
source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
Quirk
value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition
value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);