summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2018-02-08 08:44:57 +0100
committerCamil Staps2018-02-08 08:44:57 +0100
commit62f50c52bd2234e5715474fa2aeb7fd36257d6db (patch)
treee129311f75e944858b2ce0e4f4140ab23751d13a
parentIntegrate pretty printer (diff)
Add example programs; Main.hs using stdin
-rw-r--r--.gitmodules3
-rw-r--r--src/Main.hs11
m---------test/spl-test-programs0
3 files changed, 12 insertions, 2 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..fe1a037
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "test/spl-test-programs"]
+ path = test/spl-test-programs
+ url = https://github.com/mklinik/spl-test-programs
diff --git a/src/Main.hs b/src/Main.hs
index 15a97fa..07733dd 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -2,6 +2,7 @@
module Main where
import Prelude hiding(lex)
+import System.Environment
import Text.Parsec.Error (ParseError)
@@ -12,10 +13,16 @@ import SPL.PrettyPrinter
main :: IO ()
main = do
- contents <- readFile "test/example1.spl"
+ args <- getArgs
+ contents <- getContents
case lex contents of
Nothing -> putStrLn "Failed to lex"
- Just tks -> case parse tks of
+ Just tks -> if "--parse" `elem` args
+ then doParse tks
+ else return ()
+ where
+ doParse :: [Token] -> IO ()
+ doParse tks = case parse tks of
Left e -> do
putStrLn $ "Failed to parse (" ++ show e ++ "). Tokens were:"
putStrLn $ show tks
diff --git a/test/spl-test-programs b/test/spl-test-programs
new file mode 160000
+Subproject b504a9c9571070047fd74bd2c92943c65f6e260