-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.hs
75 lines (70 loc) · 2.83 KB
/
Main.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
65
66
67
68
69
70
71
72
73
74
75
module Main where
import DOM (DOMTree(..), diff, toMarkdown, displayDiff)
import Combinators (Parser(..), Error)
import Grammar (html)
parseExample :: String -> Either [Error] (DOMTree, String)
parseExample = runParser html
main :: IO ()
main = do
let input = "<html>\
\<body>\
\<h1>Welcome</h1>\
\<h5>Hello world</h5>\
\<p>This is an example paragraph</p>\
\<ul>\
\<li>Item 1</li>\
\<li>Item 2</li>\
\</ul>\
\<ol>\
\<li>Item 1</li>\
\<li>Item 2</li>\
\<li>Item 3</li>\
\<li>Item 4</li>\
\<li>Item 5</li>\
\</ol>\
\<img alt='description' title = 'Just example' src='example'></img>\
\<ol>\
\<li><a href='example1'>Item 1</a></li>\
\<li>Item 2</li>\
\</ol>\
\<a href='example2'>Item 1</a>\
\</body>\
\</html>"
let input2 = "<html>\
\<body>\
\<h1>Testing diff checking</h1>\
\<h5>Hello world</h5>\
\<p>This is an example paragraph</p>\
\<ul>\
\<li>Item 1</li>\
\</ul>\
\<ol>\
\<li>Item 1</li>\
\<li>Item 2</li>\
\<li>Item 3</li>\
\<li>Item 4</li>\
\<li>Item 5</li>\
\</ol>\
\<img alt='new description' title = 'Just example' src='example'></img>\
\<ol>\
\<li><a href='example1'>Item 1</a></li>\
\<li>Item 2</li>\
\</ol>\
\<a href='example2'>Item 1</a>\
\<p>new item here</p>\
\</body>\
\</html>"
let result = parseExample input
case result of
Left errors -> do
mapM_ print errors
Right (tree1, _) -> do
let result2 = parseExample input2
case result2 of
Left err2 -> do
mapM_ print err2
Right (tree2, _) -> do
putStrLn "Diff computation\n"
putStrLn $ displayDiff $ diff tree1 tree2
putStrLn "Markdown Generation\n"
putStrLn $ toMarkdown tree1