Quoted

Struct Quoted 

Source
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

Source

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.

Source

pub fn with(bracket: Bracket) -> Self

Creates a new quoted string rule with the given bracket.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn add_rust_escapes(self) -> Self

Adds the Rust escaping rules to this rule.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for Quoted

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Bracket> for Quoted

Source§

fn from(value: Bracket) -> Self

Converts to this type from the input type.
Source§

impl From<Quoted> for Any

Source§

fn from(value: Quoted) -> Self

Converts to this type from the input type.
Source§

impl<Open, Close, Iter> Match<((Open, Close), Iter)> for Quoted
where Open: Into<Text>, Close: Into<Text>, Iter: IntoIterator, Iter::Item: Into<Content<Text>>,

Source§

fn add_token( matcher: &mut Matcher, lexeme: Lexeme<Self>, ((open, close), content): ((Open, Close), Iter), )

Adds a new token to matcher.
Source§

impl Rule for Quoted

Source§

type Token<'lex> = Quoted<'lex>

This rule’s corresponding token type. Read more
Source§

fn try_from_ref(value: &Any) -> Result<&Self, WrongKind>

Converts a reference to Any to a reference to this kind of rule.
Source§

impl TryFrom<Any> for Quoted

Source§

type Error = WrongKind

The type returned in the event of a conversion error.
Source§

fn try_from(value: Any) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl Freeze for Quoted

§

impl RefUnwindSafe for Quoted

§

impl Send for Quoted

§

impl Sync for Quoted

§

impl Unpin for Quoted

§

impl UnwindSafe for Quoted

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.