diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2022-10-02 20:43:08 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2022-10-05 21:04:17 +0200 |
commit | 4161f5776e5e7a01fb9eb62351c0f648bb918076 (patch) | |
tree | 5ff89419ecc034538a26f3c4863c4d54d4dc537f /src/Network.hs | |
parent | 4f078b27fda0738ab4ed8f67fe3c8f2c8d010626 (diff) |
Support multiple node variables with same name
Diffstat (limited to 'src/Network.hs')
-rw-r--r-- | src/Network.hs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/Network.hs b/src/Network.hs index 5872d13..a3c7120 100644 --- a/src/Network.hs +++ b/src/Network.hs @@ -2,6 +2,7 @@ module Network ( Network(..), Node(..), NodeName(..), textNodeName, unpackNodeName, + nextNodeName, ) where import Control.Arrow @@ -26,20 +27,28 @@ data Node = Node , nodeDir :: FilePath } -newtype NodeName = NodeName Text +data NodeName = NodeName Text Word deriving (Eq, Ord) textNodeName :: NodeName -> Text -textNodeName (NodeName name) = name +textNodeName (NodeName name 0) = name +textNodeName (NodeName name num) = name <> T.pack "~" <> T.pack (show num) unpackNodeName :: NodeName -> String -unpackNodeName (NodeName tname) = T.unpack tname +unpackNodeName = T.unpack . textNodeName + +nextNodeName :: VarName -> [NodeName] -> NodeName +nextNodeName (VarName tname) = go 0 + where + go n [] = NodeName tname n + go n (NodeName tname' m : ns) | tname == tname' = go (max n m + 1) ns + | otherwise = go n ns instance ExprType Node where textExprType _ = T.pack "node" textExprValue n = T.pack "n:" <> textNodeName (nodeName n) - emptyVarValue = Node (NodeName T.empty) T.empty undefined undefined + emptyVarValue = Node (NodeName T.empty 0) T.empty undefined undefined recordMembers = map (first T.pack) [ ("ip", RecordSelector $ nodeIp) |