Fenced code blocks parser

Introduced properties

protected fun block=(block: BLOCK)

markdown2 :: MdFencedCodeBlockParser :: block=

init defaultinit(line_start: Int, column_start: Int, content_offset: Int, fence_char: Char, fence_length: Int, fence_indent: Int)

markdown2 :: MdFencedCodeBlockParser :: defaultinit

protected fun fence_char=(fence_char: Char)

markdown2 :: MdFencedCodeBlockParser :: fence_char=

Fence character
protected fun fence_indent=(fence_indent: Int)

markdown2 :: MdFencedCodeBlockParser :: fence_indent=

Fence indent
protected fun fence_length=(fence_length: Int)

markdown2 :: MdFencedCodeBlockParser :: fence_length=

Fence length
fun first_line: nullable String

markdown2 :: MdFencedCodeBlockParser :: first_line

Fence first line
protected fun first_line=(first_line: nullable String)

markdown2 :: MdFencedCodeBlockParser :: first_line=

Fence first line
protected fun other_lines=(other_lines: Buffer)

markdown2 :: MdFencedCodeBlockParser :: other_lines=

Fence other lines

Redefined properties

redef type BLOCK: MdFencedCodeBlock

markdown2 $ MdFencedCodeBlockParser :: BLOCK

Kind of block under construction
redef type SELF: MdFencedCodeBlockParser

markdown2 $ MdFencedCodeBlockParser :: SELF

Type of this instance, automatically specialized in every class
redef fun add_line(line: String)

markdown2 $ MdFencedCodeBlockParser :: add_line

Add line to the current block
redef fun block: BLOCK

markdown2 $ MdFencedCodeBlockParser :: block

MdBlock under construction
redef fun finalize(parser: MdParser)

markdown2 $ MdFencedCodeBlockParser :: finalize

Finalize the current block
redef fun try_continue(state: MdParser): nullable MdBlockContinue

markdown2 $ MdFencedCodeBlockParser :: try_continue

Can self continue from the current index in parser?

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 BLOCK: MdBlock

markdown2 :: MdBlockParser :: BLOCK

Kind of block under construction
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
fun add_line(line: String)

markdown2 :: MdBlockParser :: add_line

Add line to the current block
abstract fun block: BLOCK

markdown2 :: MdBlockParser :: block

MdBlock under construction
protected fun block=(block: BLOCK)

markdown2 :: MdFencedCodeBlockParser :: block=

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.
protected fun column_start=(column_start: Int)

markdown2 :: MdBlockParser :: column_start=

Column start
fun content_offset: Int

markdown2 :: MdBlockParser :: content_offset

Column where the content starts
protected fun content_offset=(content_offset: Int)

markdown2 :: MdBlockParser :: content_offset=

Column where the content starts
init defaultinit(line_start: Int, column_start: Int, content_offset: Int)

markdown2 :: MdBlockParser :: defaultinit

init defaultinit(line_start: Int, column_start: Int, content_offset: Int, fence_char: Char, fence_length: Int, fence_indent: Int)

markdown2 :: MdFencedCodeBlockParser :: defaultinit

protected fun fence_char=(fence_char: Char)

markdown2 :: MdFencedCodeBlockParser :: fence_char=

Fence character
protected fun fence_indent=(fence_indent: Int)

markdown2 :: MdFencedCodeBlockParser :: fence_indent=

Fence indent
protected fun fence_length=(fence_length: Int)

markdown2 :: MdFencedCodeBlockParser :: fence_length=

Fence length
fun finalize(parser: MdParser)

markdown2 :: MdBlockParser :: finalize

Finalize the current block
fun first_line: nullable String

markdown2 :: MdFencedCodeBlockParser :: first_line

Fence first line
protected fun first_line=(first_line: nullable String)

markdown2 :: MdFencedCodeBlockParser :: first_line=

Fence first line
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 initialize(parser: MdParser)

markdown2 :: MdBlockParser :: initialize

Initialize the current block
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.
protected fun line_start=(line_start: Int)

markdown2 :: MdBlockParser :: line_start=

Line Start
fun location: MdLocation

markdown2 :: MdBlockParser :: location

Location at start
protected fun location=(location: MdLocation)

markdown2 :: MdBlockParser :: location=

Location at start
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
protected fun other_lines=(other_lines: Buffer)

markdown2 :: MdFencedCodeBlockParser :: other_lines=

Fence other lines
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 parse_inlines(inline_parser: MdInlineParser)

markdown2 :: MdBlockParser :: parse_inlines

Parse block lines
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.
abstract fun try_continue(state: MdParser): nullable MdBlockContinue

markdown2 :: MdBlockParser :: try_continue

Can self continue from the current index in parser?
package_diagram markdown2::MdFencedCodeBlockParser MdFencedCodeBlockParser markdown2::MdBlockParser MdBlockParser markdown2::MdFencedCodeBlockParser->markdown2::MdBlockParser core::Object Object markdown2::MdBlockParser->core::Object ...core::Object ... ...core::Object->core::Object

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

abstract class MdBlockParser

markdown2 :: MdBlockParser

Parser for a specific block node

Class definitions

markdown2 $ MdFencedCodeBlockParser
# Fenced code blocks parser
class MdFencedCodeBlockParser
	super MdBlockParser

	redef type BLOCK: MdFencedCodeBlock
	redef var block = new MdFencedCodeBlock(location, fence_char, fence_length, fence_indent) is lazy

	# Fence character
	var fence_char: Char

	# Fence length
	var fence_length: Int

	# Fence indent
	var fence_indent: Int

	# Fence first line
	var first_line: nullable String = null

	# Fence other lines
	var other_lines = new Buffer

	redef fun try_continue(state) do
		var next_non_space = state.next_non_space_index
		var new_index = state.index
		var line = state.line_string

		if state.indent <= 3 and next_non_space < line.length and
		   line.chars[next_non_space] == fence_char then

			var match = line.substring(next_non_space, line.length - next_non_space).
				search(re_closing_fence)
			if match != null and match.subs[0].as(not null).length >= fence_length then
				# closing fence - we're at end of line, so we can finalize now
				return new MdBlockContinue.finished
			end
		end

		# skip optional spaces of fence indent
		var i = fence_indent
		while i > 0 and new_index < line.length and line.chars[new_index] == ' ' do
			new_index += 1
			i -= 1
		end

		return new MdBlockContinue.at_index(new_index)
	end

	redef fun add_line(line) do
		if first_line == null then
			first_line = line
		else
			other_lines.append(line)
			other_lines.add '\n'
		end
	end

	redef fun finalize(parser) do
		super

		# first line become info string
		var first_line = self.first_line
		if first_line != null then
			var info = first_line.trim.unescape_string
			if not info.is_empty then block.info = info
		end

		var content = other_lines.to_s
		block.literal =  content

		var lines = content.split("\n")
		location.line_end = location.line_start + lines.length
		location.column_end = content_offset + fence_indent + fence_length
	end
end
lib/markdown2/markdown_block_parsing.nit:843,1--917,3