Struct cfg::BinarizedCfg [] [src]

pub struct BinarizedCfg<H = NullHistory> {
    // some fields omitted
}

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

Methods

impl<H> BinarizedCfg<H>

fn new() -> Self

Creates a BinarizedCfg.

fn with_sym_source(sym_source: SymbolSource) -> Self

Creates an empty BinarizedCfg with the given symbol source.

fn from_context_free<'a, G>(this: &'a G) -> BinarizedCfg<H> where G: ContextFree<History=H>, &'a G: ContextFreeRef<'a, Target=G>, H: Binarize + Clone + 'static

Creates a BinarizedCfg by binarizing a context-free grammar.

fn sort(&mut self)

Sorts the rule array.

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

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

fn dedup(&mut self)

Removes consecutive duplicate rules.

impl<H> BinarizedCfg<H> where H: Binarize

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

Returns generated symbols.

fn next_sym(&mut self) -> Symbol

Generates a new unique symbol.

fn num_syms(&self) -> usize

Returns the number of symbols in use.

impl<H> BinarizedCfg<H> where H: Binarize + Clone + EliminateNulling

fn eliminate_nulling_rules(&mut self) -> BinarizedCfg<H>

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

impl<H> ContextFree for BinarizedCfg<H> where H: Binarize

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

fn precedenced_rule(&mut self, lhs: Symbol) -> PrecedencedRuleBuilder<&mut Self> where Self::History: AssignPrecedence + Default

impl<'a, H> ContextFreeRef<'a> for &'a BinarizedCfg<H> where H: Binarize + 'a

type RuleRef = RuleRef<'a, H>

type Rules = BinarizedRules<'a, H>

fn rules(self) -> Self::Rules

impl<'a, H> ContextFreeMut<'a> for &'a mut BinarizedCfg<H> where H: Binarize + 'a

impl<H> RuleContainer for BinarizedCfg<H> where H: Binarize

type History = H

fn sym_source(&self) -> &SymbolSource

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

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

fn add_rule(&mut self, lhs: Symbol, rhs: &[Symbol], history: Self::History)

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

fn next_sym(&mut self) -> Symbol

fn num_syms(&self) -> usize

Derived Implementations

impl<H: Clone> Clone for BinarizedCfg<H>

fn clone(&self) -> BinarizedCfg<H>

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