* Match a list of patterns against *remaining* (locally scoped) `ops` and consume this list along * the way, whilst appending to `substitution`. If a complete/successful match, return this new * substitution; else return `null`. * * @note: calls recursively (permutations) for sequence wi
(
patterns: ReadonlyArray<Expression>,
substitution: BoxedSubstitution
)
| 989 | } |
| 990 | for (let i = start; i < n; i++) { |
| 991 | combo.push(i); |
| 992 | backtrack(i + 1); |
| 993 | combo.pop(); |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | backtrack(0); |
| 998 | return result; |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | /** |
| 1003 | * Match a list of patterns against operands of expression, appending wildcards (named) to |
| 1004 | * *substitution* (along the way). If a successful match, returns the new substitution (or the same |
| 1005 | * if no named wildcard), or *null* for no match. |
| 1006 | * |
| 1007 | * @param expr |
| 1008 | * @param patterns |
| 1009 | * @param substitution |
| 1010 | * @param options |
| 1011 | * @returns |
| 1012 | */ |
| 1013 | function matchArguments( |
| 1014 | expr: Expression, |
| 1015 | patterns: ReadonlyArray<Expression>, |
| 1016 | substitution: BoxedSubstitution, |
| 1017 | options: PatternMatchOptions |
| 1018 | ): BoxedSubstitution | null { |
| 1019 | if (patterns.length === 0) { |
| 1020 | if (isFunction(expr) && expr.ops.length === 0) return substitution; |
| 1021 | return null; |
| 1022 | } |
| 1023 | |
| 1024 | const ce = patterns[0].engine; |
| 1025 | |
| 1026 | // We're going to consume the ops array, so make a copy |
| 1027 | if (!isFunction(expr)) return null; |
| 1028 | const ops = [...expr.ops]; |
| 1029 | |
| 1030 | return matchRemaining(patterns, substitution); |
| 1031 | |
| 1032 | /* |
| 1033 | * Local f(). |
| 1034 | */ |
| 1035 | /** |
| 1036 | * Match a list of patterns against *remaining* (locally scoped) `ops` and consume this list along |
| 1037 | * the way, whilst appending to `substitution`. If a complete/successful match, return this new |
| 1038 | * substitution; else return `null`. |
| 1039 | * |
| 1040 | * @note: calls recursively (permutations) for sequence wildcards |
| 1041 | * |
| 1042 | * @param patterns |
| 1043 | * @param substitution |
| 1044 | * @returns |
| 1045 | */ |
| 1046 | function matchRemaining( |
| 1047 | patterns: ReadonlyArray<Expression>, |
| 1048 | substitution: BoxedSubstitution |
no test coverage detected