A abstract lexer engine generated by nitcc

Introduced properties

fun col_start: Int

nitcc_runtime :: Lexer :: col_start

Cursor current column (in chars, starting from 1)
protected fun col_start=(col_start: Int)

nitcc_runtime :: Lexer :: col_start=

Cursor current column (in chars, starting from 1)
fun lex: CircularArray[NToken]

nitcc_runtime :: Lexer :: lex

Lexize a stream of characters and return a sequence of tokens
fun line_start: Int

nitcc_runtime :: Lexer :: line_start

Cursor current line (starting from 1)
protected fun line_start=(line_start: Int)

nitcc_runtime :: Lexer :: line_start=

Cursor current line (starting from 1)
fun next_token: nullable NToken

nitcc_runtime :: Lexer :: next_token

Move the cursor and return the next token.
fun pos_start: Int

nitcc_runtime :: Lexer :: pos_start

Cursor current position (in chars, starting from 0)
protected fun pos_start=(pos_start: Int)

nitcc_runtime :: Lexer :: pos_start=

Cursor current position (in chars, starting from 0)
protected abstract fun start_state: DFAState

nitcc_runtime :: Lexer :: start_state

The stating state for lexing
fun stream: String

nitcc_runtime :: Lexer :: stream

The input stream of characters
protected fun stream=(stream: String)

nitcc_runtime :: Lexer :: stream=

The input stream of characters

Redefined properties

redef type SELF: Lexer

nitcc_runtime $ Lexer :: SELF

Type of this instance, automatically specialized in every class

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 col_start: Int

nitcc_runtime :: Lexer :: col_start

Cursor current column (in chars, starting from 1)
protected fun col_start=(col_start: Int)

nitcc_runtime :: Lexer :: col_start=

Cursor current column (in chars, starting from 1)
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.
fun lex: CircularArray[NToken]

nitcc_runtime :: Lexer :: lex

Lexize a stream of characters and return a sequence of tokens
fun line_start: Int

nitcc_runtime :: Lexer :: line_start

Cursor current line (starting from 1)
protected fun line_start=(line_start: Int)

nitcc_runtime :: Lexer :: line_start=

Cursor current line (starting from 1)
fun next_token: nullable NToken

nitcc_runtime :: Lexer :: next_token

Move the cursor and return the next token.
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 pos_start: Int

nitcc_runtime :: Lexer :: pos_start

Cursor current position (in chars, starting from 0)
protected fun pos_start=(pos_start: Int)

nitcc_runtime :: Lexer :: pos_start=

Cursor current position (in chars, starting from 0)
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
protected abstract fun start_state: DFAState

nitcc_runtime :: Lexer :: start_state

The stating state for lexing
fun stream: String

nitcc_runtime :: Lexer :: stream

The input stream of characters
protected fun stream=(stream: String)

nitcc_runtime :: Lexer :: stream=

The input stream of characters
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.
package_diagram nitcc_runtime::Lexer Lexer core::Object Object nitcc_runtime::Lexer->core::Object

Parents

interface Object

core :: Object

The root of the class hierarchy.

Class definitions

nitcc_runtime $ Lexer
# A abstract lexer engine generated by nitcc
abstract class Lexer
	# The input stream of characters
	var stream: String

	# The stating state for lexing
	# Used by generated parsers
	protected fun start_state: DFAState is abstract

	# Lexize a stream of characters and return a sequence of tokens
	fun lex: CircularArray[NToken]
	do
		var res = new CircularArray[NToken]
		loop
			var t = next_token
			if t != null then res.add t
			if t isa NEof or t isa NError then break
		end
		return res
	end

	# Cursor current position (in chars, starting from 0)
	var pos_start = 0

	# Cursor current line (starting from 1)
	var line_start = 1

	# Cursor current column (in chars, starting from 1)
	var col_start = 1

	# Move the cursor and return the next token.
	#
	# Returns a `NEof` and the end.
	# Returns `null` if the token is ignored.
	fun next_token: nullable NToken
	do
		var state = start_state
		var pos = pos_start
		var pos_end = pos_start - 1
		var line = line_start
		var line_end = line_start - 1
		var col = col_start
		var col_end = col_start - 1
		var last_state: nullable DFAState = null
		var text = stream
		var length = text.length
		loop
			if state.is_accept then
				pos_end = pos - 1
				line_end = line
				col_end = col
				last_state = state
			end
			var c
			var next
			if pos >= length then
				c = '\0'
				next = null
			else
				c = text.chars[pos]
				next = state.trans(c)
			end
			if next == null then
				var token
				if pos_start < length then
					if last_state == null then
						token = new NLexerError
						var position = new Position(pos_start, pos, line_start, line, col_start, col)
						token.position = position
						token.text = text.substring(pos_start, pos-pos_start+1)
					else if not last_state.is_ignored then
						var position = new Position(pos_start, pos_end, line_start, line_end, col_start, col_end)
						token = last_state.make_token(position, text)
					else
						token = null
					end
				else
					token = new NEof
					var position = new Position(pos, pos, line, line, col, col)
					token.position = position
					token.text = ""
				end
				pos_start = pos_end + 1
				line_start = line_end
				col_start = col_end

				return token
			end
			state = next
			pos += 1
			col += 1
			if c == '\n' then
				line += 1
				col = 1
			end
		end
	end
end
lib/nitcc_runtime/nitcc_runtime.nit:157,1--254,3