-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.hs
executable file
·47 lines (39 loc) · 1.4 KB
/
Test.hs
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
40
41
42
43
44
45
46
import Language.EBNF.EBNF
import Language.EBNF.Parser
import qualified Language.EBNF.FormatText as T
import qualified Language.EBNF.FormatHTML as H
import Control.Applicative
import Control.Monad
import Data.List
testG :: FilePath -> IO ()
testG fp = do
inp <- readFile fp
length inp `seq` return ()
print $ length (lines inp)
case parseGrammar inp of
Left errs -> putStrLn (fmtDiagsWith inp errs)
Right g -> do
putStrLn $ fmtG g
putStrLn $ "gVarsRefed: " ++ show (gVarsRefed g)
putStrLn $ "gTermsRefed: " ++ show (gTermsRefed g)
putStrLn "****************"
putStrLn $ T.fmtGrammar g
putStrLn "****************"
putStrLn "CHECKING GRAMMAR:"
checkGrammarIO g
putStrLn "****************"
-- putStrLn $ fmtGrammarHTML g
writeFile "out.html" $ H.fmtGrammarHTML g
gio = parseGrammar' <$> readFile "TestGrammar.bnf"
checkGrammarIO :: Grammar -> IO ()
checkGrammarIO g = mapM_ checkVar (gVars g)
where v_roots = map vName (gVars g)
checkVar v = do
let v_wheres = map vName (vWhere v)
v_refd = eVarsRefed (vExpr v)
v_unbound = v_refd \\ (v_roots ++ v_wheres)
warn msg = putStrLn $ vName v ++ ": " ++ msg
forM_ v_unbound $ \vu ->
warn (vu ++ " is unbound")
forM_ (v_wheres `intersect` v_roots) $ \vsh ->
warn (vsh ++ " shadows root variable")