pub trait Grammar<RuleKeyType: Clone + PartialEq + Debug, ResultType: Clone + PartialEq + Debug, StreamType: Clone + PartialEq + Debug> {
Show 16 methods // Required methods fn rule_keys(&self) -> &Vec<RuleKeyType>; fn has_rule(&self, rule: &RuleKeyType) -> bool; fn get_rule_options(&self, rule: &RuleKeyType) -> Option<&Vec<ResultType>>; fn default_starting_point(&self) -> &RuleKeyType; fn check_token_stream( &self, stream: &StreamType ) -> (bool, Vec<Replacable<RuleKeyType, ResultType>>); fn rule_to_default_result(&self, rule: &RuleKeyType) -> ResultType; fn result_to_stream(&self, result: &[ResultType]) -> StreamType; fn stream_to_result(&self, stream: &StreamType) -> Vec<ResultType>; fn processing_direction(&self) -> GrammarProcessingDirection; fn set_additional_rules(&mut self, rule: RuleKeyType, values: &[ResultType]); // Provided methods fn select_from_rule<R: GrammarRandomNumberGenerator>( &self, rule: &RuleKeyType, rng: &mut R ) -> Option<&ResultType> { ... } fn copy_and_replace_rules(&mut self, other: &Self) { ... } fn max_depth(&self) -> usize { ... } fn process_stream<R: GrammarRandomNumberGenerator>( &self, stream: &StreamType, rng: &mut R, temporary_grammar: &mut Self ) -> StreamType { ... } fn breadth_first_processing<R: GrammarRandomNumberGenerator>( &self, stream: &StreamType, temporary_grammar: &mut Self, rng: &mut R ) -> StreamType { ... } fn depth_first_processing<R: GrammarRandomNumberGenerator>( &self, stream: &StreamType, temporary_grammar: &mut Self, rng: &mut R ) -> StreamType { ... }
}
Expand description

This trait defines an interface for a grammar

Required Methods§

source

fn rule_keys(&self) -> &Vec<RuleKeyType>

Gets a Vec of all the possible rule keys - can be used to see if any match

source

fn has_rule(&self, rule: &RuleKeyType) -> bool

Checks if a given rule key is available

source

fn get_rule_options(&self, rule: &RuleKeyType) -> Option<&Vec<ResultType>>

Gets all the possible expansions from a rule key

source

fn default_starting_point(&self) -> &RuleKeyType

Gets the default starting key - used if no other key is set

source

fn check_token_stream( &self, stream: &StreamType ) -> (bool, Vec<Replacable<RuleKeyType, ResultType>>)

Parses a token stream and determines a) whether there are any tokens to replace and b) if so, which The bool is true if there are no more tokens that need replacing

source

fn rule_to_default_result(&self, rule: &RuleKeyType) -> ResultType

Converts a rule key to a default result, in case no matching rule is found in the grammar.

source

fn result_to_stream(&self, result: &[ResultType]) -> StreamType

Converts a group of result types to a stream type

source

fn stream_to_result(&self, stream: &StreamType) -> Vec<ResultType>

Converts a stream to a vec of result type

source

fn processing_direction(&self) -> GrammarProcessingDirection

determines if the grammar should be processed breadth-first or depth-first

source

fn set_additional_rules(&mut self, rule: RuleKeyType, values: &[ResultType])

This is a function for setting a new rule. The expectation is that it overrides the original.

Provided Methods§

source

fn select_from_rule<R: GrammarRandomNumberGenerator>( &self, rule: &RuleKeyType, rng: &mut R ) -> Option<&ResultType>

Selects an element from a rule’s options. provides a default implementation in case no weighting is ncessessary. The RNG function should accept the total number of options, and return a single id (a number less than the total). If it is larger, we will use the last element.

source

fn copy_and_replace_rules(&mut self, other: &Self)

This is used to clone all the roles from another grammar into this one. This is used by stateful generators to update their state.

source

fn max_depth(&self) -> usize

Provides the maximum depth (number of iterations) allowed for the generator. It will always quit early if it stabilizes, but otherwise it will conclude when it reaches the provided depth.

source

fn process_stream<R: GrammarRandomNumberGenerator>( &self, stream: &StreamType, rng: &mut R, temporary_grammar: &mut Self ) -> StreamType

Takes a token stream, checks it for replacements, and then applies them by using select from rule. It returns a bool indicating whether it had to make any replacements this round, and a vec of the results.

source

fn breadth_first_processing<R: GrammarRandomNumberGenerator>( &self, stream: &StreamType, temporary_grammar: &mut Self, rng: &mut R ) -> StreamType

Processes a stream breadth first, regardless of the settings of the grammar

source

fn depth_first_processing<R: GrammarRandomNumberGenerator>( &self, stream: &StreamType, temporary_grammar: &mut Self, rng: &mut R ) -> StreamType

Processes a stream depth first, regardless of the settings of the grammar

Implementors§