Permalink
Browse files

Accept Prolog rule file in CLI arguments

  • Loading branch information...
1 parent 23887b0 commit f15302fdae025b0f98ad2fda41adf77a8211c086 @norm2782 norm2782 committed May 31, 2011
Showing with 10 additions and 5 deletions.
  1. +2 −1 NanoProlog.cabal
  2. +8 −4 src/Language/Prolog/NanoProlog/Interpreter.hs
View
@@ -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.*
@@ -2,17 +2,21 @@ module Language.Prolog.NanoProlog.Interpreter where
import Language.Prolog.NanoProlog.NanoProlog
import Text.ParserCombinators.UU
+import System (getArgs)
import System.IO
-- * Running the Interpreter
-- ** The main interpreter
-- | 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

0 comments on commit f15302f

Please sign in to comment.