diff options
| author | Lars-Dominik Braun <lars@6xq.net> | 2024-08-17 07:44:14 +0200 |
|---|---|---|
| committer | Lars-Dominik Braun <lars@6xq.net> | 2024-08-17 07:47:16 +0200 |
| commit | 79aaf53023cd71c3eabdf63c7dd88523902fe0e4 (patch) | |
| tree | 760781cc02a68f8ada387e4de8294a2c693c4c55 | |
| parent | cc2aaa6e46dfac12dfad39414925d5a535a91d19 (diff) | |
| download | pesto-79aaf53023cd71c3eabdf63c7dd88523902fe0e4.tar.gz pesto-79aaf53023cd71c3eabdf63c7dd88523902fe0e4.tar.bz2 pesto-79aaf53023cd71c3eabdf63c7dd88523902fe0e4.zip | |
Fix non-exhaustive pattern warnings with GHC 9.2.
| -rw-r--r-- | src/lib/Codec/Pesto/Graph.lhs | 11 | ||||
| -rw-r--r-- | src/lib/Codec/Pesto/Lint.lhs | 9 |
2 files changed, 14 insertions, 6 deletions
diff --git a/src/lib/Codec/Pesto/Graph.lhs b/src/lib/Codec/Pesto/Graph.lhs index 5628ec3..b959d59 100644 --- a/src/lib/Codec/Pesto/Graph.lhs +++ b/src/lib/Codec/Pesto/Graph.lhs @@ -28,6 +28,7 @@ Language semantics > import Data.List (sort, nub, sortOn) > import Test.HUnit hiding (test, Node) > import Data.Ratio ((%), Ratio) +> import Data.Either (fromRight) > > import Codec.Pesto.Parse hiding (test) @@ -158,7 +159,9 @@ These are helper functions: > consumeStack (_, s, edges) i = > let > stack = dropWhile null s -> (top:sx) = if null stack then [[]] else stack +> alwaysStack = if null stack then [[]] else stack +> top = head alwaysStack +> sx = tail alwaysStack > in (Just i, []:top:sx, edgesTo i top ++ edges) > edgesTo i = map (\x -> (x, i)) @@ -342,8 +345,8 @@ Appendix > runGraphWith f doc expect = sort edges ~?= sort expect > where -> (Right op) = (head . extract . snd . unzip) <$> parse ("%pesto " ++ doc) -> nodes = zip [firstNodeId..] op +> op = (head . extract . snd . unzip) <$> parse ("%pesto " ++ doc) +> nodes = zip [firstNodeId..] (fromRight (error "unreachable") op) > edges = f nodes > cmpGraph = runGraphWith toGraph > cmpGraphRef = runGraphWith resolveReferences @@ -363,6 +366,8 @@ Find graph’s root node(s), that is a node without outgoing edges: Get all nodes with edges pointing towards nodeid > incomingEdges edges nodeid = filter ((==) nodeid . snd) edges + +> incomingNodes :: Nodes a -> Edges -> NodeId -> Nodes a > incomingNodes nodes edges nodeid = map ((!!) nodes . fst) $ incomingEdges edges nodeid > outgoingEdges edges nodeid = filter ((==) nodeid . fst) edges diff --git a/src/lib/Codec/Pesto/Lint.lhs b/src/lib/Codec/Pesto/Lint.lhs index edeede7..5d9be7d 100644 --- a/src/lib/Codec/Pesto/Lint.lhs +++ b/src/lib/Codec/Pesto/Lint.lhs @@ -10,13 +10,15 @@ Linting > , parseMetadata > , extractMetadata > , Metadata(..) -> , LintResult(..)) where +> , LintResult(..) +> , LintStatus(..)) where > import Test.HUnit hiding (test, Node) > import Data.List (sort, isPrefixOf, insert, intersect) > import Text.Parsec hiding (parse) > import Data.Char (isSpace, toLower) > import Data.Ratio ((%)) > import Data.Maybe (fromMaybe) +> import Data.Either (fromRight) > import qualified Data.Map.Strict as M > > import Codec.Pesto.Graph hiding (test) @@ -70,6 +72,7 @@ Metadata The graph’s root node must be a result. It contains yield (amount and unit) and title (object) of the recipe. +> extractMetadata :: Nodes Instruction -> Edges -> Maybe [(NodeId, (String, Metadata))] > extractMetadata nodes edges = case walkRoot nodes edges of > [(i, Result q@(Quantity _ _ title))] -> > Just $ (i, ("title", MetaStr title)) @@ -445,8 +448,8 @@ Every lint test checks a single aspect of the graph. > withGraph doc f = f nodes edges > where -> (Right op) = (head . extract . snd . unzip) <$> parse ("%pesto " ++ doc) -> nodes = zip [firstNodeId..] op +> op = (head . extract . snd . unzip) <$> parse ("%pesto " ++ doc) +> nodes = zip [firstNodeId..] (fromRight (error "unreachable") op) > edges = toGraph nodes ++ resolveReferences nodes > cmpLint doc expect = withGraph doc (\nodes edges -> doc ~: sort (lint nodes edges) ~?= sort expect) |
