Introduced properties

private fun executor=(executor: NitUnitExecutor)

nitc :: NitunitMdVisitor :: executor=

private fun new_docunit: DocUnit

nitc :: NitunitMdVisitor :: new_docunit

Return and register a new empty docunit
private fun parse_code(block: MdCodeBlock)

nitc :: NitunitMdVisitor :: parse_code

Redefined properties

redef type SELF: NitunitMdVisitor

nitc $ NitunitMdVisitor :: SELF

Type of this instance, automatically specialized in every class
redef fun visit(node: MdNode)

nitc $ NitunitMdVisitor :: visit

Visit node

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 SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
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.
fun enter_visit(node: MdNode)

markdown2 :: MdVisitor :: enter_visit

Start visiting node
private fun executor=(executor: NitUnitExecutor)

nitc :: NitunitMdVisitor :: executor=

fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
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".
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.
private intern fun native_class_name: CString

core :: Object :: native_class_name

The class name of the object in CString format.
private fun new_docunit: DocUnit

nitc :: NitunitMdVisitor :: new_docunit

Return and register a new empty docunit
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).
private fun parse_code(block: MdCodeBlock)

nitc :: NitunitMdVisitor :: parse_code

fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
protected abstract fun visit(node: MdNode)

markdown2 :: MdVisitor :: visit

Visit node
package_diagram nitc::testing_doc::NitunitMdVisitor NitunitMdVisitor markdown2::MdVisitor MdVisitor nitc::testing_doc::NitunitMdVisitor->markdown2::MdVisitor core::Object Object markdown2::MdVisitor->core::Object ...core::Object ... ...core::Object->core::Object

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

interface MdVisitor

markdown2 :: MdVisitor

A visitor for Markdown AST

Class definitions

nitc $ NitunitMdVisitor
private class NitunitMdVisitor
	super MdVisitor

	var executor: NitUnitExecutor

	redef fun visit(node) do node.accept_nitunit(self)

	fun parse_code(block: MdCodeBlock) do
		var code = block.literal
		if code == null then return

		var meta = block.info or else "nit"
		# Do not try to test non-nit code.
		if meta != "nit" then return

		# Try to parse code blocks
		var executor = self.executor
		var ast = executor.toolcontext.parse_something(code)

		var mdoc = executor.mdoc
		assert mdoc != null

		# Skip pure comments
		if ast isa TComment then return

		# The location is computed according to the starts of the mdoc and the block
		# Note, the following assumes that all the comments of the mdoc are correctly aligned.
		var loc = block.location
		var line_offset = loc.line_start + mdoc.location.line_start - 2
		var column_offset = loc.column_start + mdoc.location.column_start
		# Hack to handle precise location in blocks
		# TODO remove when markdown is more reliable
		if block isa MdFencedCodeBlock then
			# Skip the starting fence
			line_offset += 1
		else
			# Account a standard 4 space indentation
			column_offset += 4
		end

		# We want executable code
		if not (ast isa AModule or ast isa ABlockExpr or ast isa AExpr) then
			var message
			var l = ast.location
			# Get real location of the node (or error)
			var location = new Location(mdoc.location.file,
				l.line_start + line_offset,
				l.line_end + line_offset,
				l.column_start + column_offset,
				l.column_end + column_offset)
			if ast isa AError then
				message = ast.message
			else
				message = "Error: Invalid Nit code."
			end

			var du = new_docunit
			du.block += code
			du.error_location = location
			du.error = message
			executor.toolcontext.modelbuilder.failed_entities += 1
			return
		end

		# Create a first block
		# Or create a new block for modules that are more than a main part
		var last_docunit = executor.last_docunit
		if last_docunit == null or ast isa AModule then
			last_docunit = new_docunit
			executor.last_docunit = last_docunit
		end

		# Add it to the file
		last_docunit.block += code

		# In order to retrieve precise positions,
		# the real position of each line of the raw_content is stored.
		# See `DocUnit::real_location`
		line_offset -= loc.line_start - 1
		for i in [loc.line_start..loc.line_end] do
			last_docunit.lines.add i + line_offset
			last_docunit.columns.add column_offset
		end
	end

	# Return and register a new empty docunit
	fun new_docunit: DocUnit do
		var mdoc = executor.mdoc
		assert mdoc != null

		var next_number = 1
		var name = executor.xml_name
		if executor.docunits.not_empty and executor.docunits.last.mdoc == mdoc then
			next_number = executor.docunits.last.number + 1
			name += "#" + next_number.to_s
		end

		var res = new DocUnit(mdoc, next_number, "", executor.xml_classname, name)
		executor.docunits.add res
		executor.toolcontext.modelbuilder.unit_entities += 1
		return res
	end
end
src/testing/testing_doc.nit:348,1--450,3