pub struct Quoted { /* private fields */ }Expand description
A quoted string rule.
Quoted strings consist of one or more Bracket which capture the
Unicode scalars between them. No lexing occurs between these brackets.
Escape sequences are processed, which generate u32 codes (which can be
used to represent values not representable as char, particularly for
non-Unicode target encodings).
Implementations§
Source§impl Quoted
impl Quoted
Sourcepub fn new(quote: impl Into<Yarn>) -> Self
pub fn new(quote: impl Into<Yarn>) -> Self
Creates a new quoted string rule with the given quote character..
This function is intended for the extremely common case that both sides of a quoted thing have the exact same bracket on either side.
Sourcepub fn escape(self, key: impl Into<Yarn>) -> Self
pub fn escape(self, key: impl Into<Yarn>) -> Self
Adds a basic escape rule to this rule.
A basic escape is one that just appears literally in the string,
like \n.
Quoted::new('"')
.escape(r"\n");§Panics
Panics if the key is empty.
Sourcepub fn escapes<Y: Into<Yarn>>(self, keys: impl IntoIterator<Item = Y>) -> Self
pub fn escapes<Y: Into<Yarn>>(self, keys: impl IntoIterator<Item = Y>) -> Self
Adds multiple new basic escape rules to this rule.
Basic escapes are the most common type of escape, so they get a dedicated multi-helper.
Quoted::new('"')
.escapes([r"\n", r"\\"]);§Panics
Panics if any of the keys are empty.
Sourcepub fn invalid_escape(self, key: impl Into<Yarn>) -> Self
pub fn invalid_escape(self, key: impl Into<Yarn>) -> Self
Adds an invalid escape rule to this rule.
This is intended for catching things that look like escape sequences but aren’t, and should be diagnosed, like a single \ in many langauges.
Quoted::new('"')
.escape(r"\");§Panics
Panics if the key is empty.
Sourcepub fn fixed_length_escape(self, key: impl Into<Yarn>, len: u32) -> Self
pub fn fixed_length_escape(self, key: impl Into<Yarn>, len: u32) -> Self
Adds a fixed-length escape rule to this rule.
A fixed-length escape requires some number of characters after
its key (which may not be the string’s quotation characters). For example,
\x in Rust is a fixed-length escape.
Quoted::new('"')
.fixed_length_escape(r"\x", 2);§Panics
Panics if len == 0, or if the key is empty.
Sourcepub fn bracketed_escape(
self,
key: impl Into<Yarn>,
open: impl Into<Yarn>,
close: impl Into<Yarn>,
) -> Self
pub fn bracketed_escape( self, key: impl Into<Yarn>, open: impl Into<Yarn>, close: impl Into<Yarn>, ) -> Self
Adds a bracketed escape rule to this rule.
A fixed-length escape is followed by bracket-delimited characters, such as
\u{...} in Rust.
Quoted::new('"')
.fixed_length_escape(r"\x", 2);§Panics
Panics if either bracket is empty.
Sourcepub fn add_rust_escapes(self) -> Self
pub fn add_rust_escapes(self) -> Self
Adds the Rust escaping rules to this rule.
Sourcepub fn prefix(self, prefix: impl Into<Yarn>) -> Self
pub fn prefix(self, prefix: impl Into<Yarn>) -> Self
Adds a prefix for this rule.
If any prefixes are added, this rule must start with one of them.
To make prefixes optional, add "" as a prefix.
Sourcepub fn suffix(self, suffix: impl Into<Yarn>) -> Self
pub fn suffix(self, suffix: impl Into<Yarn>) -> Self
Adds a suffix for this rule.
If any suffixes are added, this rule must end with one of them.
To make suffixes optional, add "" as a suffix.
Sourcepub fn prefixes<Y: Into<Yarn>>(
self,
prefixes: impl IntoIterator<Item = Y>,
) -> Self
pub fn prefixes<Y: Into<Yarn>>( self, prefixes: impl IntoIterator<Item = Y>, ) -> Self
Adds prefixes for this rule.
If any prefixes are added, this rule must start with one of them.
To make prefixes optional, add "" as a prefix.
Sourcepub fn suffixes<Y: Into<Yarn>>(
self,
suffixes: impl IntoIterator<Item = Y>,
) -> Self
pub fn suffixes<Y: Into<Yarn>>( self, suffixes: impl IntoIterator<Item = Y>, ) -> Self
Adds suffixes for this rule.
If any suffixes are added, this rule must end with one of them.
To make suffixes optional, add "" as a suffix.