An interface that requires an identity getter or a readonly property of string type.
If a semantic value or error value is provided, it is required to implement this interface so that
parse outcomes can be mapped with a single string key.
The identity property is heavily used for localised memoisation to provide deep equality
checks across ParseState objects and not rely on reference cheks by the === operator.
This is done because a ParseState with the same results can be produced multiple times from
different parsers and must only be memoised once for maximum performance.
It is also required when dealing with semantic data and ambiguity where it is necessary to ensure
correctness of the memoisation algorithm.
If no ambiguity is required, that is, semantic values should not distinguish parse outcomes,
then it is suggested to use an empty string for the identity value:
{ identity: '', }
(If no semantic data is null, it is like implementing Identifiable with an empty identity property)
If maximum essential ambiguity is required, that is, to match every single alternative structure
for semantic data, then it is suggested to use JSON.stringify for the identity value:
An interface that requires an identity getter or a readonly property of string type.
If a semantic value or error value is provided, it is required to implement this interface so that parse outcomes can be mapped with a single string key.
Both ParseResult and ParseError from ParseState implement this interface to ensure that all of them are identifiable.
The identity property is heavily used for localised memoisation to provide deep equality checks across ParseState objects and not rely on reference cheks by the === operator. This is done because a ParseState with the same results can be produced multiple times from different parsers and must only be memoised once for maximum performance. It is also required when dealing with semantic data and ambiguity where it is necessary to ensure correctness of the memoisation algorithm.
If no ambiguity is required, that is, semantic values should not distinguish parse outcomes, then it is suggested to use an empty string for the identity value:
(If no semantic data is null, it is like implementing Identifiable with an empty identity property)
If maximum essential ambiguity is required, that is, to match every single alternative structure for semantic data, then it is suggested to use JSON.stringify for the identity value:
It is suggested that you use one of the defined semantics types provided with the library including:
See