summaryrefslogtreecommitdiff
path: root/DSL/Util.hs
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2023-02-23 23:05:54 +1300
committerMatthew Hall <hallmatthew314@gmail.com>2023-02-23 23:05:54 +1300
commit1c2e8f59960c18b5e5794fba214a3f0906fb074d (patch)
tree0c1d1a421ad50b5d704d512a328e13aa693deefa /DSL/Util.hs
parent06692c8e1754ac8d5d671160b839723e3610fcf1 (diff)
Parsing overhaul (slightly better errors)
Diffstat (limited to 'DSL/Util.hs')
-rw-r--r--DSL/Util.hs12
1 files changed, 6 insertions, 6 deletions
diff --git a/DSL/Util.hs b/DSL/Util.hs
index 75d38af..44d272c 100644
--- a/DSL/Util.hs
+++ b/DSL/Util.hs
@@ -28,20 +28,20 @@ runChecks fs s
hcf :: Machine -> String -> IO Machine
hcf m msg = putStrLn msg >> return m{ ok=False }
-appendProcTable :: [ProcSpec] -> ProcTable -> Maybe ProcTable
+appendProcTable :: [ProcSpec] -> ProcTable -> Either String ProcTable
appendProcTable x y = go x
where
- go [] = Just y
+ go [] = Right y
go ((n, bs):ps) = go ps >>= f
where
f acc
- | member n acc = Nothing
- | otherwise = Just $ insert n bs acc
+ | member n acc = Left $ "Duplicate PROC definition: " ++ n
+ | otherwise = Right $ insert n bs acc
-mergeProcTables :: ProcTable -> ProcTable -> Maybe ProcTable
+mergeProcTables :: ProcTable -> ProcTable -> Either String ProcTable
mergeProcTables x = appendProcTable $ toList x
-buildProcTable :: [ProcSpec] -> Maybe ProcTable
+buildProcTable :: [ProcSpec] -> Either String ProcTable
buildProcTable ps = appendProcTable ps empty
unreachable :: a