···88use crate::local_prelude::*;
991010/// A set of symbols in the form of a bit vector.
1111-#[cfg_attr(feature = "miniserde", derive(miniserde::Serialize, miniserde::Deserialize))]
1212-#[derive(Clone, Debug)]
1111+#[derive(miniserde::Serialize, miniserde::Deserialize, Clone, Debug)]
1312pub struct SymbolBitSet {
1413 bit_vec: BitVec,
1514}
···3344use std::fmt;
5566-pub use crate::basic::{CfgLoadExt};
77-pub use crate::advanced::{CfgLoadAdvancedExt};
66+pub use crate::basic::CfgLoadExt;
77+pub use crate::advanced::CfgLoadAdvancedExt;
8899#[derive(Debug, Clone)]
1010pub enum LoadError {
+22-22
cfg-load/tests/test_load.rs
···13131414#[test]
1515fn test_load_advanced() {
1616- let (cfg, _, bs) = Cfg::load_advanced(r#"
1717- start ::= a b c d;
1616+ let grammar = Cfg::load_advanced(r#"
1717+ start ::= a ~ b ~ c ~ d;
1818 a ::= y;
1919 "#).unwrap();
2020- assert_eq!(cfg.rules().count(), 2);
2121- let (cfg, _, bs) = Cfg::load_advanced(r#"
2222- start ::= a b c d;
2020+ assert_eq!(grammar.cfg.rules().count(), 2);
2121+ let grammar = Cfg::load_advanced(r#"
2222+ start ::= a ~ b ~ c ~ d;
2323 a ::= "y";
2424 "#).unwrap();
2525- assert_eq!(cfg.rules().count(), 3);
2626- let (cfg, _, bs) = Cfg::load_advanced(r#"
2727- start ::= a b c d;
2525+ assert_eq!(grammar.cfg.rules().count(), 3);
2626+ let grammar = Cfg::load_advanced(r#"
2727+ start ::= a ~ b ~ c ~ d;
2828 a ::= "y";
2929 lexer {
3030 x ::= "z";
3131 }
3232 "#).unwrap();
3333- assert_eq!(cfg.rules().count(), 5);
3434- let (cfg, lm, bs) = Cfg::load_advanced(r#"
3535- start ::= a b c d;
3333+ assert_eq!(grammar.cfg.rules().count(), 5);
3434+ let grammar = Cfg::load_advanced(r#"
3535+ start ::= a ~ b ~ c ~ d;
3636 a ::= "y";
3737 lexer {
3838 x ::= "zzt";
3939 x ::= Regexp("test");
4040 }
4141 "#).unwrap();
4242- assert_eq!(cfg.rules().count(), 7);
4343- assert_eq!(format!("{:?}", lm.0.keys().flat_map(|cl| cl.iter().next()).collect::<Vec<_>>()), "[('e', 'f'), ('s', 't'), ('t', 'u'), ('y', 'z'), ('z', '{')]");
4444- assert_eq!(cfg.to_bnf(), r#"start ::= a b c d;
4242+ assert_eq!(grammar.cfg.rules().count(), 7);
4343+ assert_eq!(format!("{:?}", grammar.lexer_map.classes.keys().flat_map(|cl| cl.iter().next()).collect::<Vec<_>>()), "[('e', 'f'), ('s', 't'), ('t', 'u'), ('y', 'z'), ('z', '{')]");
4444+ assert_eq!(grammar.cfg.to_bnf(), r#"start ::= a b c d;
4545__lex0 ::= g6;
4646a ::= __lex0;
4747__lex1 ::= g9 g9 g10;
···4949g13 ::= g10 g11 g12 g10;
5050x ::= g13;
5151"#);
5252- assert_eq!(bs.iter().count(), 3);
5252+ assert_eq!(grammar.sbs.iter().count(), 3);
5353}
54545555#[test]
5656fn test_err() {
5757 assert!(Cfg::load_advanced(r#"
5858- start ::= a b c d;
5858+ start ::= a ~ b ~ c ~ d;
5959 x ::= "y";
6060 lexer {
6161 x ::= "zzt";
···66666767#[test]
6868fn test_big() {
6969- let (cfg, lm, bs) = Cfg::load_advanced(r#"
7070- start ::= a b c d;
6969+ let grammar = Cfg::load_advanced(r#"
7070+ start ::= a ~ b ~ c ~ d;
7171 a ::= "y";
7272 lexer {
7373 x ::= "zzt";
7474 x ::= Regexp("test(er)?");
7575 }
7676 "#).unwrap();
7777- assert_eq!(cfg.rules().count(), 11);
7878- assert_eq!(format!("{:?}", lm.0.keys().flat_map(|cl| cl.iter().next()).collect::<Vec<_>>()), "[('e', 'f'), ('r', 's'), ('s', 't'), ('t', 'u'), ('y', 'z'), ('z', '{')]");
7979- assert_eq!(cfg.to_bnf(), r#"start ::= a b c d;
7777+ assert_eq!(grammar.cfg.rules().count(), 11);
7878+ assert_eq!(format!("{:?}", grammar.lexer_map.classes.keys().flat_map(|cl| cl.iter().next()).collect::<Vec<_>>()), "[('e', 'f'), ('r', 's'), ('s', 't'), ('t', 'u'), ('y', 'z'), ('z', '{')]");
7979+ assert_eq!(grammar.cfg.to_bnf(), r#"start ::= a b c d;
8080__lex0 ::= g6;
8181a ::= __lex0;
8282__lex1 ::= g9 g9 g10;
···8888g17 ::= g10 g11 g13 g10 g15;
8989x ::= g17;
9090"#);
9191- assert_eq!(bs.iter().count(), 3);
9191+ assert_eq!(grammar.sbs.iter().count(), 3);
9292}
-1
cfg-predict-distance/src/lib.rs
···11//! Calculation of minimum distance from one part of the grammar to another.
2233use cfg_grammar::*;
44-use cfg_history::{earley::History, HistoryId};
54use cfg_symbol::Symbol;
6576/// Calculation of minimum distance from one part of the grammar to another.