summaryrefslogtreecommitdiff
path: root/src-2.9/GF/JavaScript/TestJS.hs
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2008-05-20 11:47:44 +0000
committeraarne <aarne@cs.chalmers.se>2008-05-20 11:47:44 +0000
commit31bf84122b21efb444aa8d055472e166ffb90783 (patch)
tree1f051909336f1534346bcccde8dda59beab02f64 /src-2.9/GF/JavaScript/TestJS.hs
parent74f048dcf41de3540778de54dfa7541fa5b39c46 (diff)
moved all old source code to src-2.9 ; src will be for GF 3 development
Diffstat (limited to 'src-2.9/GF/JavaScript/TestJS.hs')
-rw-r--r--src-2.9/GF/JavaScript/TestJS.hs58
1 files changed, 58 insertions, 0 deletions
diff --git a/src-2.9/GF/JavaScript/TestJS.hs b/src-2.9/GF/JavaScript/TestJS.hs
new file mode 100644
index 000000000..3ddb52074
--- /dev/null
+++ b/src-2.9/GF/JavaScript/TestJS.hs
@@ -0,0 +1,58 @@
+-- automatically generated by BNF Converter
+module Main where
+
+
+import IO ( stdin, hGetContents )
+import System ( getArgs, getProgName )
+
+import GF.JavaScript.LexJS
+import GF.JavaScript.ParJS
+import GF.JavaScript.SkelJS
+import GF.JavaScript.PrintJS
+import GF.JavaScript.AbsJS
+
+
+
+
+import GF.Data.ErrM
+
+type ParseFun a = [Token] -> Err a
+
+myLLexer = myLexer
+
+type Verbosity = Int
+
+putStrV :: Verbosity -> String -> IO ()
+putStrV v s = if v > 1 then putStrLn s else return ()
+
+runFile :: (Print a, Show a) => Verbosity -> ParseFun a -> FilePath -> IO ()
+runFile v p f = putStrLn f >> readFile f >>= run v p
+
+run :: (Print a, Show a) => Verbosity -> ParseFun a -> String -> IO ()
+run v p s = let ts = myLLexer s in case p ts of
+ Bad s -> do putStrLn "\nParse Failed...\n"
+ putStrV v "Tokens:"
+ putStrV v $ show ts
+ putStrLn s
+ Ok tree -> do putStrLn "\nParse Successful!"
+ showTree v tree
+
+
+
+showTree :: (Show a, Print a) => Int -> a -> IO ()
+showTree v tree
+ = do
+ putStrV v $ "\n[Abstract Syntax]\n\n" ++ show tree
+ putStrV v $ "\n[Linearized tree]\n\n" ++ printTree tree
+
+main :: IO ()
+main = do args <- getArgs
+ case args of
+ [] -> hGetContents stdin >>= run 2 pProgram
+ "-s":fs -> mapM_ (runFile 0 pProgram) fs
+ fs -> mapM_ (runFile 2 pProgram) fs
+
+
+
+
+