Commit 5b4b943c authored by Hans-Peter Deifel's avatar Hans-Peter Deifel
Browse files

Use strict state monad for morphism parsing

parent 4ae76e76
......@@ -14,7 +14,7 @@ import Data.Void (Void)
import Data.Tuple
import Control.Monad (void)
import Control.Monad.State (StateT, execStateT)
import Control.Monad.State.Strict (StateT, execStateT)
import qualified Data.HashMap.Strict as M
import Data.Text (Text)
import qualified Data.Text as T
......@@ -59,12 +59,13 @@ newState = nextState <<%= succ
defineSymbol :: Text -> MorphParser l h1 State
defineSymbol sym = use (symbolTable . at sym) >>= \case
Just (_, Defined) -> fail $ T.unpack sym ++ "defined twice" -- TODO: Better error
Just (x, Undefined) -> define x >> return x
Nothing -> do { x <- newState; define x; return x }
Just (x, Undefined) -> define x
Nothing -> newState >>= define
where
define :: State -> MorphParser l h1 ()
define node = symbolTable . at sym .= Just (node, Defined)
define :: State -> MorphParser l h1 State
define node = (symbolTable . at sym .= Just (node, Defined))
*> return node
lookupSymbol :: Text -> MorphParser l h1 State
lookupSymbol sym = use (symbolTable . at sym) >>= \case
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment