cfg_predict_sets/
cfg_sets_ext.rs

1//! Extension trait for computing FIRST and FOLLOW sets.
2
3use cfg_grammar::Cfg;
4
5use crate::{FirstSets, FollowSets, PredictSets};
6
7/// Extension trait for `Cfg`.
8pub trait CfgSetsExt {
9    /// Computes the FIRST sets for this grammar.
10    fn first_sets(&self) -> FirstSets;
11    /// Computes the FOLLOW sets for this grammar.
12    fn follow_sets(&self) -> FollowSets;
13    /// Computes the FOLLOW sets for this grammar with the
14    /// given FIRST sets.
15    fn follow_sets_with_first(&self, first_sets: &FirstSets) -> FollowSets;
16}
17
18impl CfgSetsExt for Cfg {
19    fn first_sets(&self) -> FirstSets {
20        FirstSets::new(self)
21    }
22
23    fn follow_sets(&self) -> FollowSets {
24        FollowSets::new(self, self.first_sets().predict_sets())
25    }
26
27    fn follow_sets_with_first(&self, first_sets: &FirstSets) -> FollowSets {
28        FollowSets::new(self, first_sets.predict_sets())
29    }
30}