Skip to content

Commit

Permalink
Accept Prolog rule file in CLI arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
norm2782 committed May 31, 2011
1 parent 23887b0 commit f15302f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion 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
Expand Down Expand Up @@ -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.*
Expand Down
12 changes: 8 additions & 4 deletions src/Language/Prolog/NanoProlog/Interpreter.hs
Expand Up @@ -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
Expand Down

0 comments on commit f15302f

Please sign in to comment.