Skip to content

Commit

Permalink
refactor: factor out epsilon()
Browse files Browse the repository at this point in the history
  • Loading branch information
Devin-Yeung committed Nov 18, 2023
1 parent 50d1c1c commit 4582958
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/utils/first/builder.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
use crate::utils::first::First;
use crate::utils::symbols;
use crate::utils::{epsilon, symbols};
use bnf::{Grammar, Production, Term};
use once_cell::sync::OnceCell;
use std::cell::RefCell;
use std::collections::{HashMap, HashSet};

pub fn epsilon() -> &'static Term {
static EPSILON: OnceCell<Term> = OnceCell::new();
EPSILON.get_or_init(|| Term::Terminal(String::from("ε")))
}

pub struct FirstBuilder<'grammar> {
pub(crate) grammar: &'grammar Grammar,
pub(crate) first: RefCell<HashMap<&'grammar Term, HashSet<&'grammar Term>>>,
Expand Down
6 changes: 6 additions & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bnf::{Grammar, Term};
use once_cell::sync::OnceCell;
use std::collections::HashSet;

pub mod builder;
Expand All @@ -13,3 +14,8 @@ pub fn symbols(grammar: &Grammar) -> HashSet<&Term> {
.flat_map(|expr| expr.terms_iter())
.collect::<HashSet<_>>()
}

pub fn epsilon() -> &'static Term {
static EPSILON: OnceCell<Term> = OnceCell::new();
EPSILON.get_or_init(|| Term::Terminal(String::from("ε")))
}

0 comments on commit 4582958

Please sign in to comment.