Struct cfg::binarized::BinarizedCfg

source ·
pub struct BinarizedCfg { /* private fields */ }
Expand description

Representation for grammars where right-hand sides of all rules have at most two symbols.

Implementations§

source§

impl BinarizedCfg

source

pub fn new() -> Self

Creates a BinarizedCfg.

source

pub fn with_sym_source(sym_source: SymbolSource) -> Self

Creates an empty BinarizedCfg with the given symbol source.

source

pub fn from_context_free<'a, G>(this: &'a G) -> BinarizedCfgwhere G: RuleContainer + Default, &'a G: RuleContainerRef<'a, Target = G>,

Creates a BinarizedCfg by binarizing a context-free grammar.

source

pub fn sort(&mut self)

Sorts the rule array.

source

pub fn sort_by<F>(&mut self, compare: F)where F: FnMut(&BinarizedRule, &BinarizedRule) -> Ordering,

Sorts the rule array in place, using the argument to compare elements.

source

pub fn dedup(&mut self)

Removes consecutive duplicate rules.

source

pub fn sym<T>(&mut self) -> Twhere T: SymbolContainer,

Returns generated symbols.

source

pub fn next_sym(&mut self) -> Symbol

Generates a new unique symbol.

source

pub fn num_syms(&self) -> usize

Returns the number of symbols in use.

source

pub fn eliminate_nulling_rules(&mut self) -> BinarizedCfg

Eliminates all rules of the form A ::= epsilon.

In other words, this splits off the set of nulling rules.

The language represented by the grammar is preserved, except for the possible lack of the empty string. Unproductive rules aren’t preserved.

Trait Implementations§

source§

impl Clone for BinarizedCfg

source§

fn clone(&self) -> BinarizedCfg

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for BinarizedCfg

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl RuleContainer for BinarizedCfg

source§

fn history_graph(&self) -> &HistoryGraph

source§

fn add_history_node(&mut self, node: HistoryNode) -> HistoryId

source§

fn sym_source(&self) -> &SymbolSource

Returns an immutable reference to the grammar’s symbol source.
source§

fn sym_source_mut(&mut self) -> &mut SymbolSource

Returns a mutable reference to the grammar’s symbol source.
source§

fn retain<F>(&mut self, f: F)where F: FnMut(Symbol, &[Symbol], HistoryId) -> bool,

Retains only the rules specified by the predicate. Read more
source§

fn add_rule(&mut self, lhs: Symbol, rhs: &[Symbol], history_id: HistoryId)

Inserts a rule with lhs and rhs on its LHS and RHS. The rule carries history.
source§

fn sym<T>(&mut self) -> Twhere T: SymbolContainer,

Returns generated symbols.
source§

fn next_sym(&mut self) -> Symbol

Generates a new unique symbol.
source§

fn num_syms(&self) -> usize

Returns the number of symbols in use.
source§

fn rule(&mut self, lhs: Symbol) -> RuleBuilder<&mut Self>

Starts building a new rule.
source§

fn precedenced_rule(&mut self, lhs: Symbol) -> PrecedencedRuleBuilder<&mut Self>

Starts building a new precedenced rule.
source§

impl<'a> RuleContainerRef<'a> for &'a BinarizedCfg

§

type RuleRef = RuleRef<'a>

Immutable reference to a rule.
§

type Rules = Chain<LhsWithHistoryToRuleRef<'a, Enumerate<Cloned<Iter<'a, Option<NonZeroUsize>>>>>, BinarizedRuleToRuleRef<Iter<'a, BinarizedRule>>>

Iterator over immutable references to the grammar’s rules.
source§

fn rules(self) -> Self::Rules

Returns an iterator over immutable references to the grammar’s rules.
source§

impl<'a> RuleContainerMut<'a> for &'a mut BinarizedCfg

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.