diff --git a/src/Rextra/Dfa.hs b/src/Rextra/Dfa.hs index ac9634d..1b4f375 100644 --- a/src/Rextra/Dfa.hs +++ b/src/Rextra/Dfa.hs @@ -56,8 +56,10 @@ dfa stateMap entryState = let myDfa = Dfa{stateMap=stateMap, entryState=entryState} in if integrityCheck myDfa then Just myDfa else Nothing -dfa' :: (Ord s) => [(s, State s t)] -> s -> Maybe (Dfa s t) -dfa' states entryState = dfa (Map.fromList states) entryState +dfa' :: (Ord s, Ord t) => [(s, [(t, s)], s, Bool)] -> s -> Maybe (Dfa s t) +dfa' states entryState = + let stateList = map (\(s, ts, dt, a) -> (s, State (Map.fromList ts) dt a)) states + in dfa (Map.fromList stateList) entryState {- - Executing diff --git a/src/Rextra/Nfa.hs b/src/Rextra/Nfa.hs index 8c66dd0..12a0138 100644 --- a/src/Rextra/Nfa.hs +++ b/src/Rextra/Nfa.hs @@ -7,6 +7,8 @@ module Rextra.Nfa ( , specialTokens , accepts -- ** Constructing + , only + , allExcept , nfa , nfa' -- ** Properties @@ -105,9 +107,20 @@ 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. -nfa' :: (Ord s) => [(s, State s t)] -> s -> [s] -> Maybe (Nfa s t) -nfa' states entryState exitStates = nfa (Map.fromList states) entryState (Set.fromList exitStates) +only :: (Ord t) => [t] -> TransitionCondition t +only = Only . Set.fromList + +allExcept :: (Ord t) => [t] -> TransitionCondition t +allExcept = AllExcept . Set.fromList + +nfa' :: (Ord s) + => [(s, [(TransitionCondition t, s)], [s])] + -> s + -> [s] + -> Maybe (Nfa s t) +nfa' states entryState exitStates = + let stateList = map (\(s, ts, et) -> (s, State ts (Set.fromList et))) states + in nfa (Map.fromList stateList) entryState (Set.fromList exitStates) {- - Executing