diff --git a/src/library/Graph/GraphMorphism.hs b/src/library/Graph/GraphMorphism.hs index edfb432a..e6d7d521 100644 --- a/src/library/Graph/GraphMorphism.hs +++ b/src/library/Graph/GraphMorphism.hs @@ -45,8 +45,7 @@ import Control.Arrow import Abstract.Morphism import qualified Abstract.Relation as R import Abstract.Valid -import Data.List -import Data.Maybe (fromMaybe, isNothing, mapMaybe) +import Data.Maybe (fromMaybe, isNothing) import Graph.Graph as G data GraphMorphism a b = GraphMorphism { diff --git a/src/library/TypedGraph/Partitions/VerigraphToGraphPartition.hs b/src/library/TypedGraph/Partitions/VerigraphToGraphPartition.hs index 373808da..7843d0fc 100644 --- a/src/library/TypedGraph/Partitions/VerigraphToGraphPartition.hs +++ b/src/library/TypedGraph/Partitions/VerigraphToGraphPartition.hs @@ -36,9 +36,6 @@ createSatisfyingNacsDisjointUnion (g,injG) (n,injN) = disjointUnionGraphs left r (right,_) = graphMorphismToPartitionGraph injectiveN (M.codomain n) False id disjointUnionGraphs a b = (nodes a ++ nodes b, edges a ++ edges b) -countIncidentMap :: Eq a => (a -> Maybe a) -> [a] -> a -> Int -countIncidentMap f l y = length $ filter (\x -> f x == Just y) l - graphMorphismToPartitionGraph :: ([NodeId],[EdgeId]) -> GraphMorphism (Maybe a) (Maybe b) -> Bool -> Int -> (GP.Graph,Int) graphMorphismToPartitionGraph inj@(injNodes,_) morfL side id = ((nodes',edges'), nextId) where diff --git a/src/library/Util/List.hs b/src/library/Util/List.hs index 0f76eff4..951a210d 100644 --- a/src/library/Util/List.hs +++ b/src/library/Util/List.hs @@ -5,10 +5,13 @@ module Util.List , listKeys , replace , repeated +, split ) where +import Data.List (isPrefixOf) + -- TODO: Verify suitability for the use of Data.Sequence -- | Replaces the @idx@-th element by @new@ in the list @l@ replace :: Int -> a -> [a] -> [a] @@ -37,3 +40,29 @@ deleteByKey l k = filter (\a -> fst a /= k) l {- | Given an element @e@ and a list @l@, it returns the number of times that @e@ appears in @l@ -} countElement :: Eq a => a -> [a] -> Int countElement i = length . filter (i==) + +{- | Similar to Data.List.span, but performs the test on the entire remaining list instead of just one element.@-} +spanList :: ([a] -> Bool) -> [a] -> ([a], [a]) +spanList _ [] = ([],[]) +spanList func list@(x:xs) = + if func list + then (x:ys,zs) + else ([],list) + where (ys,zs) = spanList func xs + +{- | Similar to Data.List.break, but performs the test on the entire remaining list instead of just one element.-} +breakList :: ([a] -> Bool) -> [a] -> ([a], [a]) +breakList func = spanList (not . func) + +{- | Given a delimiter and a list (or string), split into components.-} +split :: Eq a => [a] -> [a] -> [[a]] +split _ [] = [] +split delim str = + let (firstline, remainder) = breakList (isPrefixOf delim) str + in + firstline : case remainder of + [] -> [] + x -> if x == delim + then [[]] + else split delim + (drop (length delim) x) diff --git a/src/library/XML/GGXReader.hs b/src/library/XML/GGXReader.hs index 8a5430bb..40e5894d 100644 --- a/src/library/XML/GGXReader.hs +++ b/src/library/XML/GGXReader.hs @@ -20,7 +20,6 @@ import Abstract.Valid import qualified Data.List as L import qualified Data.Map as M import Data.Maybe (fromJust, fromMaybe, mapMaybe) -import Data.String.Utils (startswith) import qualified Graph.Graph as G import Graph.GraphMorphism as GM import SndOrder.Morphism @@ -53,7 +52,7 @@ readGrammar fileName useConstraints morphismsConf = do parsedGraphs <- readGraphs fileName parsedRules <- readRules fileName - let (sndOrdRules, fstOrdRules) = L.partition (\((x,_,_,_),_) -> startswith "2rule_" x) parsedRules + let (sndOrdRules, fstOrdRules) = L.partition (\((x,_,_,_),_) -> L.isPrefixOf "2rule_" x) parsedRules rulesNames = map (\((x,_,_,_),_) -> x) fstOrdRules productions = map (instantiateRule typeGraph) fstOrdRules @@ -221,7 +220,7 @@ instantiateAtomicConstraint tg (name, premise, conclusion, maps) = buildNamedAto p = instantiateTypedGraph premise tg c = instantiateTypedGraph conclusion tg m = buildGraphMorphism (domain p) (domain c) (map mapToId mNodes) (map mapToId mEdges) - isPositive = not $ startswith "-" name + isPositive = not $ L.isPrefixOf "-" name mapToId (a,_,b) = (toN b, toN a) pNodes = G.nodeIds (domain p) (mNodes,mEdges) = L.partition (\(_,_,x) -> G.NodeId (toN x) `elem` pNodes) maps diff --git a/src/library/XML/ParseSndOrderRule.hs b/src/library/XML/ParseSndOrderRule.hs index 6ba3c98f..fbafa9f1 100644 --- a/src/library/XML/ParseSndOrderRule.hs +++ b/src/library/XML/ParseSndOrderRule.hs @@ -57,14 +57,14 @@ module XML.ParseSndOrderRule ( import Data.Char (toLower) import Data.Function (on) -import Data.List (find, groupBy, sortBy, sortOn, (\\)) +import Data.List (find, groupBy, intercalate, sortBy, sortOn, (\\)) import Data.Maybe (fromMaybe, mapMaybe) -import Data.String.Utils (join, split) import Abstract.Morphism import Graph.Graph import Graph.GraphMorphism as GM import TypedGraph.Morphism as TGM +import Util.List import XML.ParsedTypes -- | Gets the object name map between the left of two rules @@ -119,7 +119,7 @@ getSndOrderRuleSide rule@((name,_,_,_),_) = (side, ruleName, rule) side = if length splitted < 3 then error "Error parsing 2rule name" else map toLower $ splitted !! 1 - ruleName = join "_" (tail (tail splitted)) + ruleName = intercalate "_" (tail (tail splitted)) -- put together rules in the form (left,right,[nacs]) groupRules :: [SndOrderRuleSide] -> [(SndOrderRuleSide,SndOrderRuleSide,[SndOrderRuleSide])] @@ -174,7 +174,7 @@ parseNonMonoObjNames (x:xs) = (a,b,newObjName) : parseNonMonoObjNames xs where (a,b,_) = head x allObjNames = map (\(_,_,y) -> y) x - newObjName = join "|" allObjNames + newObjName = intercalate "|" allObjNames -- | Given two morphisms with the same domain, maps the codomain of both according to the interface (domain graph) -- Used to translate DPO in verigraph to SPO in ggx diff --git a/verigraph.cabal b/verigraph.cabal index cc701437..d1dfd22a 100644 --- a/verigraph.cabal +++ b/verigraph.cabal @@ -20,7 +20,6 @@ library build-depends: base >=4.8 && <4.10, containers >=0.4 && <0.6, hxt >=9.3.1.15 && <9.4, - MissingH >=1.1 && <1.5, mtl >=2.2 && <2.3, parsec >=3.1 && <3.2, QuickCheck >=2.8 && <2.10, @@ -112,7 +111,6 @@ executable verigraph containers, hxt, matrix >= 0.3, - MissingH, optparse-applicative>=0.12 && < 0.14, split >= 0.2 other-modules: ApplySndOrderRules @@ -177,7 +175,6 @@ test-suite SecondOrderTest main-is: SecondOrderTest.hs type: exitcode-stdio-1.0 build-depends: base, verigraph, - MissingH >=1.1 && <1.5, HUnit >= 1.3.1.2 other-modules: Utils