Skip to content
This repository was archived by the owner on Jul 18, 2023. It is now read-only.

Commit c8bf1c1

Browse files
committed
%input% %output%
1 parent 141fb5e commit c8bf1c1

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/Language/PipeScript/Interpreter/Context.hs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import Language.PipeScript.Parser
3434
import Path
3535
import System.Environment (getEnv, getEnvironment)
3636
import Data.List ( groupBy, sortBy )
37-
import Path.IO (getCurrentDir)
37+
import Path.IO (getCurrentDir, AnyPath (makeRelative))
3838
import Data.Maybe (fromMaybe)
3939

4040
data Value
@@ -59,7 +59,7 @@ instance Show Value where
5959
show (ValList x) = show x
6060
show ValUnit = show ()
6161

62-
value2Str :: Value -> String
62+
value2Str :: Value -> String
6363
value2Str (ValInt x) = show x
6464
value2Str (ValStr x) = x
6565
value2Str (ValSymbol x) = x
@@ -79,10 +79,10 @@ data Task = Task
7979
operationName :: String,
8080
arguments :: [Value],
8181
context :: Context
82-
}
82+
}
8383

8484
instance Eq Task where
85-
a == b =
85+
a == b =
8686
inputFiles a == inputFiles b &&
8787
outputFiles a == outputFiles b &&
8888
dirty a == dirty b &&
@@ -188,6 +188,16 @@ getVariable (Variable (Identifier "cd")) = do
188188
rel <- scriptDir . curScript <$> get
189189
cd <- getCurrentDir
190190
return $ ValStr $ toFilePath $ cd </> rel
191+
getVariable (Variable (Identifier "input")) = do
192+
t <- curTask <$> get
193+
cd <- currentWorkAbsDir
194+
files <- liftIO $ mapM (makeRelative cd) $ maybe [] inputFiles t
195+
return $ ValList $ ValStr . toFilePath <$> files
196+
getVariable (Variable (Identifier "output")) = do
197+
t <- curTask <$> get
198+
cd <- currentWorkAbsDir
199+
files <- liftIO $ mapM (makeRelative cd) $ maybe [] outputFiles t
200+
return $ ValList $ ValStr . toFilePath <$> files
191201
getVariable v = do
192202
vars <- variables <$> get
193203
case vars !? v of
@@ -196,6 +206,7 @@ getVariable v = do
196206
where
197207
(Variable (Identifier vn)) = v
198208

209+
199210
getVariables :: Interpreter [(Variable, Value)]
200211
getVariables = toList . variables <$> get
201212

src/Language/PipeScript/Interpreter/Eval.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@ runCommand command args = do
128128

129129
evalApplyExpr :: Expression -> [Expression] -> Interpreter Value
130130
evalApplyExpr (IdentifierExpr (Identifier "set")) [VariableExpr var, expr] = do
131-
val <- evalExpr expr
132-
setVariable var val
133-
return ValUnit
131+
case var of Variable (Identifier "inputs") -> evalError "%inputs% is a read-only variable."
132+
Variable (Identifier "outputs") -> evalError "%outputs% is a read-only variable."
133+
Variable (Identifier "cd") -> evalError "%cd% is a read-only variable."
134+
Variable _ -> evalExpr expr >>= setVariable var >> return ValUnit
134135
evalApplyExpr (IdentifierExpr (Identifier "set")) _ =
135136
evalError "Set function must has a variable argument and an expression argument."
136137
evalApplyExpr (IdentifierExpr (Identifier i)) args = do

0 commit comments

Comments
 (0)