MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / captureWildcard

Function captureWildcard

src/compute-engine/boxed-expression/match.ts:76–101  ·  view source on GitHub ↗

* 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
)

Source from the content-addressed store, hash-verified

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 */
89function 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

Callers 4

matchOnceFunction · 0.85
tryAssignWildcardsFunction · 0.85
matchRemainingFunction · 0.85
matchIdentityTermFunction · 0.85

Calls 3

hasUnboundWildcardsFunction · 0.85
assertMethod · 0.80
isSameMethod · 0.65

Tested by

no test coverage detected