From f15302fdae025b0f98ad2fda41adf77a8211c086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurri=C3=ABn=20Stutterheim?= Date: Tue, 31 May 2011 15:48:28 +0200 Subject: [PATCH] Accept Prolog rule file in CLI arguments --- NanoProlog.cabal | 3 ++- src/Language/Prolog/NanoProlog/Interpreter.hs | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/NanoProlog.cabal b/NanoProlog.cabal index 6be364f..c4125a9 100644 --- a/NanoProlog.cabal +++ b/NanoProlog.cabal @@ -1,5 +1,5 @@ Name: NanoProlog -Version: 0.2.1 +Version: 0.2.2 Synopsis: Very small interpreter for a Prolog-like language Description: This package was developed to demonstrate the ideas behind the Prolog language. It contains a very small interpreter @@ -31,6 +31,7 @@ Executable nano-prolog Library Build-Depends: base >= 4.0 && < 5.0, + haskell98 >= 1.1.0.1, uu-parsinglib >= 2.7.1, ListLike == 3.1.*, containers == 0.4.* diff --git a/src/Language/Prolog/NanoProlog/Interpreter.hs b/src/Language/Prolog/NanoProlog/Interpreter.hs index d0f7f33..c42fcc0 100644 --- a/src/Language/Prolog/NanoProlog/Interpreter.hs +++ b/src/Language/Prolog/NanoProlog/Interpreter.hs @@ -2,6 +2,7 @@ module Language.Prolog.NanoProlog.Interpreter where import Language.Prolog.NanoProlog.NanoProlog import Text.ParserCombinators.UU +import System (getArgs) import System.IO -- * Running the Interpreter @@ -9,10 +10,13 @@ import System.IO -- | The `main` program prompt for a file with Prolog rules and call the main -- interpreter loop run :: IO () -run = do hSetBuffering stdin LineBuffering - putStrLn "File with rules?" - fn <- getLine - s <- readFile fn +run = do args <- getArgs + fn <- case args of + [] -> do hSetBuffering stdin LineBuffering + putStrLn "File with rules?" + getLine + (x:_) -> return x + s <- readFile fn let (rules, errors) = startParse (pList pRule) s if null errors then do mapM_ print rules loop rules