MCPcopy Create free account
hub / github.com/LambdaNote/support-ts-tapl / subsetSystem

Function subsetSystem

article/utils.ts:476–497  ·  view source on GitHub ↗
(
  node: Term,
  keepTypes: Types[],
  keepTerms: Terms[],
)

Source from the content-addressed store, hash-verified

474type ExtractTags<T, K> = Extract<{ [P in keyof T]: ExtractTagsSub<T[P], K> }, { tag: K }>;
475
476function subsetSystem<Types extends Type["tag"], Terms extends Term["tag"]>(
477 node: Term,
478 keepTypes: Types[],
479 keepTerms: Terms[],
480): ExtractTags<Term, Types | Terms> {
481 if (!node.tag) return node;
482
483 if (!(<string[]> keepTypes).includes(node.tag) && !(<string[]> keepTerms).includes(node.tag)) {
484 throw new Error(`"${node.tag}" is not allowed in this system`);
485 }
486
487 // deno-lint-ignore no-explicit-any
488 const newNode: any = {};
489 Object.entries(node).forEach(([key, val]) => {
490 if (typeof val !== "object" || !val.tag) {
491 newNode[key] = val;
492 } else {
493 newNode[key] = subsetSystem<Types, Terms>(val, keepTypes, keepTerms);
494 }
495 });
496 return newNode;
497}
498
499export function parse(code: string): Term {
500 const node = p.parse(code, { allowInvalidAST: false, loc: true });

Callers 7

parseArithFunction · 0.70
parseBasicFunction · 0.70
parseExtendedFunction · 0.70
parseSubFunction · 0.70
parseRecFunction · 0.70
parseRec2Function · 0.70
parsePolyFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected