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:
|
Extends
Members
(static, constant) INHERIT :Symbol
The enum for rule properties, which means the actual property value inherits from the parent rule
Type:
-
Symbol
(readonly) ancestors :Array.<Composite>
The ancestor composites ordered by closest to furthest
- Inherited From:
- Source:
Type:
-
Array.<Composite>
encoding :string
The encoding to decode buffers. Falls back to 'utf8'
Type:
-
string
end :RegExp
The end pattern
Type:
-
RegExp
endsWithParent :boolean
Whether the current context can also be ended by the parent context rule
Type:
-
boolean
(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
isRecursive :boolean
Whether this rule is recursive
Type:
-
boolean
(readonly) length :number
The number of child composites
- Inherited From:
- Source:
Type:
-
number
onActive :function
The event handler which is called every time the parser reached at Rule#splitter
Type:
-
function
onEnd :function
The event handler which is called when this rule is deactivated
Type:
-
function
onOutline :function
Debug purpose only. The callback which runs when Context#outline is called
Type:
-
function
onStart :function
The event handler which is called when this rule is activated
Type:
-
function
splitter :string|RegExp
The chunk splitter
Type:
-
string
|RegExp
start :RegExp
The start pattern
Type:
-
RegExp
Methods
addChild(Cp) → {Composite}
Adds a child composite
- Inherited From:
- Source:
Parameters:
Name | Type | Description |
---|---|---|
Cp |
Composite
|
The composite to add as a child |
addChildren(Cps) → {Composite}
Adds multiple child composites
- Inherited From:
- Source:
Parameters:
Name | Type | Description |
---|---|---|
Cps |
Array.<Composite>
|
The array of the composites to add |
endsWith(Chunk) → {mixed}
Performs matching the specified chunk with the end pattern
Parameters:
Name | Type | Description |
---|---|---|
Chunk |
string
|
The chunk to match |
Returns:
- Type:
-
mixed
The matching result
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:
- Type:
-
boolean
Result of fin
callback.
If fin
is not specified, true
will be returned
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:
- Type:
-
boolean
The result of init
callback.
If init
is not specified, true
will be returned
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:
|
parse(Cx, Chunk) → {boolean}
Parses a chunk
Parameters:
Name | Type | Default | Description |
---|---|---|---|
Cx |
Context
|
The current context |
|
Chunk |
string
|
'' |
The chunk to parse |
Returns:
- Type:
-
boolean
The result of parse
callback.
If parse
is not specified, true
will be returned
startsWith(Chunk) → {mixed}
Performs matching the specified chunk with the start pattern
Parameters:
Name | Type | Description |
---|---|---|
Chunk |
string
|
The chunk to match |
Returns:
- Type:
-
mixed
The matching result
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 |
|
Depth |
number
|
-1 |
The limit of traversal depth. Negative number means no-limit |
Arg |
mixed
|
null |
Additinal argument to pass to |
Returns:
- Type:
-
boolean
true
if the traversal is successfully completed.
false
if the traversal is aborted
verifyChild(Cp) → {boolean|string}
Determines whether the specified composite can be added as a child
- Inherited From:
- Source:
Parameters:
Name | Type | Description |
---|---|---|
Cp |
Composite
|
The composite which is about to be added |
Returns:
- Type:
-
boolean
|string
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