@@ -80,6 +80,7 @@ import Control.DeepSeq (NFData(..))
80
80
import qualified Data.Vector as V
81
81
import Safe (atMay )
82
82
import Control.Error (note )
83
+ import Text.Read (readEither )
83
84
84
85
import System.IO
85
86
import System.Directory
@@ -335,8 +336,11 @@ interpretFunction' (FuncName "count") expr args Nothing = runNGLessIO (execu
335
336
interpretFunction' (FuncName " __check_count" ) expr args Nothing = runNGLessIO (executeCountCheck expr args)
336
337
interpretFunction' (FuncName " countfile" ) expr args Nothing = runNGLessIO (executeCountFile expr args)
337
338
interpretFunction' (FuncName " print" ) expr args Nothing = executePrint expr args
339
+ interpretFunction' (FuncName " read_int" ) expr args Nothing = executeReadInt expr args
340
+ interpretFunction' (FuncName " read_double" ) expr args Nothing = executeReadDouble expr args
338
341
interpretFunction' (FuncName " paired" ) mate1 args Nothing = runNGLessIO (executePaired mate1 args)
339
342
interpretFunction' (FuncName " select" ) expr args (Just b) = executeSelectWBlock expr args b
343
+ interpretFunction' (FuncName " __assert" ) expr [] args = executeAssert expr args
340
344
interpretFunction' fname@ (FuncName fname') expr args Nothing = do
341
345
traceExpr (" executing module function: '" ++ T. unpack fname'++ " '" ) expr
342
346
execF <- findFunction fname
@@ -536,6 +540,24 @@ executePrint :: NGLessObject -> [(T.Text, NGLessObject)] -> InterpretationEnvIO
536
540
executePrint (NGOString s) [] = liftIO (T. putStr s) >> return NGOVoid
537
541
executePrint err _ = throwScriptError (" Cannot print " ++ show err)
538
542
543
+ executeReadInt :: NGLessObject -> [(T. Text , NGLessObject )] -> InterpretationEnvIO NGLessObject
544
+ executeReadInt (NGOString " " ) kwargs = NGOInteger <$> lookupIntegerOrScriptError " read_int" " on_empty_return" kwargs
545
+ executeReadInt (NGOString s) _ = case readEither (T. unpack s) of
546
+ Right val -> return $! NGOInteger val
547
+ Left err -> throwDataError (" Could not parse integer from '" ++ T. unpack s++ " '. Error: " ++ err)
548
+ executeReadInt s _ = throwScriptError (" Cannot parse this object as integer: " ++ show s)
549
+
550
+ executeReadDouble :: NGLessObject -> [(T. Text , NGLessObject )] -> InterpretationEnvIO NGLessObject
551
+ executeReadDouble (NGOString " " ) kwargs = NGODouble <$> lookupDoubleOrScriptError " read_int" " on_empty_return" kwargs
552
+ executeReadDouble (NGOString s) _ = case readEither (T. unpack s) of
553
+ Right val -> return $! NGODouble val
554
+ Left err -> throwDataError (" Could not parse double from '" ++ T. unpack s++ " '. Error: " ++ err)
555
+ executeReadDouble s _ = throwScriptError (" Cannot parse this object as double: " ++ show s)
556
+
557
+ executeAssert (NGOBool True ) _ = return $! NGOVoid
558
+ executeAssert (NGOBool False ) _ = throwScriptError " Assert failed"
559
+ executeAssert _ _ = throwShouldNotOccur " Assert did not receive a boolean!"
560
+
539
561
executeSelectWBlock :: NGLessObject -> [(T. Text , NGLessObject )] -> Block -> InterpretationEnvIO NGLessObject
540
562
executeSelectWBlock input@ NGOMappedReadSet { nglSamFile = isam} args (Block (Variable var) body) = do
541
563
paired <- lookupBoolOrScriptErrorDef (return True ) " select" " paired" args
@@ -727,6 +749,8 @@ evalBinary BOpPathAppend a b = case (a,b) of
727
749
(NGOString pa, NGOString pb) -> return . NGOString $! T. pack (T. unpack pa </> T. unpack pb)
728
750
_ -> nglTypeError (" Operator </>: invalid arguments" :: String )
729
751
752
+ evalBinary BOpEQ (NGOString a) (NGOString b) = return . NGOBool $! a == b
753
+ evalBinary BOpNEQ (NGOString a) (NGOString b) = return . NGOBool $! a /= b
730
754
evalBinary op a b = do
731
755
a' <- asDouble a
732
756
b' <- asDouble b
0 commit comments