Private
currentThe current target for the current execution.
Each execution has a unique target that stays the same during execution. When the target changes, we know that a new execution takes place and can clear the memotable.
Private
memotableA map from ParseState inputs to ParseState outputs produced by the parser, for those inputs and Continuation functions to which those outputs are to be passed.
Semantic values from input states are also used to distinguish different parsing paths to provide support for essential ambiguity
Readonly
transformerThe state transformer function that performs the parser logic.
Static
MAX_Restricts the maximum number of possible parse tree branches to the value specified.
If it is defined as Infinity, then no restriction is applied.
Runs the parser for the specified target
and optional index
and
data
asynchronously
Returns a promise that resolves to an array that contains all ParseState results produced.
A promise which resolves to an array containing all ParseState results or an error.
The complete input to be parsed.
Optional
data: DAn optional initial semantic value. Defaults to null
Optional
index: numberAn optional initial index in the target
. Defaults to 0.
Runs the parser for the specified target
, with optional index
and
data
semantic value.
It returns a Generator which will lazily generate all possible parse results from the parser execution, one by one. If the parser parses an infinitely ambiguous grammar, the generator will always produce new results.
A Generator which produces new ParseState results on each iteration.
The complete input to be parsed.
Optional
data: DAn optional initial semantic value. Defaults to null
Optional
index: numberAn optional initial index in the target
. Defaults to 0.
Runs the parser for the specified input target
, with optional index
and
data
semantic value.
Returns an array that contains all the ParseState results produced.
An array containing all ParseState results or an error.
The complete input to be parsed.
Optional
data: DAn optional initial semantic value. Defaults to null
Optional
index: numberAn optional initial index in the target
. Defaults to 0.
Static
lazyDefines a SymbolParser that will execute parserThunk
to get a parser and execute it.
It employs localised memoisation of the parser returned by parserThunk
so that it does not have to
be redefined on every execution.
It's purpose is to defer the execution of a SymbolParser constructor for later, in cases where it contains a reference to itself (i.e. for recursion) It can be used to construct recursive parsers that would otherwise could not be possible to define due to JavaScript's eager evaluation.
A new SymbolParser that will lazily execute parserThunk
's returned parser.
A function that returns a new SymbolParser.
Static
toDefines a SymbolParser that will execute a TokenParser, parser
, for it's results.
It basically promotes a TokenParser to a SymbolParser so that the former can be used in the more advanced context of generalised grammars, when the capabilities of TokenParser are not sufficient.
A new SymbolParser that will execute parser
.
The TokenParser to be promoted.
A parser that augments the capabilities of TokenParser to recognise grammars with:
It can be used to define any Generalised LL (GLL) parser
It uses a ParseStack stack structure along with localised bookeeping to provide the capabilities needed for GLL parsing. Localised Bookeeping: An alternative to the Graph Structured Stack (GSS) needed for GLL parsing. Each parser uses localised memoisation to map parse inputs to outputs produced by the parser and continuations that act on those outputs, assigned to the parser's ContinuationParseStateTransformer funtions over the execution. It also checks the ParseStack before pushing it's ContinuationParseStateTransformer, so that it does not gets executed twice for the same data. This effectively makes the parser act as a localised GSS node and eliminates the need for more centeralised data structures, while achieving the O(n^3) desired complexity the GSS data structure promises in GLL parsing
All parsers of this type resolve their parsing in O(n^3) worse time to the input. They all return one or more valid parses (ambiguous grammars have more than one valid parses) or an error. If recursive grammars are parsed, only the largest parse possible will be returned (greedy approach). Spurious ambiguity is pruned and all results with the same semantics are considered the same result. Essential ambiguity on the other hand is fully supported and if 2 results have different semantics, they will both be returned. This comes at a cost, as now the worst case rises to exponential O(2^k) complexity, where k all different results with different semantics.
Spurious ambiguity: A sentence is spuriously ambiguous if all its parse trees have the exact same semantics Essential ambiguity: A sentence is essentially ambiguous if it has at least 2 parse trees with different semantics
A constant parameter MAX_AMBIGUITY_BREADTH is employed to keep the breadth of possible tree production under control and prevent stack overflows.
Localised Memoisation is employed on the parser level to store intermediate results for specific inputs and prevent recalculations and loops that might occur. There exists an automatic flush policy on each parser where the memoisation tables will be flushed each time the target of parsing changes, where it usually means that a new parsing is requested and, thus, the old memoisation table entries are now irrelevant. This is there to prevent heap allocation issues that might occur.