From 89a5683ba2d6a040a1f8c82543112c07f6142d1a Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 24 Oct 2019 22:39:17 +0000 Subject: [PATCH] Change function naming scheme Since NFAs and DFAs have been put into separate modules, there's no need to prefix their attribute functions with 'nfa' or 'dfa' any more. --- src/Rextra/Nfa.hs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Rextra/Nfa.hs b/src/Rextra/Nfa.hs index c9cbbf9..faea5c6 100644 --- a/src/Rextra/Nfa.hs +++ b/src/Rextra/Nfa.hs @@ -6,10 +6,10 @@ module Rextra.Nfa ( , nfa , nfa' -- ** Using - , nfaStates - , nfaEntryState - , nfaExitStates - , nfaTransition + , stateMap + , entryState + , exitStates + , transition -- ** Transitions , TransitionCondition , specialStates @@ -49,9 +49,9 @@ type State s t = [(TransitionCondition t, s)] -- It has one entry state and any number of exit states, which can be -- interpreted as accepting states when the NFA is run. data Nfa s t = Nfa - { nfaStates :: Map.Map s (State s t) - , nfaEntryState :: s - , nfaExitStates :: Set.Set s + { stateMap :: Map.Map s (State s t) + , entryState :: s + , exitStates :: Set.Set s } {- @@ -61,11 +61,11 @@ data Nfa s t = Nfa integrityCheck :: (Ord s) => Nfa s t -> Bool integrityCheck nfa = let referencedStates = Set.unions - [ Set.singleton (nfaEntryState nfa) - , nfaExitStates nfa - , Set.fromList . map snd . concat . Map.elems $ nfaStates nfa + [ Set.singleton (entryState nfa) + , exitStates nfa + , Set.fromList . map snd . concat . Map.elems $ stateMap nfa ] - in referencedStates `Set.isSubsetOf` Map.keysSet (nfaStates nfa) + in referencedStates `Set.isSubsetOf` Map.keysSet (stateMap nfa) -- | Construct an 'Nfa' from all its components. -- @@ -78,8 +78,8 @@ nfa :: (Ord s) -> s -- ^ The entry state (starting state) -> Set.Set s -- ^ The exit states -> Maybe (Nfa s t) -- ^ The 'Nfa', if the data didn't show any inconsistencies -nfa states entryState exitStates = - let myNfa = Nfa{nfaStates=states, nfaEntryState=entryState, nfaExitStates=exitStates} +nfa stateMap entryState exitStates = + let myNfa = Nfa{stateMap=stateMap, entryState=entryState, exitStates=exitStates} in if integrityCheck myNfa then Just myNfa else Nothing -- | A version of 'nfa' using argument formats that should be easier to work with. @@ -91,7 +91,7 @@ nfa' states entryState exitStates = nfa (Map.fromList states) entryState (Set.fr -} getState :: (Ord s) => Nfa s t -> s -> State s t -getState nfa s = nfaStates nfa Map.! s +getState nfa s = stateMap nfa Map.! s -- | Starting from a state, find all the states that it can transition to with token @t@. nextStates :: (Ord s, Ord t) => State s t -> t -> Set.Set s @@ -106,5 +106,5 @@ nextStates state t = Set.fromList . map snd . filter (\(cond, _) -> cond `accept -- __Warning__: This function does /not/ check whether the states -- actually exist in the automaton, and it crashes if an invalid state -- is used. -nfaTransition :: (Ord s, Ord t) => Nfa s t -> Set.Set s -> t -> Set.Set s -nfaTransition nfa ss t = foldMap (\s -> nextStates (getState nfa s) t) ss +transition :: (Ord s, Ord t) => Nfa s t -> Set.Set s -> t -> Set.Set s +transition nfa ss t = foldMap (\s -> nextStates (getState nfa s) t) ss