Skip to content

Commit

Permalink
make is_final a field which is the inverse of non_final
Browse files Browse the repository at this point in the history
  • Loading branch information
jdonszelmann committed Nov 22, 2023
1 parent e0f3866 commit 2097ba3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
8 changes: 2 additions & 6 deletions scopegraphs-regular-expressions/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::rc::Rc;
pub type StateID = usize;

pub struct MatchState {
non_final: bool,
pub is_final: bool,
nullable: bool,
pub transition_table: HashMap<Rc<Symbol>, StateID>,
#[cfg(feature = "dynamic")]
Expand All @@ -18,10 +18,6 @@ pub struct MatchState {
}

impl MatchState {
pub fn is_final(&self) -> bool {
!self.non_final
}

pub fn is_accepting(&self) -> bool {
self.nullable
}
Expand Down Expand Up @@ -180,7 +176,7 @@ impl RegexCompiler {
match_states.insert(
*state_ids.get(state).unwrap(),
MatchState {
non_final,
is_final: !non_final,
nullable,
#[cfg(feature = "dynamic")]
string_transition_table: transition_table
Expand Down
2 changes: 1 addition & 1 deletion scopegraphs-regular-expressions/src/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<'a> RegexMatcher<&'a str> for DynamicMatcher<'_> {
self.compiled_regex
.states
.get(self.current_state)
.map(MatchState::is_final)
.map(|i| i.is_final)
.unwrap_or_default()
}

Expand Down
2 changes: 1 addition & 1 deletion scopegraphs-regular-expressions/src/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Automaton {
})
.collect();

let finals: Vec<_> = states.iter().map(MatchState::is_final).collect();
let finals: Vec<_> = states.iter().map(|i| i.is_final).collect();
let accepting: Vec<_> = states.iter().map(MatchState::is_accepting).collect();

quote!(
Expand Down

0 comments on commit 2097ba3

Please sign in to comment.