From 45829580113f577a9ce2460dcdbf39700442b9c5 Mon Sep 17 00:00:00 2001 From: Devin Yeung Date: Sat, 18 Nov 2023 22:47:43 +0800 Subject: [PATCH] refactor: factor out `epsilon()` --- src/utils/first/builder.rs | 8 +------- src/utils/mod.rs | 6 ++++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/utils/first/builder.rs b/src/utils/first/builder.rs index 4d007fc..8a12ef8 100644 --- a/src/utils/first/builder.rs +++ b/src/utils/first/builder.rs @@ -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 = OnceCell::new(); - EPSILON.get_or_init(|| Term::Terminal(String::from("ε"))) -} - pub struct FirstBuilder<'grammar> { pub(crate) grammar: &'grammar Grammar, pub(crate) first: RefCell>>, diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 47fc680..72d192e 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,4 +1,5 @@ use bnf::{Grammar, Term}; +use once_cell::sync::OnceCell; use std::collections::HashSet; pub mod builder; @@ -13,3 +14,8 @@ pub fn symbols(grammar: &Grammar) -> HashSet<&Term> { .flat_map(|expr| expr.terms_iter()) .collect::>() } + +pub fn epsilon() -> &'static Term { + static EPSILON: OnceCell = OnceCell::new(); + EPSILON.get_or_init(|| Term::Terminal(String::from("ε"))) +}