aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/Main.hs12
-rw-r--r--src/Interpreter.hs14
-rw-r--r--src/Utils.hs8
3 files changed, 26 insertions, 8 deletions
diff --git a/app/Main.hs b/app/Main.hs
index 0bfda2c..6b3a543 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -16,7 +16,9 @@ parseArgs config args =
("-h":rest) -> parseArgs
config { configShowHelp = True } rest
("-e":rest) -> parseArgs
- config { configPrintEvaled = True } rest
+ config { configPrintEvaled = PrintEvaledNonUnit } rest
+ ("-E":rest) -> parseArgs
+ config { configPrintEvaled = PrintEvaledAll } rest
("-s":rest) -> parseArgs
config { configPrintCallStack = True } rest
("-r":rest) -> parseArgs
@@ -51,7 +53,7 @@ main = do
configScriptFileName = Nothing,
configVerboseMode = False,
configShowHelp = False,
- configPrintEvaled = False,
+ configPrintEvaled = PrintEvaledOff,
configPrintCallStack = False,
configUseREPL = False
}
@@ -64,9 +66,11 @@ main = do
if (configShowHelp config) then do
putStrLn $ "Usage: " ++ progName ++ " # to open REPL"
- putStrLn $ " " ++ progName ++ " -i scriptFile # to run script file"
putStrLn $ " " ++ progName ++ " -h # to show this help"
- putStrLn $ " " ++ progName ++ " -e # to automatically print results of evaluated expressions to stdout"
+ putStrLn $ " " ++ progName ++ " -v # to show verbose debugging information"
+ putStrLn $ " " ++ progName ++ " -i scriptFile # to run script file"
+ putStrLn $ " " ++ progName ++ " -e # to print non-unit results of evaluated expressions to stdout"
+ putStrLn $ " " ++ progName ++ " -E # to print all results of evaluated expressions to stdout"
putStrLn $ " " ++ progName ++ " -s # to automatically print call stack of evaluated expressions to stdout"
putStrLn $ " " ++ progName ++ " -r # to open REPL, even after script file execution"
else do
diff --git a/src/Interpreter.hs b/src/Interpreter.hs
index f9e00b9..3e74c37 100644
--- a/src/Interpreter.hs
+++ b/src/Interpreter.hs
@@ -205,7 +205,8 @@ evaluateImport asts = do
args = tail asts
d <- getDepth
- when (d > 1) $ throwL (astPos importAst) $ "import can only be called on the top level, current depth: " ++ show d
+ when (d > 1) $ throwL (astPos importAst) $
+ "import can only be called on the top level, current depth: " ++ show d
config <- getConfig
let initialState = LState {
@@ -423,8 +424,15 @@ runInlineScript' lineNo fileName src = do
liftIO $ putStrLn output
evaluated <- foldEvaluate parsed
- when (configPrintEvaled config) $ do
- liftIO $ mapM_ putStrLn (map show evaluated)
+
+ case configPrintEvaled config of
+ PrintEvaledAll -> liftIO $ mapM_ putStrLn (map show evaluated)
+ PrintEvaledNonUnit -> do
+ let evaledNonUnits = evaluated $>
+ filter (\case AST { astNode = ASTUnit } -> False
+ _ -> True)
+ liftIO $ mapM_ putStrLn (map show evaledNonUnits)
+ PrintEvaledOff -> return ()
return evaluated
where
diff --git a/src/Utils.hs b/src/Utils.hs
index 2f9e3c0..c2a5088 100644
--- a/src/Utils.hs
+++ b/src/Utils.hs
@@ -15,11 +15,17 @@ type PositionString = String
type ErrorString = String
data LException = LException (Maybe PositionString) ErrorString
+data PrintEvaled
+ = PrintEvaledOff
+ | PrintEvaledAll
+ | PrintEvaledNonUnit
+ deriving Show
+
data Config = Config {
configScriptFileName :: Maybe String,
configVerboseMode :: Bool,
configShowHelp :: Bool,
- configPrintEvaled :: Bool,
+ configPrintEvaled :: PrintEvaled,
configPrintCallStack :: Bool,
configUseREPL :: Bool
}