cfg_grammar/rule/
mod.rs

1//! This module defines grammar rules. Each rule in a context-free grammar
2//! consists of a single symbol on its left-hand side and an array of symbols
3//! on its right-hand side. In this library, each rule carries additional
4//! value called "history."
5
6pub mod builder;
7pub mod cfg_rule;
8
9use crate::local_prelude::*;
10
11/// Trait for rules of a context-free grammar.
12pub trait AsRuleRef {
13    fn as_rule_ref(&self) -> RuleRef;
14}
15
16impl<'a, R> AsRuleRef for &'a R
17where
18    R: AsRuleRef,
19{
20    fn as_rule_ref(&self) -> RuleRef {
21        (**self).as_rule_ref()
22    }
23}
24
25/// References rule's components.
26#[derive(Copy, Clone)]
27pub struct RuleRef<'a> {
28    /// Left-hand side.
29    pub lhs: Symbol,
30    /// Right-hand side.
31    pub rhs: &'a [Symbol],
32    /// The rule's history.
33    pub history_id: HistoryId,
34}
35
36impl<'a> AsRuleRef for RuleRef<'a> {
37    fn as_rule_ref(&self) -> RuleRef {
38        *self
39    }
40}