Skip to main content

PatternBuilder

Struct PatternBuilder 

Source
pub struct PatternBuilder<'s> { /* private fields */ }
Expand description

A pattern’s source together with the readings it is to be parsed under.

Implementations§

Source§

impl<'s> PatternBuilder<'s>

Source

pub fn new(src: &'s str) -> Self

A builder over src with every reading at its default, so PatternBuilder::new(s).build() is crate::parse.

Source

pub fn as_str(&self) -> &'s str

The pattern text this builder was given.

The nearest thing to the regex crate’s as_str, which exists because a compiled Regex is opaque: once built, the source is the only window into what it matches. A Pattern is a public tree the caller can walk and match on, so the question as_str answers does not arise for one - and a builder is the only place in this crate that holds the text after parsing, so it is the only place the accessor belongs.

Source

pub fn case_insensitive(self, yes: bool) -> Self

Compare every literal in the pattern under case folding, so "Cat" matches cat and CAT.

A register-equality atom keeps whichever group its own spelling gave it: =case x is a comparison the author named, and widening it here would make the pattern mean something other than what was written.

Source

pub fn orbit(self, group: OrbitGroup) -> Self

Compare every literal in the pattern under group.

Self::case_insensitive is this with OrbitGroup::Case, and it is the only rung the regex crate has a name for. The others have no counterpart there because a regular expression compares bytes and these are equivalences over tokens:

  • OrbitGroup::Notation folds case and notation together, so theta, \theta and the Greek letter are one token.
  • OrbitGroup::Shape compares a token’s consonant-vowel-digit shape, so "cat" matches dog and bat. A whole pattern under this rung is a structural search: find anything shaped like this, whatever it says.
  • OrbitGroup::E8 compares the token’s eight-channel profile quotiented by the E8 reflection group, which is the one rung whose equivalence is not a string relation at all.

A register-equality atom keeps whichever group its own spelling gave it, at every rung: =shape x is a comparison the author named.

Source

pub fn swap_greed(self, yes: bool) -> Self

Swap every quantifier’s preference, so * prefers the shortest match and *? the longest.

Source

pub fn nest_limit(self, limit: u32) -> Self

Refuse a pattern nesting deeper than limit groups.

Source

pub fn empty_loop(self, empty: EmptyLoop) -> Self

Which reading a repetition whose body can match nothing takes.

Source

pub fn build(self) -> Result<Pattern, ParseError>

The pattern, or the error that says why the source is not one.

§Errors

A malformed pattern, or one nesting deeper than the limit.

Source

pub fn reading(&self) -> Result<EmptyLoop, ParseError>

The empty-loop reading a scan of this pattern should take: the one the source named with (?empty:...), or the one this builder was given.

The source wins because it is part of the pattern, and a pattern that says how its own empty loops read is making a claim about what it means rather than about how some caller wants it run.

§Errors

A malformed (?empty:...) directive.

Auto Trait Implementations§

§

impl<'s> Freeze for PatternBuilder<'s>

§

impl<'s> RefUnwindSafe for PatternBuilder<'s>

§

impl<'s> Send for PatternBuilder<'s>

§

impl<'s> Sync for PatternBuilder<'s>

§

impl<'s> Unpin for PatternBuilder<'s>

§

impl<'s> UnsafeUnpin for PatternBuilder<'s>

§

impl<'s> UnwindSafe for PatternBuilder<'s>

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.