| 385 | } |
| 386 | |
| 387 | const splitTop = (def: string, separator: string): string[] => { |
| 388 | const parts: string[] = [] |
| 389 | let depth = 0 |
| 390 | let quoted = false |
| 391 | let start = 0 |
| 392 | for (let i = 0; i < def.length; i++) { |
| 393 | const c = def[i] |
| 394 | if (c === "'") quoted = !quoted |
| 395 | else if (quoted) continue |
| 396 | else if (c === "/" || c === "\\" || c === '"') return [def] |
| 397 | else if (c === "(") depth++ |
| 398 | else if (c === ")") depth-- |
| 399 | else if (!depth && def.startsWith(separator, i)) { |
| 400 | parts.push(def.slice(start, i)) |
| 401 | i += separator.length - 1 |
| 402 | start = i + 1 |
| 403 | } |
| 404 | } |
| 405 | parts.push(def.slice(start)) |
| 406 | return parts |
| 407 | } |
| 408 | |
| 409 | const wrap = (f: Facts) => (f.terms ? `(${f.key})` : f.key) |
| 410 | |