A helper class to handle (print) Nit AST as an OrderedTree

Introduced properties

private var _display_line: Bool

nitc :: ASTDump :: _display_line

Display lines?
private var _display_structural: Bool

nitc :: ASTDump :: _display_structural

Display tokens and structural production?
private var _last_parent: nullable ANode

nitc :: ASTDump :: _last_parent

Reference to the last parent in the Ordered Tree
private var _line: Int

nitc :: ASTDump :: _line

Current line number (when printing lines)
init defaultinit(display_structural: Bool, display_line: Bool)

nitc :: ASTDump :: defaultinit

fun display_line: Bool

nitc :: ASTDump :: display_line

Display lines?
protected fun display_line=(display_line: Bool)

nitc :: ASTDump :: display_line=

Display lines?
fun display_structural: Bool

nitc :: ASTDump :: display_structural

Display tokens and structural production?
protected fun display_structural=(display_structural: Bool)

nitc :: ASTDump :: display_structural=

Display tokens and structural production?
private fun last_parent: nullable ANode

nitc :: ASTDump :: last_parent

Reference to the last parent in the Ordered Tree
private fun last_parent=(last_parent: nullable ANode)

nitc :: ASTDump :: last_parent=

Reference to the last parent in the Ordered Tree
private fun line: Int

nitc :: ASTDump :: line

Current line number (when printing lines)
private fun line=(line: Int)

nitc :: ASTDump :: line=

Current line number (when printing lines)
fun red(s: String): String

nitc :: ASTDump :: red

s as red
fun yellow(s: String): String

nitc :: ASTDump :: yellow

s as yellow

Redefined properties

redef type SELF: ASTDump

nitc $ ASTDump :: SELF

Type of this instance, automatically specialized in every class
redef fun display(n: ANode): String

nitc $ ASTDump :: display

How to display a specific element of the tree
redef fun visit(n: ANode)

nitc $ ASTDump :: visit

What the visitor do when a node is visited
redef fun write_line(o: Writer, n: ANode, p: String)

nitc $ ASTDump :: write_line

Write the full line for the element e in o.

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type CONCURRENT: ConcurrentCollection[E]

core :: Collection :: CONCURRENT

Type of the concurrent variant of this collection
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
private var _current_node: nullable ANode

nitc :: Visitor :: _current_node

The current visited node
private var _display_line: Bool

nitc :: ASTDump :: _display_line

Display lines?
private var _display_structural: Bool

nitc :: ASTDump :: _display_structural

Display tokens and structural production?
private var _last_parent: nullable ANode

nitc :: ASTDump :: _last_parent

Reference to the last parent in the Ordered Tree
private var _line: Int

nitc :: ASTDump :: _line

Current line number (when printing lines)
private var _parents: HashMap[E, nullable E]

ordered_tree :: OrderedTree :: _parents

The parent of each element.
private var _roots: Array[E]

ordered_tree :: OrderedTree :: _roots

The roots of the tree (in sequence)
private var _sub: HashMap[E, Array[E]]

ordered_tree :: OrderedTree :: _sub

The branches of the trees.
fun add(p: nullable E, e: E)

ordered_tree :: OrderedTree :: add

Add a new element e in the tree.
fun add_all(p: nullable E, es: Collection[E])

ordered_tree :: OrderedTree :: add_all

Append all nodes es as children of p.
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
abstract fun clone: SELF

core :: Cloneable :: clone

Duplicate self
fun combinations(r: Int): Collection[SequenceRead[E]]

core :: Collection :: combinations

All r-length combinations on self (in same order) without repeated elements.
fun combinations_with_replacement(r: Int): Collection[SequenceRead[E]]

core :: Collection :: combinations_with_replacement

All r-length combination on self (in same order) with repeated elements.
fun count(item: nullable Object): Int

core :: Collection :: count

How many occurrences of item are in the collection?
fun current_node: nullable ANode

nitc :: Visitor :: current_node

The current visited node
fun current_node=(current_node: nullable ANode)

nitc :: Visitor :: current_node=

The current visited node
init defaultinit(display_structural: Bool, display_line: Bool)

nitc :: ASTDump :: defaultinit

private fun detach(e: E)

ordered_tree :: OrderedTree :: detach

Temporary remove e.
fun display(e: E): String

ordered_tree :: OrderedTree :: display

How to display a specific element of the tree
fun display_line: Bool

nitc :: ASTDump :: display_line

Display lines?
protected fun display_line=(display_line: Bool)

nitc :: ASTDump :: display_line=

Display lines?
fun display_structural: Bool

nitc :: ASTDump :: display_structural

Display tokens and structural production?
protected fun display_structural=(display_structural: Bool)

nitc :: ASTDump :: display_structural=

Display tokens and structural production?
fun enter_visit(e: nullable ANode)

nitc :: Visitor :: enter_visit

Ask the visitor to visit a given node.
fun first: E

core :: Collection :: first

Return the first item of the collection
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun has(item: nullable Object): Bool

core :: Collection :: has

Is item in the collection ?
fun has_all(other: Collection[nullable Object]): Bool

core :: Collection :: has_all

Does the collection contain at least each element of other?
fun has_any(other: Collection[nullable Object]): Bool

core :: Collection :: has_any

Does the collection contain at least one element of other?
fun has_exactly(other: Collection[nullable Object]): Bool

core :: Collection :: has_exactly

Does the collection contain exactly all the elements of other?
fun has_only(item: nullable Object): Bool

core :: Collection :: has_only

Is the collection contain only item?
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
fun is_empty: Bool

core :: Collection :: is_empty

Is there no item in the collection?
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
abstract fun iterator: Iterator[E]

core :: Collection :: iterator

Get a new iterator on the collection.
fun join(separator: nullable Text, last_separator: nullable Text): String

core :: Collection :: join

Concatenate and separate each elements with separator.
private fun last_parent: nullable ANode

nitc :: ASTDump :: last_parent

Reference to the last parent in the Ordered Tree
private fun last_parent=(last_parent: nullable ANode)

nitc :: ASTDump :: last_parent=

Reference to the last parent in the Ordered Tree
fun length: Int

core :: Collection :: length

Number of items in the collection.
private fun line: Int

nitc :: ASTDump :: line

Current line number (when printing lines)
private fun line=(line: Int)

nitc :: ASTDump :: line=

Current line number (when printing lines)
private intern fun native_class_name: CString

core :: Object :: native_class_name

The class name of the object in CString format.
fun not_empty: Bool

core :: Collection :: not_empty

Alias for not is_empty.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun parent(e: E): nullable E

ordered_tree :: OrderedTree :: parent

The parent of the element e
private fun parents: HashMap[E, nullable E]

ordered_tree :: OrderedTree :: parents

The parent of each element.
private fun parents=(parents: HashMap[E, nullable E])

ordered_tree :: OrderedTree :: parents=

The parent of each element.
fun permutations(r: Int): Collection[SequenceRead[E]]

core :: Collection :: permutations

All r-length permutations on self (all possible ordering) without repeated elements.
fun plain_to_s: String

core :: Collection :: plain_to_s

Concatenate elements without separators
fun product(r: Int): Collection[SequenceRead[E]]

core :: Collection :: product

Cartesian product, over r times self.
fun rand: E

core :: Collection :: rand

Return a random element form the collection
fun red(s: String): String

nitc :: ASTDump :: red

s as red
fun roots: Array[E]

ordered_tree :: OrderedTree :: roots

The roots of the tree (in sequence)
protected fun roots=(roots: Array[E])

ordered_tree :: OrderedTree :: roots=

The roots of the tree (in sequence)
fun sample(length: Int): Array[E]

core :: Collection :: sample

Return a new array made of (at most) length elements randomly chosen.
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
private fun serialize_to_pure_json(v: JsonSerializer)

core :: Collection :: serialize_to_pure_json

Utility to serialize a normal Json array
fun sort_with(comparator: Comparator)

ordered_tree :: OrderedTree :: sort_with

Sort roots and other elements using a comparator method
fun sub: HashMap[E, Array[E]]

ordered_tree :: OrderedTree :: sub

The branches of the trees.
protected fun sub=(sub: HashMap[E, Array[E]])

ordered_tree :: OrderedTree :: sub=

The branches of the trees.
private fun sub_to_a(e: E, res: Array[E])

ordered_tree :: OrderedTree :: sub_to_a

private fun sub_write_to(o: Writer, e: E, prefix: String)

ordered_tree :: OrderedTree :: sub_write_to

intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun to_a: Array[E]

core :: Collection :: to_a

Build a new array from a collection
abstract fun to_concurrent: CONCURRENT

core :: Collection :: to_concurrent

Wraps self in a thread-safe collection
fun to_counter: Counter[E]

core :: Collection :: to_counter

Create and fill up a counter with the elements of `self.
fun to_curlslist: CURLSList

core :: Collection :: to_curlslist

Convert Collection[String] to CURLSList
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun to_shuffle: Array[E]

core :: Collection :: to_shuffle

Return a new array made of elements in a random order.
protected abstract fun visit(e: ANode)

nitc :: Visitor :: visit

What the visitor do when a node is visited
protected fun write_line(o: Writer, e: E, prefix: String)

ordered_tree :: OrderedTree :: write_line

Write the full line for the element e in o.
abstract fun write_to(stream: Writer)

core :: Writable :: write_to

Write itself to a stream
fun write_to_bytes: Bytes

core :: Writable :: write_to_bytes

Like write_to but return a new Bytes (may be quite large)
fun write_to_file(filepath: String)

core :: Writable :: write_to_file

Like write_to but take care of creating the file
fun write_to_string: String

core :: Writable :: write_to_string

Like write_to but return a new String (may be quite large).
fun yellow(s: String): String

nitc :: ASTDump :: yellow

s as yellow
package_diagram nitc::ASTDump ASTDump nitc::Visitor Visitor nitc::ASTDump->nitc::Visitor ordered_tree::OrderedTree OrderedTree nitc::ASTDump->ordered_tree::OrderedTree core::Object Object nitc::Visitor->core::Object core::Writable Writable ordered_tree::OrderedTree->core::Writable core::Collection Collection ordered_tree::OrderedTree->core::Collection core::Cloneable Cloneable ordered_tree::OrderedTree->core::Cloneable ...core::Object ... ...core::Object->core::Object ...core::Writable ... ...core::Writable->core::Writable ...core::Collection ... ...core::Collection->core::Collection ...core::Cloneable ... ...core::Cloneable->core::Cloneable

Ancestors

interface Cloneable

core :: Cloneable

Something that can be cloned
interface Collection[E: nullable Object]

core :: Collection

The root of the collection hierarchy.
interface Object

core :: Object

The root of the class hierarchy.
interface Writable

core :: Writable

Things that can be efficienlty written to a Writer

Parents

class OrderedTree[E: Object]

ordered_tree :: OrderedTree

Generic structure to manage and display an ordered tree
abstract class Visitor

nitc :: Visitor

Abstract standard visitor on the AST

Class definitions

nitc $ ASTDump
# A helper class to handle (print) Nit AST as an OrderedTree
class ASTDump
	super Visitor
	super OrderedTree[ANode]

	# Reference to the last parent in the Ordered Tree
	# Is used to handle the initial node parent and workaround possible inconsistent `ANode::parent`
	private var last_parent: nullable ANode = null

	# Display tokens and structural production?
	#
	# Should tokens (and structural production like AQId) be displayed?
	var display_structural: Bool

	# Display lines?
	#
	# Should each new line be displayed (numbered and in gray)?
	var display_line: Bool

	# Current line number (when printing lines)
	private var line = 0

	redef fun visit(n)
	do
		if not display_structural and n.is_structural then return
		var p = last_parent
		add(p, n)
		last_parent = n
		n.visit_all(self)
		last_parent = p
	end

	redef fun write_line(o, n, p)
	do
		if display_line then
			var ls = n.location.line_start
			var file = n.location.file
			var line = self.line
			if ls > line and file != null then
				if line == 0 then line = ls - 1
				while line < ls do
					line += 1
					o.write "{line}\t{file.get_line(line)}\n".light_gray
				end
				self.line = ls
			end
		end

		super
	end

	redef fun display(n)
	do
		return "{n.class_name} {n.dump_info(self)} @{n.location}"
	end

	# `s` as yellow
	fun yellow(s: String): String do return s.yellow

	# `s` as red
	fun red(s: String): String do return s.red
end
src/parser/parser_nodes.nit:185,1--246,3