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.
This commit is contained in:
parent
edd31cb52a
commit
89a5683ba2
1 changed files with 16 additions and 16 deletions
|
|
@ -6,10 +6,10 @@ module Rextra.Nfa (
|
||||||
, nfa
|
, nfa
|
||||||
, nfa'
|
, nfa'
|
||||||
-- ** Using
|
-- ** Using
|
||||||
, nfaStates
|
, stateMap
|
||||||
, nfaEntryState
|
, entryState
|
||||||
, nfaExitStates
|
, exitStates
|
||||||
, nfaTransition
|
, transition
|
||||||
-- ** Transitions
|
-- ** Transitions
|
||||||
, TransitionCondition
|
, TransitionCondition
|
||||||
, specialStates
|
, 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
|
-- It has one entry state and any number of exit states, which can be
|
||||||
-- interpreted as accepting states when the NFA is run.
|
-- interpreted as accepting states when the NFA is run.
|
||||||
data Nfa s t = Nfa
|
data Nfa s t = Nfa
|
||||||
{ nfaStates :: Map.Map s (State s t)
|
{ stateMap :: Map.Map s (State s t)
|
||||||
, nfaEntryState :: s
|
, entryState :: s
|
||||||
, nfaExitStates :: Set.Set s
|
, exitStates :: Set.Set s
|
||||||
}
|
}
|
||||||
|
|
||||||
{-
|
{-
|
||||||
|
|
@ -61,11 +61,11 @@ data Nfa s t = Nfa
|
||||||
integrityCheck :: (Ord s) => Nfa s t -> Bool
|
integrityCheck :: (Ord s) => Nfa s t -> Bool
|
||||||
integrityCheck nfa =
|
integrityCheck nfa =
|
||||||
let referencedStates = Set.unions
|
let referencedStates = Set.unions
|
||||||
[ Set.singleton (nfaEntryState nfa)
|
[ Set.singleton (entryState nfa)
|
||||||
, nfaExitStates nfa
|
, exitStates nfa
|
||||||
, Set.fromList . map snd . concat . Map.elems $ nfaStates 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.
|
-- | Construct an 'Nfa' from all its components.
|
||||||
--
|
--
|
||||||
|
|
@ -78,8 +78,8 @@ nfa :: (Ord s)
|
||||||
-> s -- ^ The entry state (starting state)
|
-> s -- ^ The entry state (starting state)
|
||||||
-> Set.Set s -- ^ The exit states
|
-> Set.Set s -- ^ The exit states
|
||||||
-> Maybe (Nfa s t) -- ^ The 'Nfa', if the data didn't show any inconsistencies
|
-> Maybe (Nfa s t) -- ^ The 'Nfa', if the data didn't show any inconsistencies
|
||||||
nfa states entryState exitStates =
|
nfa stateMap entryState exitStates =
|
||||||
let myNfa = Nfa{nfaStates=states, nfaEntryState=entryState, nfaExitStates=exitStates}
|
let myNfa = Nfa{stateMap=stateMap, entryState=entryState, exitStates=exitStates}
|
||||||
in if integrityCheck myNfa then Just myNfa else Nothing
|
in if integrityCheck myNfa then Just myNfa else Nothing
|
||||||
|
|
||||||
-- | A version of 'nfa' using argument formats that should be easier to work with.
|
-- | 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 :: (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@.
|
-- | 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
|
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
|
-- __Warning__: This function does /not/ check whether the states
|
||||||
-- actually exist in the automaton, and it crashes if an invalid state
|
-- actually exist in the automaton, and it crashes if an invalid state
|
||||||
-- is used.
|
-- is used.
|
||||||
nfaTransition :: (Ord s, Ord t) => Nfa s t -> Set.Set s -> t -> Set.Set s
|
transition :: (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 nfa ss t = foldMap (\s -> nextStates (getState nfa s) t) ss
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue