Property definitions

nitcc_runtime $ Node :: defaultinit
# A node of a syntactic tree
abstract class Node
	# The name of the node (as used in the grammar file)
	fun node_name: String do return class_name

	# A point of view on the direct children of the node
	fun children: SequenceRead[nullable Node] is abstract

	# A point of view of a depth-first visit of all non-null children
	var depth: Collection[Node] = new DephCollection(self) is lazy

	# Visit all the children of the node with the visitor `v`
	protected fun visit_children(v: Visitor)
	do
		for c in children do if c != null then v.enter_visit(c)
	end

	# The position of the node in the input stream
	var position: nullable Position = null is writable

	# Produce a graphiz file for the syntaxtic tree rooted at `self`.
	fun to_dot(filepath: String)
	do
		var f = new FileWriter.open(filepath)
		f.write("digraph g \{\n")
		f.write("rankdir=BT;\n")

		var a = new Array[NToken]
		to_dot_visitor(f, a)

		f.write("\{ rank=same\n")
		var first = true
		for n in a do
			if first then
				first = false
			else
				f.write("->")
			end
			f.write("n{n.object_id}")
		end
		f.write("[style=invis];\n")
		f.write("\}\n")

		f.write("\}\n")
		f.close
	end

	private fun to_dot_visitor(f: Writer, a: Array[NToken])
	do
		f.write("n{object_id} [label=\"{node_name}\"];\n")
		for x in children do
			if x == null then continue
			f.write("n{x.object_id} -> n{object_id};\n")
			x.to_dot_visitor(f,a )
		end
	end

	redef fun to_s do
		var pos = position
		if pos == null then
			return "{node_name}"
		else
			return "{node_name}@({pos})"
		end
	end
end
lib/nitcc_runtime/nitcc_runtime.nit:360,1--425,3