Rule(Df)
A nestable parsing rule
Constructor
new Rule(Df)
Creates a rule instance with the options in the specified object.
Parameters:
Name | Type | Default | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Df |
object | null | The rule definition object that contains the options as its properties.
Definition objects can be nested.
A nested definition is interpreted as a sub-rule.
The property name for a nested definition must start with Available Options:Properties
|
Extends
CompositeMembers
staticconstantINHERIT Symbol
The enum for rule properties, which means the actual property value inherits from the parent rule
readonlyancestors Array.<Composite>
The ancestor composites ordered by closest to furthest
- Overrides:
- Composite#ancestors
- Source:
- Composite.js, line 43
encoding string
The encoding to decode buffers. Falls back to 'utf8'
end RegExp
The end pattern
endsWithParent boolean
Whether the current context can also be ended by the parent context rule
from RegExp
The start pattern
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
isRecursive boolean
Whether this rule is recursive
readonlylength number
The number of child composites
- Overrides:
- Composite#length
- Source:
- Composite.js, line 69
name string
The name of this rule
onActive function
The event handler which is called every time the parser reached at Rule#splitter
onEnd function
The event handler which is called when this rule is deactivated
onOutline function
Debug purpose only. The callback which runs when Context#outline is called
onStart function
The event handler which is called when this rule is activated
readonlyparent Composite
The parent composite
- Overrides:
- Composite#parent
- Source:
- Composite.js, line 34
readonlyroot Composite
The root of composition
- Overrides:
- Composite#root
- Source:
- Composite.js, line 58
splitter stringRegExp
The chunk splitter
start RegExp
The start pattern
to RegExp
The end pattern
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
endsWith(Chunk) → mixed
Performs matching the specified chunk with the end pattern
Parameters:
Name | Type | Description |
---|---|---|
Chunk |
string | The chunk to match |
Returns:
The matching result
- Type:
- mixed
express(Cx) → string
Expresses a context. Debug purpose only.
Parameters:
Name | Type | Description |
---|---|---|
Cx |
Context | The context to express |
Returns:
- Type:
- string
fin(Cx, Chunk, MatchResult) → boolean
Finalizes a context
Parameters:
Name | Type | Default | Description |
---|---|---|---|
Cx |
Context | The context to finalize |
|
Chunk |
string | '' | The chunk that matched with the |
MatchResult |
Array.<string> | null | The maching result of the |
Returns:
Result of fin
callback.
If fin
is not specified, true
will be returned
- Type:
- boolean
init(Cx, Chunk, MatchResult) → boolean
Initializes a context
Parameters:
Name | Type | Default | Description |
---|---|---|---|
Cx |
Context | The context to initialize |
|
Chunk |
string | '' | The chunk that matched with the |
MatchResult |
Array.<string> | null | The matching result of the |
Returns:
The result of init
callback.
If init
is not specified, true
will be returned
- Type:
- boolean
on(Ev, Fn)
Sets an event handler
Parameters:
Name | Type | Description |
---|---|---|
Ev |
string | The event identifier Available Events:
|
Fn |
function | The event handler.
Returning Parameters:Properties |
parse(Cx, Chunk) → boolean
Parses a chunk
Parameters:
Name | Type | Default | Description |
---|---|---|---|
Cx |
Context | The current context |
|
Chunk |
string | '' | The chunk to parse |
Returns:
The result of parse
callback.
If parse
is not specified, true
will be returned
- Type:
- boolean
startsWith(Chunk) → mixed
Performs matching the specified chunk with the start pattern
Parameters:
Name | Type | Description |
---|---|---|
Chunk |
string | The chunk to match |
Returns:
The matching result
- Type:
- mixed
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
verifyChild(Cp) → booleanstring
Determines whether the specified composite can be added as a child
Parameters:
Name | Type | Description |
---|---|---|
Cp |
Composite | The composite which is about to be added |
- Overrides:
- Composite#verifyChild
- Source:
- Composite.js, line 80
Returns:
true
if Cp
is valid. Any type other than true
means invalid.
If a string is returned, it is shown as an error message in the debug console
- Type:
- boolean | string