Home > @activeviam/activeui-sdk > NodeMatcher
NodeMatcher interface
Create this with NodeMatcherFactory to get a fluent API for matching nodes in a parsed statement.
Signature:
export interface NodeMatcher
Remarks
See the NodeMatcherFactory documentation for examples.
Most methods on this object return another NodeMatcher, so you can chain them to perform multiple checks on a node and its children. The results of each match are ANDed together; for OR conditions, use the .or() method.
There are methods to match against attributes of the node, such as .isFunction('Generate'), or against children of the node, such as .subArg(0, firstArgMatcher => firstArgMatcher.isScalar()). If the method you want is not defined, you can match against whatever property of a node you want within a .customMatch call.
At the end of the chain, call .matches() to get a boolean result. If you need more information about the match success or failure, call .matchDetails() on the NodeMatcher.
A NodeMatcher is stateless. You can save a partially-constructed NodeMatcher and construct two different matchers based on it.
Properties
| Property | Type | Description |
|---|---|---|
| containsArgs | (...expectedArgsCallbacks: NodeMatcherTransformer[]) => NodeMatcher | |
| customMatch | (nodeShouldMatchCallback: (a: MdxNode, b?: NodeMatcher) => boolean) => NodeMatcher | |
| hasNArguments | (n: number) => NodeMatcher | |
| hasNCases | (n: number) => NodeMatcher | |
| isCase | () => NodeMatcher | |
| isCompoundIdentifier | () => NodeMatcher | |
| isFunction | (...names: string[]) => NodeMatcher | |
| isLevelCompoundIdentifier | () => NodeMatcher | |
| isLiteral | () => NodeMatcher | |
| isMeasure | () => NodeMatcher | |
| isNegativeNumber | () => NodeMatcher | |
| isNull | () => NodeMatcher | |
| isNumber | () => NodeMatcher | |
| isPositiveNumber | () => NodeMatcher | |
| isScalar | () => NodeMatcher | |
| isString | () => NodeMatcher | |
| isWhen | () => NodeMatcher | |
| matchDetails | () => { matchFailReason: string | null; node: MdxNode; } | |
| matches | () => boolean | |
| or | () => NodeMatcher | |
| subArg | (argN: number, argMatcherCallback: NodeMatcherTransformer) => NodeMatcher | |
| subCase | (caseN: number, caseMatcherCallback: NodeMatcherTransformer) => NodeMatcher | |
| subElse | (elseCaseMatcherCallback: NodeMatcherTransformer) => NodeMatcher | |
| subEveryArg | (argMatcherCallback: NodeMatcherTransformer) => NodeMatcher | |
| subThen | (thenMatcherCallback: NodeMatcherTransformer) => NodeMatcher | |
| subWhenCondition | (whenMatcherCallback: NodeMatcherTransformer) => NodeMatcher |