Merge: doc: fixed some typos and other misc. corrections
[nit.git] / src / test_highlight.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Program used to test the Nit highlighter
16 module test_highlight
17
18 import htmlight
19 import test_phase
20
21 class TestHighlightVisitor
22 super HtmlightVisitor
23 redef fun hrefto(e) do
24 return "#" + e.c_name
25 end
26 end
27
28 redef fun do_work(mainmodule, mmodules, mb)
29 do
30 var v = new TestHighlightVisitor
31 print """<head>
32 <meta charset="utf-8">
33 <style type="text/css">
34 {{{v.css_content}}}
35 </style>
36 {{{v.head_content}}}
37 </head><body>
38 """
39
40 for mm in mmodules do for cd in mm.mclassdefs do for pd in cd.mpropdefs do
41 var n = mb.mpropdef2node(pd)
42 if not n isa APropdef then continue
43 var hl = new TestHighlightVisitor
44 hl.highlight_node(n)
45 print "<h1 id=\"{pd.c_name}\">{pd.full_name}</h1>"
46 printn "<pre><code>"
47 hl.html.write_to(stdout)
48 print "</code></pre>"
49 end
50
51 # Some random nodes
52 var thlv = new THLVisitor
53 for mm in mmodules do
54 var n = mb.mmodule2node(mm)
55 thlv.enter_visit(n)
56 end
57
58 print v.foot_content
59 print "</body></html>"
60 end
61
62 class THLVisitor
63 super Visitor
64 var seen = new HashSet[String]
65 redef fun visit(n)
66 do
67 var cn = n.class_name
68 if not seen.has(cn) then
69 seen.add cn
70
71 var hl = new TestHighlightVisitor
72 hl.highlight_node(n)
73 print "<h2>AST node: {cn} at {n.location}</h2>"
74 printn "<pre><code>"
75 hl.html.write_to(stdout)
76 print "</code></pre>"
77 end
78
79 n.visit_all(self)
80 end
81 end