Replace Blank/BlankOptional atoms with placeholder symbols.
(expr: Json, variable: string)
| 59 | const VAR = 'RUBIPATVARX'; |
| 60 | |
| 61 | function isCall(x: Json, op: string): x is Json[] { |
| 62 | return Array.isArray(x) && x[0] === op; |
| 63 | } |
| 64 | |
| 65 | /** Replace Blank/BlankOptional atoms with placeholder symbols. */ |
| 66 | function skeletonize(expr: Json, variable: string): Json { |
| 67 | if (isCall(expr, 'Blank') || isCall(expr, 'BlankOptional')) { |
| 68 | const name = expr[1] as string; |
| 69 | if (name === variable) return VAR; |
| 70 | return (expr[0] === 'BlankOptional' ? OPT : SLOT) + name; |
| 71 | } |
| 72 | if (Array.isArray(expr)) |
| 73 | return expr.map((a, i) => (i === 0 ? a : skeletonize(a, variable))) as Json; |
no test coverage detected