summaryrefslogtreecommitdiff
path: root/src/GF/GFCC/TestGFCC.hs
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2007-10-04 21:38:59 +0000
committeraarne <aarne@cs.chalmers.se>2007-10-04 21:38:59 +0000
commit48ebf562b9bfcacff7c0fabeaa5892f31ddd3e1c (patch)
tree7c39399a32dd7b66e9921118de61e9246468944d /src/GF/GFCC/TestGFCC.hs
parentacc32ec199694c0e57df9f4a1f2273d166b88be4 (diff)
new GFCC format in GF/GFCC
Diffstat (limited to 'src/GF/GFCC/TestGFCC.hs')
-rw-r--r--src/GF/GFCC/TestGFCC.hs58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/GF/GFCC/TestGFCC.hs b/src/GF/GFCC/TestGFCC.hs
new file mode 100644
index 000000000..761e1db5f
--- /dev/null
+++ b/src/GF/GFCC/TestGFCC.hs
@@ -0,0 +1,58 @@
+-- automatically generated by BNF Converter
+module Main where
+
+
+import IO ( stdin, hGetContents )
+import System ( getArgs, getProgName )
+
+import GF.GFCC.LexGFCC
+import GF.GFCC.ParGFCC
+import GF.GFCC.SkelGFCC
+import GF.GFCC.PrintGFCC
+import GF.GFCC.AbsGFCC
+
+
+
+
+import GF.GFCC.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 pGrammar
+ "-s":fs -> mapM_ (runFile 0 pGrammar) fs
+ fs -> mapM_ (runFile 2 pGrammar) fs
+
+
+
+
+