examples: annotate examples
[nit.git] / lib / ropes_debug.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2004-2008 Jean Privat <jean@pryen.org>
4 # Copyright 2006-2008 Floréal Morandat <morandat@lirmm.fr>
5 #
6 # This file is free software, which comes along with NIT. This software is
7 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
9 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
10 # is kept unaltered, and a notification of the changes is added.
11 # You are allowed to redistribute it and sell it, alone or is a part of
12 # another product.
13
14 # Exposes methods for debugging ropes when needed.
15 module ropes_debug
16
17 import core
18 intrude import core::text::ropes
19
20 redef class Text
21 # Writes self as a dot file on the hard drive
22 private fun internal_to_dot: String is abstract
23
24 # Returns the graphviz-formatted content of `self`
25 fun to_dot: String do
26 return "digraph g \{\n" + internal_to_dot + "\}\n"
27 end
28 end
29
30 redef class Concat
31 redef fun internal_to_dot
32 do
33 var s = "n{object_id} [label = {length}];\n"
34 s += "n{object_id} -> n{left.object_id} [label = \"left\"];\n"
35 s += left.internal_to_dot
36 s += "n{object_id} -> n{right.object_id} [label = \"right\"];\n"
37 s += right.internal_to_dot
38 return s
39 end
40 end
41
42 redef class FlatString
43 redef fun internal_to_dot
44 do
45 return "n{object_id} [label=\"FlatString\\nlength = {length}\\nbyte_length = {byte_length}\\nfirst_byte = {first_byte}\\nlast_byte = {last_byte}\\nText = {self.escape_to_dot}\"];\n"
46 end
47 end
48
49 redef class FlatBuffer
50 redef fun internal_to_dot
51 do
52 return "n{object_id} [label=\"FlatBuffer\\nbyte_length = {byte_length}\\nlength = {length}\\ncapacity = {capacity}\\nText = {escape_to_dot}\"];\n"
53 end
54 end
55