-
Notifications
You must be signed in to change notification settings - Fork 1
/
program.hs
64 lines (53 loc) · 1.38 KB
/
program.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{-
ASN.2 - 2016
(C) Copyright Buster Kim Mejborn 2016
All Rights Reserved.
-}
import Prelude hiding ((<$>))
import System.Directory
import Text.PrettyPrint.Leijen
import System.IO
import Data.List
import Lexer
import Parser
import Ast
import MakeDoc hiding(level)
level :: Int
level = 2
main :: IO ()
main = do
createDirectoryIfMissing True "out"
inp <- readFile "Concrete Examples/TLS.asn2"
let tokens = alexScanTokens inp
let formats = parser tokens
if not (isDisjoint formats) then
print "Formats are not disjoint. Leaving"
else
writeClasses formats
writeClasses :: [Format] -> IO ()
writeClasses [] = putStr "Done outputting classes."
writeClasses ((Format name ids body):xs)
= do writeDoc name ids body
writeClasses xs
writeDoc :: String -> [Id] -> FormatBody -> IO ()
{- Perhaps should include checks for invalid tags in XML -}
writeDoc name ids body = do
{ handle <- openFile ("out/" ++ name ++ ".java") WriteMode
; hPutDoc handle (makeDoc name ids body)
; hClose handle
}
makeDoc :: String -> [String] -> FormatBody -> Doc
makeDoc name ids body =
makeImports body <$>
nest level
(makeHeader name <$>
makePrivateVars body <$>
makeConstructor name body <$>
makeEncode name body <$>
makeStatics name body
)<$>
text "}" <$>
makeRest body
makeRest :: FormatBody -> Doc
makeRest (XML _) = empty
makeRest (ASN1 _) = makeASNByteObjClass