1 # This file is part of NIT ( http://www.nitlanguage.org ).
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 # Tool that produces highlighting for Nit programs
20 var toolcontext
= new ToolContext
22 var opt_fragment
= new OptionBool("Omit document header and footer", "-f", "--fragment")
23 var opt_dir
= new OptionString("Output html files in a specific directory (required if more than one module)", "-d", "--dir")
24 var opt_full
= new OptionBool("Process also imported modules", "--full")
25 var opt_ast
= new OptionBool("Generate specific HTML elements for each Node of the AST", "--ast")
26 toolcontext
.option_context
.add_option
(opt_fragment
, opt_dir
, opt_full
)
29 var modelbuilder
= new ModelBuilder(model
, toolcontext
)
31 toolcontext
.process_options
32 var args
= toolcontext
.option_context
.rest
35 print
"usage: nitlight [options] files..."
36 toolcontext
.option_context
.usage
40 var mmodules
= modelbuilder
.parse
(args
)
41 modelbuilder
.run_phases
43 if opt_full
.value
then mmodules
= model
.mmodules
45 var dir
= opt_dir
.value
48 else if mmodules
.length
> 1 then
49 print
"More than one module to render, use option -d"
54 if dir
!= null then toolcontext
.info
("write {dir}/{mm.name}.html", 1)
56 var v
= new HighlightVisitor
57 if opt_ast
.value
then v
.with_ast
= true
59 if not opt_fragment
.value
then
60 page
= new HTMLTag("html")
61 page
.add_raw_html
"""<head>
62 <meta charset="utf-8">"""
65 <style type="text/css">
70 page
.add_raw_html
"""<link rel="stylesheet" type="text/css" href="style.css" />"""
72 page
.add_raw_html
"</head><body><pre>"
74 var m
= modelbuilder
.mmodule2nmodule
[mm
]
76 if not opt_fragment
.value
then
78 page
.add_raw_html
"</pre></body>"
84 page
.save
("{dir}/{mm.name}.html")
91 toolcontext
.info
("write {dir}/index.html", 1)
93 var page
= new HTMLTag("html")
94 page
.add_raw_html
"""<head>
95 <meta charset="utf-8">
99 var n
= new HTMLTag("li")
100 var n2
= new HTMLTag("a")
103 n2
.attr
("href", "{mm.name}.html")
106 page
.add_raw_html
"</li></body>"
107 page
.save
("{dir}/index.html")
109 var v
= new HighlightVisitor
110 toolcontext
.info
("write {dir}/style.css", 1)
111 var f
= new OFStream.open
("{dir}/style.css")
112 f
.write v
.css_content