Struct cfg::Cfg [] [src]

pub struct Cfg<H = NullHistory, Hs = H> {
    // some fields omitted
}

Basic representation of context-free grammars.

Methods

impl<H, Hs> Cfg<H, Hs>

fn new() -> Self

Creates an empty context-free grammar.

fn with_sym_source(sym_source: SymbolSource) -> Self

Creates an empty context-free grammar with the given symbol source.

impl<H, Hs> Cfg<H, Hs> where Hs: RewriteSequence<Rewritten=H>, H: Clone, Hs: Clone

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.

fn sequence(&mut self, lhs: Symbol) -> SequenceRuleBuilder<Hs, &mut Vec<Sequence<Hs>>>

Starts building a sequence rule.

fn sequence_rules(&self) -> &[Sequence<Hs>]

Returns sequence rules.

fn rewrite_sequences(&mut self)

Forces a rewrite of sequence rules into grammar rules.

fn binarize<'a>(&'a self) -> BinarizedCfg<H> where &'a Self: ContextFreeRef<'a, Target=Self>, H: Binarize + Clone + 'static

Returns a binarized grammar which is weakly equivalent to this grammar.

Trait Implementations

impl<H, Hs> ContextFree for Cfg<H, Hs> where Hs: Clone + RewriteSequence<Rewritten=H>

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, Hs> ContextFreeRef<'a> for &'a Cfg<H, Hs> where H: 'a, Hs: Clone + RewriteSequence<Rewritten=H>

type RuleRef = Self::Rules::Item

type Rules = Iter<'a, Rule<H>>

fn rules(self) -> Self::Rules

impl<'a, H, Hs> ContextFreeMut<'a> for &'a mut Cfg<H, Hs> where H: 'a, Hs: Clone + RewriteSequence<Rewritten=H> + 'a

impl<H, Hs> RuleContainer for Cfg<H, Hs> where Hs: Clone + RewriteSequence<Rewritten=H>

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], &H) -> bool

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

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, Hs: Clone> Clone for Cfg<H, Hs>

fn clone(&self) -> Cfg<H, Hs>

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