# Exposes methods for debugging ropes when needed.
module ropes_debug
-intrude import ::standard::ropes
-import ::standard
+import core
+intrude import core::text::ropes
-redef class Rope
+redef class Text
# Writes self as a dot file on the hard drive
- fun to_dot(filepath: String): String is abstract
-end
-
-redef class RopeNode
- # Generates a dot string
- fun to_dot(s: String): String is abstract
-end
+ private fun internal_to_dot: String is abstract
-redef class Leaf
- redef fun to_dot(s): String
- do
- s += "n{object_id} [label = \"{str}\" shape = rect];\n"
- s += "n{str.object_id} -> n{object_id} [label = \"contains\"];\n"
- s = str.to_dot(s)
- return s
+ # Returns the graphviz-formatted content of `self`
+ fun to_dot: String do
+ return "digraph g \{\n" + internal_to_dot + "\}\n"
end
end
redef class Concat
- redef fun to_dot(s): String
+ redef fun internal_to_dot
do
- s += "n{object_id} [label = {length}];\n"
- if left != null then
- s += "n{object_id} -> n{left.object_id} [label = \"left\"];\n"
- s = left.to_dot(s)
- end
- if right != null then
- s += "n{object_id} -> n{right.object_id} [label = \"right\"];\n"
- s = right.to_dot(s)
- end
+ var s = "n{object_id} [label = {length}];\n"
+ s += "n{object_id} -> n{left.object_id} [label = \"left\"];\n"
+ s += left.internal_to_dot
+ s += "n{object_id} -> n{right.object_id} [label = \"right\"];\n"
+ s += right.internal_to_dot
return s
end
end
-redef class FlatText
- fun to_dot(s: String): String is abstract
-end
-
redef class FlatString
- redef fun to_dot(s: String): String
+ redef fun internal_to_dot
do
- return s + "n{object_id} [label=\"FlatString\\nindex_from = {index_from}\\nindex_to = {index_to}\\nNativeString = {items.to_s_with_length(items.cstring_length)}\"];\n"
+ 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"
end
end
redef class FlatBuffer
- redef fun to_dot(s: String): String
- do
- return s + "n{object_id} [label=\"FlatBuffer\\length = {length}\\ncapacity = {capacity}\\nitems = {items.to_s_with_length(items.cstring_length)}\"];\n"
- end
-end
-
-redef class RopeString
- redef fun to_dot(filepath: String)
+ redef fun internal_to_dot
do
- var of = new OFStream.open(filepath)
- var ret: String = new RopeString.from("digraph g \{\n")
- ret = root.to_dot(ret).as(RopeString)
- ret += "\}\n"
- ret.write_to(of)
- of.close
- return ret
+ return "n{object_id} [label=\"FlatBuffer\\nbyte_length = {byte_length}\\nlength = {length}\\ncapacity = {capacity}\\nText = {escape_to_dot}\"];\n"
end
end
-