summaryrefslogtreecommitdiff
path: root/src/GF/Canon/TestGFC.hs
blob: ee4175610ac2e06876f684cf9c8689f5466b24e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
-- automatically generated by BNF Converter
module Main where


import IO ( stdin, hGetContents )
import System ( getArgs, getProgName )

import LexGFC
import ParGFC
import SkelGFC
import PrintGFC
import AbsGFC


import ErrM

type ParseFun a = [Token] -> Err a

myLLexer = myLexer

runFile :: (Print a, Show a) => ParseFun a -> FilePath -> IO ()
runFile p f = readFile f >>= run p

run :: (Print a, Show a) => ParseFun a -> String -> IO ()
run p s = case (p (myLLexer s)) of
           Bad s    -> do  putStrLn "\nParse Failed...\n"
                           putStrLn s
           Ok  tree -> do putStrLn "\nParse Successful!"
                          putStrLn $ "\n[Abstract Syntax]\n\n" ++ show tree
                          putStrLn $ "\n[Linearized tree]\n\n" ++ printTree tree


main :: IO ()
main = do args <- getArgs
          case args of
            []  -> hGetContents stdin >>= run pCanon
            [f] -> runFile pCanon f
            _   -> do progName <- getProgName
                      putStrLn $ progName ++ ": excess arguments."