Context

Context

A parsing context

Constructor

new Context(Rl, Manager)

Source:
Parameters:
Name Type Default Description
Rl Rule

The rule that determines the behavior of this context

Manager ContextManager null

The manager that controls this context

Extends

Members

(static, readonly) ACTIVE :Symbol

An enum for Context#state which means the context is active

Source:
Type:
  • Symbol

(static, readonly) BACKGROUND :Symbol

An enum for Context#state. When a sub-context gets activated, the parent context goes this state

Source:
Type:
  • Symbol

(static, readonly) FINISHED :Symbol

An enum for Context#state which means the context has been deactivated

Source:
Type:
  • Symbol

(static, readonly) STANDBY :Symbol

An enum for Context#state which means the context is waiting for being activated

Source:
Type:
  • Symbol

(static, readonly) WASTED :Symbol

An enum for Context#state which means the context has no longer chance of getting activated

Source:
Type:
  • Symbol

(readonly) ancestors :Array.<Composite>

The ancestor composites ordered by closest to furthest

Inherited From:
Source:
Type:

data :mixed

The data object

Default Value:
  • {}
Source:
Type:
  • mixed

(readonly) hasChild :boolean

Whether this has one or more child composites

Inherited From:
Source:
Type:
  • boolean

(readonly) hasParent :boolean

Whether this has parent composite

Inherited From:
Source:
Type:
  • boolean

(readonly) length :number

The number of child composites

Inherited From:
Source:
Type:
  • number

manager :ContextManager

The manager that is controlling this context

Source:
Type:

next :Context

The next context

Source:
Type:

nextState :Symbol

The next state which this context is about to change to

Source:
Type:
  • Symbol

(readonly) parent :Composite

The parent composite

Inherited From:
Source:
Type:

prev :Context

The previous context

Source:
Type:

(readonly) results :ResultSet

The parsing results

Source:
Type:

(readonly) root :Composite

The root of composition

Inherited From:
Source:
Type:

(readonly) rule :Rule

The rule that determines the behavior of this context

Source:
Type:

(readonly) state :Symbol

The current state

Default Value:
  • Context.STANDBY
Source:
Type:
  • Symbol

Methods

addChild(Cp) → {Composite}

Adds a child composite

Inherited From:
Source:
Parameters:
Name Type Description
Cp Composite

The composite to add as a child

Returns:
Type:
Composite

This

addChildren(Cps) → {Composite}

Adds multiple child composites

Inherited From:
Source:
Parameters:
Name Type Description
Cps Array.<Composite>

The array of the composites to add

Returns:
Type:
Composite

This

cleanupChildren(Recursive) → {Array.<Context>}

Removes all the unnecessary children

Source:
Parameters:
Name Type Default Description
Recursive boolean false

Whether or not to perform recursively

Returns:
Type:
Array.<Context>

An array of removed contexts

(protected) clearBuffer()

Clears internal reading buffer

Source:

end()

Deactivates this context

Source:

outline(Indent, Level) → {string}

Returns the outlined string for debug

Source:
Parameters:
Name Type Default Description
Indent string '

' The indentation string

Level number 0

The indentation level

Returns:
Type:
string

The outlined string

parseChunk(Chunk)

Applies the rule to a chunk

Source:
Parameters:
Name Type Description
Chunk string

Chunk to apply the rule

(protected) populate()

Populates sub-contexts

Source:

start()

Activates this context

Source:

step(Byte) → {boolean}

Pushes a single byte into the internal reading buffer. And if the buffer reached at the chunk splitter (default: '\n'), passes the buffer to parseChunk().

Source:
Parameters:
Name Type Description
Byte Buffer

The byte to push into the buffer

Returns:
Type:
boolean

true if the buffer reached at the chunk splitter. Otherwise false

traverse(Fn, Depth, Arg) → {boolean}

Performs tree traversal

Inherited From:
Source:
Parameters:
Name Type Default Description
Fn function

The callback that receives every descendant composite as the 1st parameter. If false is returned, the traversal will be aborted. The returned value other than false will be passed to the next traversal call of Fn as the 2nd parameter

Depth number -1

The limit of traversal depth. Negative number means no-limit

Arg mixed null

Additinal argument to pass to Fn as the 2nd parameter.

Returns:
Type:
boolean

true if the traversal is successfully completed. false if the traversal is aborted

updateState(Recursive)

Updates the state

Source:
Parameters:
Name Type Default Description
Recursive boolean false

Whether or not to perform recursively

verifyChild(Cx)

Overrides:
Source:
Parameters:
Name Type Description
Cx Context

The context to verify