end
return ret
end
+
+ # Gets the hexdigest of the bytes of `self`
+ #
+ # assert "<STRING/&rt;".hexdigest == "266C743B535452494E47262334373B2672743B"
+ fun hexdigest: String do
+ var ln = bytelen
+ var outns = new NativeString(ln * 2)
+ var oi = 0
+ for i in [0 .. ln[ do
+ bytes[i].add_digest_at(outns, oi)
+ oi += 2
+ end
+ return new FlatString.with_infos(outns, ln * 2, 0, ln * 2 - 1)
+ end
end
redef class FlatText
return ns_i
end
+ # By escaping `self` to HTML, how many more bytes will be needed ?
+ fun chars_to_html_escape: Int do
+ var its = _items
+ var max = last_byte
+ var pos = first_byte
+ var endlen = 0
+ while pos <= max do
+ var c = its[pos]
+ if c == 0x3Cu8 then
+ endlen += 3
+ else if c == 0x3Eu8 then
+ endlen += 3
+ else if c == 0x26u8 then
+ endlen += 4
+ else if c == 0x22u8 then
+ endlen += 4
+ else if c == 0x27u8 then
+ endlen += 4
+ else if c == 0x2Fu8 then
+ endlen += 4
+ end
+ pos += 1
+ end
+ return endlen
+ end
+
+ redef fun html_escape
+ do
+ var extra = chars_to_html_escape
+ if extra == 0 then return to_s
+ var its = _items
+ var max = last_byte
+ var pos = first_byte
+ var nlen = extra + _bytelen
+ var nits = new NativeString(nlen)
+ var outpos = 0
+ while pos <= max do
+ var c = its[pos]
+ # Special codes:
+ # Some HTML characters are used as meta-data, they need
+ # to be replaced by an HTML-Escaped equivalent
+ #
+ # * 0x3C (<) => <
+ # * 0x3E (>) => >
+ # * 0x26 (&) => &
+ # * 0x22 (") => "
+ # * 0x27 (') => '
+ # * 0x2F (/) => /
+ if c == 0x3Cu8 then
+ nits[outpos] = 0x26u8
+ nits[outpos + 1] = 0x6Cu8
+ nits[outpos + 2] = 0x74u8
+ nits[outpos + 3] = 0x3Bu8
+ outpos += 4
+ else if c == 0x3Eu8 then
+ nits[outpos] = 0x26u8
+ nits[outpos + 1] = 0x67u8
+ nits[outpos + 2] = 0x74u8
+ nits[outpos + 3] = 0x3Bu8
+ outpos += 4
+ else if c == 0x26u8 then
+ nits[outpos] = 0x26u8
+ nits[outpos + 1] = 0x61u8
+ nits[outpos + 2] = 0x6Du8
+ nits[outpos + 3] = 0x70u8
+ nits[outpos + 4] = 0x3Bu8
+ outpos += 5
+ else if c == 0x22u8 then
+ nits[outpos] = 0x26u8
+ nits[outpos + 1] = 0x23u8
+ nits[outpos + 2] = 0x33u8
+ nits[outpos + 3] = 0x34u8
+ nits[outpos + 4] = 0x3Bu8
+ outpos += 5
+ else if c == 0x27u8 then
+ nits[outpos] = 0x26u8
+ nits[outpos + 1] = 0x23u8
+ nits[outpos + 2] = 0x33u8
+ nits[outpos + 3] = 0x39u8
+ nits[outpos + 4] = 0x3Bu8
+ outpos += 5
+ else if c == 0x2Fu8 then
+ nits[outpos] = 0x26u8
+ nits[outpos + 1] = 0x23u8
+ nits[outpos + 2] = 0x34u8
+ nits[outpos + 3] = 0x37u8
+ nits[outpos + 4] = 0x3Bu8
+ outpos += 5
+ else
+ nits[outpos] = c
+ outpos += 1
+ end
+ pos += 1
+ end
+ var s = new FlatString.with_infos(nits, nlen, 0, nlen - 1)
+ return s
+ end
+
# By escaping `self` to C, how many more bytes will be needed ?
#
# This enables a double-optimization in `escape_to_c` since if this
# Read the next useful line from file-name arguments
private fun read_next_line
do
- if stdin.eof then
+ while stdin.eof do
open_next_stream
end
- var line = stdin.read_line
- loop
- if not stdin.eof then break
- open_next_stream
- if not line.is_empty then break
- line = stdin.read_line
- end
- self.line = line
+ self.line = stdin.read_line
end
# Open the next file until there is no more arguments
end
# The next line to process by the main program
- var line: String
+ var line: String is noautoinit
end
# Create an instance of this class from the `deserializer`
#
# This constructor is refined by subclasses to correctly build their instances.
- init from_deserializer(deserializer: Deserializer) do end
+ init from_deserializer(deserializer: Deserializer) is nosuper do end
end
redef interface Object
# FIXME redo the plugin
var opt_github_gitdir = new OptionString("Git working directory used to resolve path name (ex: /home/me/mypackage/)", "--github-gitdir")
+ # Do not produce HTML files
+ var opt_no_render = new OptionBool("do not render HTML files", "--no-render")
+
redef init do
super
opt_source, opt_sharedir, opt_shareurl, opt_custom_title,
opt_custom_footer, opt_custom_intro, opt_custom_brand,
opt_github_upstream, opt_github_base_sha1, opt_github_gitdir,
- opt_piwik_tracker, opt_piwik_site_id)
+ opt_piwik_tracker, opt_piwik_site_id,
+ opt_no_render)
end
redef fun process_options(args) do
var name_sorter = new MEntityNameSorter
redef fun apply do
+ if ctx.opt_no_render.value then return
init_output_dir
for page in doc.pages.values do
page.render(self, doc).write_to_file("{ctx.output_dir.to_s}/{page.html_url}")
import doc_html
import doc_indexing
+import doc_test
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Print the generated DocModel in stdout.
+#
+# Mainly used for tests.
+module doc_test
+
+import doc_structure
+import counter
+
+redef class ToolContext
+
+ # File pattern used to link documentation to source code.
+ var opt_test = new OptionBool("print test data", "--test")
+
+ redef init do
+ super
+ option_context.add_option(opt_test)
+ end
+end
+
+# Display the DocModel in stdout.
+class DocTestPhase
+ super DocPhase
+
+ redef fun apply do
+ if not ctx.opt_test.value then return
+ # Pages metrics
+ var page_counter = new Counter[String]
+ var pages = doc.pages.keys.to_a
+ default_comparator.sort(pages)
+ for title in pages do
+ var page = doc.pages[title]
+ page_counter.inc page.class_name
+ print page.pretty_print.write_to_string
+ end
+ print "Generated {doc.pages.length} pages"
+ page_counter.print_elements(100)
+ # Model metrics
+ var model_counter = new Counter[String]
+ for mentity in doc.mentities do
+ model_counter.inc mentity.class_name
+ end
+ print "Found {doc.mentities.length} mentities"
+ model_counter.print_elements(100)
+ end
+end
var mmodule = identify_module(a)
if mmodule == null then
+ if a.file_exists then
+ toolcontext.error(null, "Error: `{a}` is not a Nit source file.")
+ else
+ toolcontext.error(null, "Error: cannot find module `{a}`.")
+ end
continue
end
end
end
- var candidate = search_module_in_paths(anode.hot_location, name, lookpaths)
+ var loc = null
+ if anode != null then loc = anode.hot_location
+ var candidate = search_module_in_paths(loc, name, lookpaths)
if candidate == null then
if mgroup != null then
var mmodule = new MModule(model, mgroup, mod_name, nmodule.location)
nmodule.mmodule = mmodule
nmodules.add(nmodule)
+ parsed_modules.add mmodule
self.mmodule2nmodule[mmodule] = nmodule
if parent!= null then
import modelbuilder
import doc
-import counter
redef class ToolContext
# Nitdoc generation phase.
var docphase: Phase = new Nitdoc(self, null)
- # File pattern used to link documentation to source code.
- var opt_test = new OptionBool("do not render anything, only print test data", "--test")
-
- redef init do
- super
- option_context.add_option(opt_test)
- end
+ init do super # to fix ambiguous linearization
end
# Nitdoc phase explores the model and generate pages for each mentities found
new IntroRedefListPhase(toolcontext, doc),
new LinListPhase(toolcontext, doc),
new GraphPhase(toolcontext, doc),
- new ReadmePhase(toolcontext, doc): DocPhase]
-
- if not toolcontext.opt_test.value then
- phases.add new RenderHTMLPhase(toolcontext, doc)
- end
+ new ReadmePhase(toolcontext, doc),
+ new RenderHTMLPhase(toolcontext, doc),
+ new DocTestPhase(toolcontext, doc): DocPhase]
for phase in phases do
toolcontext.info("# {phase.class_name}", 1)
phase.apply
end
-
- if toolcontext.opt_test.value then
- # Pages metrics
- var page_counter = new Counter[String]
- var pages = doc.pages.keys.to_a
- default_comparator.sort(pages)
- for title in pages do
- var page = doc.pages[title]
- page_counter.inc page.class_name
- print page.pretty_print.write_to_string
- end
- print "Generated {doc.pages.length} pages"
- page_counter.print_elements(100)
- # Model metrics
- var model_counter = new Counter[String]
- for mentity in doc.mentities do
- model_counter.inc mentity.class_name
- end
- print "Found {doc.mentities.length} mentities"
- model_counter.print_elements(100)
- end
end
end
base_simple3.nit
-m test_mixin.nit ../examples/hello_world.nit
-D text=hello -D num=42 -D flag test_define.nit
+-e 'print "hello world"'
+-n -e 'print line' test_prog/README.md test_prog/test_prog.nit
module_1.nit -d $WRITE
base_attr_nullable.nit -d $WRITE
--private base_attr_nullable.nit -d $WRITE
---test test_prog -d $WRITE
+--no-render --test test_prog -d $WRITE
nit_args1
nit_args3
nit_args4
+nit_args5
+nit_args6
nitvm_args1
nitvm_args3
nitc_args1
nit_args1
nit_args3
nit_args4
+nit_args5
+nit_args6
nitvm_args1
nitvm_args3
nitc_args1
--- /dev/null
+hello world
--- /dev/null
+Test program for model tools.
+
+This program creates a fake model that can be used to test tools like:
+
+* `nitdoc`
+* `nitmetrics`
+* `nitx`
+* or others `modelbuilder`.
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# A test program with a fake model to check model tools.
+module test_prog
+
+import rpg
+import game
+
+class Starter
+ fun start do end
+end
+
+var starter = new Starter
+starter.start
+
# Src:
<G: hs: -1, 0; s: one, two; hm: one. 1, two. 2; am: three. 3, four. 4>
# Dst:
-<G: hs: -1, 0; s: one, two; hm: one. 1, two. 2; am: three. 3, four. 4>
+<G: hs: ; s: ; hm: ; am: >
{"__kind": "obj", "__id": 0, "__class": "G", "hs": {"__kind": "obj", "__id": 1, "__class": "HashSet", "__items": [-1, 0]}, "s": {"__kind": "obj", "__id": 2, "__class": "ArraySet", "__items": ["one", "two"]}, "hm": {"__kind": "obj", "__id": 3, "__class": "HashMap", "__length": 2, "__keys": ["one", "two"], "__values": [1, 2]}, "am": {"__kind": "obj", "__id": 4, "__class": "ArrayMap", "__length": 2, "__keys": ["three", "four"], "__values": ["3", "4"]}}
# Back in Nit:
-<G: hs: -1, 0; s: one, two; hm: one. 1, two. 2; am: three. 3, four. 4>
+<G: hs: ; s: ; hm: ; am: >
--- /dev/null
+Error: cannot find module `fail.nit`.
+Error: `README.md` is not a Nit source file.
+Errors: 2. Warnings: 0.
base_simple3.nit
+fail.nit base_simple3.nit README.md