new Parser(grammar [, skip])
Creates a parser;
see parser() factory method.
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
grammar |
module:EBNF~Grammar | represents grammar and states. |
|
skip |
RegExp |
<optional> |
a pattern to define ignorable character sequences,
by default white space,
must not accept empty input, must not use |
- Source:
Properties:
| Name | Type | Argument | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
scanner |
module:Base~Scanner |
<nullable> |
tokenizes input. |
||||||
tuples |
Array.<?module:Base~Tuple> | tokenized input during recognition. |
|||||||
index |
number | index of next tuple during recognition. |
|||||||
current |
module:Base~Tuple |
<nullable> |
current input tuple or |
||||||
ruleStack |
Array.<?module:EBNF:Rule> | currently activated rules during recognition. |
|||||||
grammar |
module:EBNF~Grammar | represents the grammar, counts errors; concurrent recognition will trash error counting. |
|||||||
actions |
Object.<string, module:Base~Action> |
<nullable> |
maps rule names to action functions or methods during recognition. |
||||||
data |
Object |
<nullable> |
context for all actions during recognition. Properties
|
||||||
oop |
boolean | true if |
Extends
Methods
-
act(name, result)
-
Calls an action method. Checks argument count unless
grammar.config.noargsis set or the method expects no arguments, i.e., has a rest parameter.Parameters:
Name Type Description namestring rule name to match.
resultArray list of arguments.
- Inherited From:
- Overrides:
- Source:
Returns:
action method result or unchanged
result. -
call(target, method, args)
-
Checks if argument and parameter count of a method match unless the method expects no parameters, or has a rest parameter or
grammar.config.noargsis true.Parameters:
Name Type Argument Description targetobject to apply method to.
methodfunction to check.
argsObject <repeatable>
arguments to pass.
- Inherited From:
- Overrides:
- Source:
Returns:
method result.
- Type
- Object
Example
super.method(arg1, .. argn)
this.parser.call(this, super.method, arg1, .. argn)
-
error(s)
-
Displays a message and the rule stack, if any; lets grammar count it as an error.
Parameters:
Name Type Argument Description sArray.<object> <repeatable>
message, to be displayed; prefixed by
.currentand joined by blanks.Returns:
the message.
- Type
- string
-
next(caller)
-
Advances
.indexand, therefore,.currentto the next element of.tuples, if any. Finds or createsnullas.currentto indicate end of input. Ignores illegal characters but only reports the first in a sequence. Implements lookahead trace.Parameters:
Name Type Description callerstring for trace.
-
parse(input [, actions], arg)
-
Recognizes an input sentence. Requires
grammar.expect(). Resets and reports.errorsfor the grammar.Parameters:
Name Type Argument Default Description inputstring to process.
actionsfunction | Object <optional>
null a function is assumed to be a class and a singleton is created with
thisas constructor argument. The object maps rule names to action methods.argObject <repeatable>
used as further constructor arguments.
- Overrides:
- Source:
Throws:
-
error message, also reported by
parser.error(). - Type
- string
Returns:
the collected sequence of values or the value produced by the action of the start rule. The parsing methods return the following types, where
objectrefers to the result produced by the action of a rule.class returns LitstringTokenstringAltArrayOptnull|ArraySeqArraySomeArray<Array>RuleArray|objectNTArray|object- Type
- Array | Object