mirror of
https://github.com/rgleichman/glance.git
synced 2024-11-22 05:38:23 +03:00
Use a Set instead of a list for lambda enclosed nodes.
This commit is contained in:
parent
164d837a10
commit
aa63e6107a
@ -23,6 +23,7 @@ import qualified Data.GraphViz as GV
|
||||
import qualified Data.GraphViz.Attributes.Complete as GVA
|
||||
import qualified Data.IntMap as IM
|
||||
import qualified Data.Map as Map
|
||||
import qualified Data.Set as Set
|
||||
|
||||
import Control.Arrow(first)
|
||||
import Data.Function(on)
|
||||
@ -393,7 +394,7 @@ drawLambdaRegions :: forall b . SpecialBackend b Double =>
|
||||
-> [(NamedIcon, SpecialQDiagram b Double)]
|
||||
-> SpecialQDiagram b Double
|
||||
drawLambdaRegions iconInfo placedNodes
|
||||
= mconcat $ fmap (drawRegion [] . fst) placedNodes
|
||||
= mconcat $ fmap (drawRegion Set.empty . fst) placedNodes
|
||||
where
|
||||
findDia :: NodeName -> SpecialQDiagram b Double
|
||||
findDia n1
|
||||
@ -401,13 +402,13 @@ drawLambdaRegions iconInfo placedNodes
|
||||
(find (\(Named n2 _, _) -> n1 == n2) placedNodes)
|
||||
|
||||
-- Also draw the region around the icon the lambda is in.
|
||||
drawRegion :: [NodeName] -> NamedIcon -> SpecialQDiagram b Double
|
||||
drawRegion :: Set.Set NodeName -> NamedIcon -> SpecialQDiagram b Double
|
||||
drawRegion parentNames icon = case icon of
|
||||
Named _ (LambdaIcon _ _ enclosedNames)
|
||||
-> regionRect $ fmap findDia (parentNames <> enclosedNames)
|
||||
-> regionRect $ findDia <$> Set.toList (parentNames <> enclosedNames)
|
||||
Named parentName (NestedApply _ headIcon icons)
|
||||
-> mconcat
|
||||
$ drawRegion (parentName:parentNames)
|
||||
$ drawRegion (Set.insert parentName parentNames)
|
||||
<$> mapMaybe
|
||||
(fmap (findIconFromName iconInfo))
|
||||
(headIcon:icons)
|
||||
|
@ -14,6 +14,7 @@ import Data.Either(partitionEithers)
|
||||
import qualified Data.Graph.Inductive.PatriciaTree as FGR
|
||||
import Data.List(unzip5, partition, intercalate)
|
||||
import Data.Maybe(fromMaybe, mapMaybe)
|
||||
import qualified Data.Set as Set
|
||||
|
||||
import qualified Language.Haskell.Exts as Exts
|
||||
import qualified Language.Haskell.Exts.Pretty as PExts
|
||||
@ -536,7 +537,7 @@ evalLambda _ context patterns expr = do
|
||||
GraphAndRef rhsRawGraph rhsRef <- evalExp rhsContext expr
|
||||
let
|
||||
paramNames = fmap patternName patternValsWithAsNames
|
||||
enclosedNodeNames = naName <$> sgNodes combinedGraph
|
||||
enclosedNodeNames = Set.fromList $ naName <$> sgNodes combinedGraph
|
||||
lambdaNode = FunctionDefNode paramNames enclosedNodeNames
|
||||
lambdaPorts = map (nameAndPort lambdaName) $ argumentPorts lambdaNode
|
||||
patternGraph = mconcat $ fmap graphAndRefToGraph patternVals
|
||||
|
@ -321,12 +321,12 @@ nestedApplySyntaxNodeToIcon flavor numArgs args =
|
||||
|
||||
nestedLambdaToIcon :: [String] -- labels
|
||||
-> Set.Set (NodeName, Edge) -- embedded icons
|
||||
-> [NodeName] -- body nodes
|
||||
-> Set.Set NodeName -- body nodes
|
||||
-> Icon
|
||||
nestedLambdaToIcon labels embeddedNodes =
|
||||
LambdaIcon labels embeddedBodyNode
|
||||
where
|
||||
dummyNode = FunctionDefNode [] []
|
||||
dummyNode = FunctionDefNode [] Set.empty
|
||||
embeddedBodyNode = makeArg embeddedNodes (inputPort dummyNode)
|
||||
|
||||
nestedCaseOrMultiIfNodeToIcon ::
|
||||
|
@ -69,7 +69,7 @@ data Icon = TextBoxIcon String
|
||||
| LambdaIcon
|
||||
[String] -- Parameter labels
|
||||
(Maybe NodeName) -- Function body expression
|
||||
[NodeName] -- Nodes inside the lambda
|
||||
(Set NodeName) -- Nodes inside the lambda
|
||||
| CaseIcon Int
|
||||
| CaseResultIcon
|
||||
| BindTextBoxIcon String
|
||||
@ -114,7 +114,7 @@ data SyntaxNode =
|
||||
| LiteralNode String -- Literal values like the string "Hello World"
|
||||
| FunctionDefNode -- Function definition (ie. lambda expression)
|
||||
[String] -- Parameter labels
|
||||
[NodeName] -- Nodes inside the lambda
|
||||
(Set NodeName) -- Nodes inside the lambda
|
||||
| CaseResultNode -- TODO remove caseResultNode
|
||||
| CaseOrMultiIfNode CaseOrMultiIfTag Int
|
||||
deriving (Show, Eq, Ord)
|
||||
|
@ -4,6 +4,7 @@ module VisualRenderingTests (
|
||||
renderTests
|
||||
) where
|
||||
import qualified Diagrams.Prelude as Dia
|
||||
import qualified Data.Set as Set
|
||||
|
||||
import Rendering (renderDrawing)
|
||||
import Types (Labeled(..), NodeName(..), Drawing(..), Edge, Icon(..), Port(..)
|
||||
@ -122,7 +123,7 @@ lambdaDia :: Drawing
|
||||
lambdaDia = Drawing icons []
|
||||
where
|
||||
icons = [
|
||||
ni0 $ LambdaIcon ["foo", "bar"] Nothing [n0, n1]
|
||||
ni0 $ LambdaIcon ["foo", "bar"] Nothing (Set.fromList [n0, n1])
|
||||
, ni1 CaseResultIcon
|
||||
, ni2 $ MultiIfIcon 3
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user