summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2025-09-28 20:38:18 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2025-09-28 20:38:18 +0200
commit57c27f313e9f28548aec19e58b1497b79d7d5335 (patch)
tree6c4eaa4e64be6b7e6eb46133df018ce44c0a2ad7
parentc55f3775c9ce7842021a6e90db0437dce41cbecb (diff)
Additional instances of ExprType used by parsed commands
-rw-r--r--src/Script/Expr/Class.hs10
-rw-r--r--src/Script/Shell.hs17
-rw-r--r--src/Script/Var.hs10
-rw-r--r--src/Test.hs8
4 files changed, 43 insertions, 2 deletions
diff --git a/src/Script/Expr/Class.hs b/src/Script/Expr/Class.hs
index 005b6a8..810b0c8 100644
--- a/src/Script/Expr/Class.hs
+++ b/src/Script/Expr/Class.hs
@@ -79,3 +79,13 @@ instance ExprType a => ExprType [a] where
textExprValue x = "[" <> T.intercalate ", " (map textExprValue x) <> "]"
exprListUnpacker _ = Just $ ExprListUnpacker id (const Proxy)
+
+instance ExprType a => ExprType (Maybe a) where
+ textExprType _ = textExprType @a Proxy <> "?"
+ textExprValue (Just x) = textExprValue x
+ textExprValue Nothing = "Nothing"
+
+instance (ExprType a, ExprType b) => ExprType (Either a b) where
+ textExprType _ = textExprType @a Proxy <> "|" <> textExprType @b Proxy
+ textExprValue (Left x) = "Left " <> textExprValue x
+ textExprValue (Right x) = "Right " <> textExprValue x
diff --git a/src/Script/Shell.hs b/src/Script/Shell.hs
index 23c3891..cc8d06f 100644
--- a/src/Script/Shell.hs
+++ b/src/Script/Shell.hs
@@ -33,6 +33,7 @@ import Network.Ip
import Output
import Process
import Run.Monad
+import Script.Expr.Class
import Script.Var
@@ -54,6 +55,22 @@ data ShellCommand = ShellCommand
, cmdSourceLine :: SourceLine
}
+instance ExprType ShellScript where
+ textExprType _ = T.pack "ShellScript"
+ textExprValue _ = "<shell-script>"
+
+instance ExprType ShellStatement where
+ textExprType _ = T.pack "ShellStatement"
+ textExprValue _ = "<shell-statement>"
+
+instance ExprType ShellPipeline where
+ textExprType _ = T.pack "ShellPipeline"
+ textExprValue _ = "<shell-pipeline>"
+
+instance ExprType ShellCommand where
+ textExprType _ = T.pack "ShellCommand"
+ textExprValue _ = "<shell-command>"
+
data ShellExecInfo = ShellExecInfo
{ seiNode :: Node
diff --git a/src/Script/Var.hs b/src/Script/Var.hs
index 668060c..2c50101 100644
--- a/src/Script/Var.hs
+++ b/src/Script/Var.hs
@@ -9,6 +9,8 @@ module Script.Var (
import Data.Text (Text)
import Data.Text qualified as T
+import Script.Expr.Class
+
newtype VarName = VarName Text
deriving (Eq, Ord)
@@ -40,6 +42,10 @@ unqualifyName (LocalVarName name) = name
newtype TypedVarName a = TypedVarName { fromTypedVarName :: VarName }
deriving (Eq, Ord)
+instance ExprType a => ExprType (TypedVarName a) where
+ textExprType _ = "TypedVarName"
+ textExprValue = textVarName . fromTypedVarName
+
newtype ModuleName = ModuleName [ Text ]
deriving (Eq, Ord, Show)
@@ -54,3 +60,7 @@ data SourceLine
textSourceLine :: SourceLine -> Text
textSourceLine (SourceLine text) = text
textSourceLine SourceLineBuiltin = "<builtin>"
+
+instance ExprType SourceLine where
+ textExprType _ = "SourceLine"
+ textExprValue = textSourceLine
diff --git a/src/Test.hs b/src/Test.hs
index 9ba185b..5530081 100644
--- a/src/Test.hs
+++ b/src/Test.hs
@@ -58,8 +58,12 @@ data TestStep a where
Wait :: TestStep ()
instance ExprType a => ExprType (TestBlock a) where
- textExprType _ = "test block"
- textExprValue _ = "<test block>"
+ textExprType _ = "TestBlock"
+ textExprValue _ = "<test-block>"
+
+instance ExprType a => ExprType (TestStep a) where
+ textExprType _ = "TestStep"
+ textExprValue _ = "<test-step>"
data MultiplyTimeout = MultiplyTimeout Scientific