Context(Rl, Manager)
A parsing context
Constructor
new Context(Rl, Manager)
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 |
- Source:
- Context.js, line 15
Extends
CompositeMembers
staticconstantACTIVE Symbol
An enum for Context#state which means the context is active
- Source:
- Context.js, line 50
staticconstantBACKGROUND Symbol
An enum for Context#state. When a sub-context gets activated, the parent context goes this state
- Source:
- Context.js, line 60
staticconstantFINISHED Symbol
An enum for Context#state which means the context has been deactivated
- Source:
- Context.js, line 70
staticconstantSTANDBY Symbol
An enum for Context#state which means the context is waiting for being activated
- Source:
- Context.js, line 40
staticconstantWASTED Symbol
An enum for Context#state which means the context has no longer chance of getting activated
- Source:
- Context.js, line 80
readonlyancestors Array.<Composite>
The ancestor composites ordered by closest to furthest
- Overrides:
- Composite#ancestors
- Source:
- Composite.js, line 43
data mixed
The data object
- Default Value:
- {}
- Source:
- Context.js, line 143
readonlyhasChild boolean
Whether this has one or more child composites
- Overrides:
- Composite#hasChild
- Source:
- Composite.js, line 25
readonlyhasParent boolean
Whether this has parent composite
- Overrides:
- Composite#hasParent
- Source:
- Composite.js, line 16
readonlylength number
The number of child composites
- Overrides:
- Composite#length
- Source:
- Composite.js, line 69
manager ContextManager
The manager that is controlling this context
- Source:
- Context.js, line 97
next Context
The next context
- Source:
- Context.js, line 168
nextState Symbol
The next state which this context is about to change to
- Source:
- Context.js, line 121
readonlyparent Composite
The parent composite
- Overrides:
- Composite#parent
- Source:
- Composite.js, line 34
prev Context
The previous context
- Source:
- Context.js, line 155
readonlyresults ResultSet
The parsing results
- Source:
- Context.js, line 134
readonlyroot Composite
The root of composition
- Overrides:
- Composite#root
- Source:
- Composite.js, line 58
readonlyrule Rule
The rule that determines the behavior of this context
- Source:
- Context.js, line 89
readonlystate Symbol
The current state
- Default Value:
- Context.STANDBY
- Source:
- Context.js, line 113
Methods
addChild(Cp) → Composite
Adds a child composite
Parameters:
Name | Type | Description |
---|---|---|
Cp |
Composite | The composite to add as a child |
- Overrides:
- Composite#addChild
- Source:
- Composite.js, line 89
Returns:
This
- Type:
- Composite
addChildren(Cps) → Composite
Adds multiple child composites
Parameters:
Name | Type | Description |
---|---|---|
Cps |
Array.<Composite> | The array of the composites to add |
- Overrides:
- Composite#addChildren
- Source:
- Composite.js, line 106
Returns:
This
- Type:
- Composite
cleanupChildren(Recursive) → Array.<Context>
Removes all the unnecessary children
Parameters:
Name | Type | Default | Description |
---|---|---|---|
Recursive |
boolean | false | Whether or not to perform recursively |
- Source:
- Context.js, line 225
Returns:
An array of removed contexts
- Type:
- Array.<Context>
protectedclearBuffer()
Clears internal reading buffer
- Source:
- Context.js, line 191
end()
Deactivates this context
- Source:
- Context.js, line 356
outline(Indent, Level) → string
Returns the outlined string for debug
Parameters:
Name | Type | Default | Description |
---|---|---|---|
Indent |
string | 2-spaces | The indentation string |
Level |
number | 0 | The indentation level |
- Source:
- Context.js, line 389
Returns:
The outlined string
- Type:
- string
parseChunk(Chunk)
Applies the rule to a chunk
Parameters:
Name | Type | Description |
---|---|---|
Chunk |
string | Chunk to apply the rule |
- Source:
- Context.js, line 309
protectedpopulate()
Populates sub-contexts
- Source:
- Context.js, line 199
start()
Activates this context
- Source:
- Context.js, line 338
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()
.
Parameters:
Name | Type | Description |
---|---|---|
Byte |
Buffer | The byte to push into the buffer |
- Source:
- Context.js, line 251
Returns:
true
if the buffer reached at the chunk splitter.
Otherwise false
- Type:
- boolean
traverse(Fn, Depth, Arg) → boolean
Performs tree traversal
Parameters:
Name | Type | Default | Description |
---|---|---|---|
Fn |
function | The callback that receives every descendant composite as the 1st parameter.
If |
|
Depth |
number | -1 | The limit of traversal depth. Negative number means no-limit |
Arg |
mixed | null | Additinal argument to pass to |
- Overrides:
- Composite#traverse
- Source:
- Composite.js, line 125
Returns:
true
if the traversal is successfully completed.
false
if the traversal is aborted
- Type:
- boolean
updateState(Recursive)
Updates the state
Parameters:
Name | Type | Default | Description |
---|---|---|---|
Recursive |
boolean | false | Whether or not to perform recursively |
- Source:
- Context.js, line 208
verifyChild(Cx)
Parameters:
Name | Type | Description |
---|---|---|
Cx |
Context | The context to verify |
- Overrides:
- Composite#verifyChild
- Source:
- Context.js, line 181