Skip to main content

TermStore

Struct TermStore 

Source
pub struct TermStore { /* private fields */ }
Expand description

Interning store and derivative engine.

Implementations§

Source§

impl TermStore

Source

pub fn new(universe: CharSet) -> Self

New store over the given universe of symbols.

Source

pub fn universe(&self) -> &CharSet

The universe of symbols.

Source

pub fn len(&self) -> usize

Number of interned terms (used for memory estimates).

Source

pub fn approx_bytes(&self) -> u64

Estimated heap bytes held by terms and memo tables (for the memory limit).

Source

pub fn is_empty(&self) -> bool

True when only the three built-in terms exist.

Source

pub fn empty(&self) -> TermId

The empty language.

Source

pub fn epsilon(&self) -> TermId

The language containing only the empty string.

Source

pub fn universal(&self) -> TermId

All strings over the universe.

Source

pub fn kind(&self, t: TermId) -> &TermKind

Shape of a term.

Source

pub fn nullable(&self, t: TermId) -> bool

Does the term accept the empty string, ignoring context? Exact only when TermStore::ctx_dep is false; use TermStore::accepting otherwise.

Source

pub fn ctx_dep(&self, t: TermId) -> bool

Does the term contain an assertion or lookaround?

Source

pub fn aux_sets(&self) -> &[CharSet]

The auxiliary sets referenced by assertions, by index.

Source

pub fn tracker_body(&self, i: u8) -> Option<TermId>

Body of lookbehind tracker i.

Source

pub fn class(&mut self, set: &CharSet) -> TermId

One symbol from set (restricted to the universe).

Source

pub fn any_symbol(&mut self) -> TermId

Any one symbol of the universe.

Source

pub fn concat_all(&mut self, factors: &[TermId]) -> TermId

Concatenation of factors, right-nested and normalised. Iterative along the sequence, so long chains cannot overflow the stack.

Source

pub fn concat(&mut self, a: TermId, b: TermId) -> TermId

Binary concatenation.

Source

pub fn union(&mut self, items: &[TermId]) -> TermId

Union, flattened, sorted and de-duplicated; classes are merged.

Source

pub fn inter(&mut self, items: &[TermId]) -> TermId

Intersection, flattened, sorted and de-duplicated; classes are merged.

Source

pub fn star(&mut self, t: TermId) -> TermId

Kleene star.

Source

pub fn not(&mut self, t: TermId) -> TermId

Complement.

Source

pub fn opt(&mut self, t: TermId) -> TermId

x?

Source

pub fn assertion( &mut self, kind: AssertKind, word: Option<&CharSet>, line: Option<&CharSet>, ) -> Option<TermId>

An assertion. word is the word-character set for word assertions, line the line-terminator set for line assertions. None when too many distinct sets are in use.

Source

pub fn look_ahead(&mut self, neg: bool, body: TermId) -> TermId

(?=body) or (?!body); the body is a complete pattern.

Source

pub fn look_behind(&mut self, neg: bool, body: TermId) -> Option<TermId>

(?<=body) or (?<!body). None when the body is context-dependent or too many trackers are in use.

Source

pub fn ctx_start(&mut self) -> u32

Context before any input has been consumed.

Source

pub fn ctx(&self, id: u32) -> &Ctx

The context object for an id.

Source

pub fn advance_ctx(&mut self, id: u32, c: u32) -> u32

Context after consuming symbol c in context id.

Source

pub fn nullable_in(&self, t: TermId, ctx: &Ctx, next: Option<u32>) -> bool

Does t accept the empty remainder at a position described by ctx, when the next input symbol is next (None = end of input)?

Source

pub fn accepting(&self, t: TermId, ctx_id: u32) -> bool

Acceptance at the end of input in context ctx_id.

Source

pub fn deriv(&mut self, t: TermId, c: u32) -> TermId

Derivative of t with respect to c, for terms that do not depend on context. For general terms use TermStore::deriv_in.

Source

pub fn deriv_in(&mut self, t: TermId, c: u32, ctx_id: u32) -> TermId

Brzozowski derivative of t with respect to the symbol c, where the input so far is described by context ctx_id.

Iterative (explicit work stack): terms from counted repetition are thousands of levels deep, and recursion would overflow the stack (NFR-R01).

Source

pub fn may_consume(&self, t: TermId) -> bool

Can the term match a non-empty string? (Conservative: true when unsure.)

Source

pub fn to_spec(&self, t: TermId) -> String

Serialise a term in the documented interchange format shared with the independent checker: 0 empty, e epsilon, [lo-hi,lo] hex ranges, (. a b) concatenation, (| ...) union, (& ...) intersection, (* a) star, (! a) complement, (#K w l) assertion (_ for an unused set), (?= x) / (?! x) lookahead and (<= x) / (<! x) lookbehind. Iterative, so deep terms are fine.

Source

pub fn partition(&mut self, t: TermId) -> Arc<Vec<CharSet>> ⓘ

Coarsest partition of the universe such that every class set occurring in t (including the sets used by assertions) is a union of blocks (the term’s symbol classes, FR-B02). Blocks are ordered by smallest member. Derivatives never introduce new sets, so the partition of the start term serves for the whole automaton. Iterative for the same reason as TermStore::deriv_in.

Auto Trait Implementations§

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 = !

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.