* Return a new substitution based on arg. `substitution`, but with wildcard (of value *expr*) * added. * Returns given *substitution* unchanged if wildcard is a unnamed, or is already present in * substitution. * * Returns `null` in cases either of attempting to an existing wildcard/substitutio
( wildcard: string, expr: Expression, substitution: BoxedSubstitution )
| 74 | |
| 75 | /** |
| 76 | * Return a new substitution based on arg. `substitution`, but with wildcard (of value *expr*) |
| 77 | * added. |
| 78 | * Returns given *substitution* unchanged if wildcard is a unnamed, or is already present in |
| 79 | * substitution. |
| 80 | * |
| 81 | * Returns `null` in cases either of attempting to an existing wildcard/substitution with a |
| 82 | * different value, or if the given *expr* is, or contains, a wildcard expression. |
| 83 | * |
| 84 | * @param wildcard |
| 85 | * @param expr |
| 86 | * @param substitution |
| 87 | * @returns |
| 88 | */ |
| 89 | function captureWildcard( |
| 90 | wildcard: string, |
| 91 | expr: Expression, |
| 92 | substitution: BoxedSubstitution |
| 93 | ): BoxedSubstitution | null { |
| 94 | console.assert(wildcard.startsWith('_')); |
| 95 | |
| 96 | // If this is a universal wildcard, it always matches and no need to add it |
| 97 | // to the substitution record. |
| 98 | if (wildcard === '_' || wildcard === '__' || wildcard === '___') |
| 99 | return substitution; |
| 100 | |
| 101 | if (wildcard in substitution) { |
| 102 | // There was already a matching wildcard, make sure this one is identical. |
| 103 | // Patterns are syntax: a capture can contain pattern-side artifacts (a |
| 104 | // pre-bound wildcard like the unknown `_x` during equation solving, raw |
no test coverage detected