19 lines
514 B
TypeScript
19 lines
514 B
TypeScript
import type { Data } from "./05data";
|
|
|
|
// Parsing
|
|
|
|
type Pair<A, B> = { left: A, right: B };
|
|
|
|
type List = ListNil | ListCons<any, any>;
|
|
type ListNil = { type: "list_nil" };
|
|
type ListCons<H, T extends List> = { type: "list_cons", head: H, tail: T };
|
|
|
|
type Parse<T> =
|
|
T extends `${infer Crates}\n\n${infer Instrs}` ? Pair<Crates, Instrs>:
|
|
never;
|
|
|
|
type SplitBy<T, Sep> =
|
|
T extends `${infer Head}${infer Sep}${infer Tail}` ? {}
|
|
: { type: "cons", head: T, tail: { type: "nil" } };
|
|
|
|
type DataSplit = Parse<Data>;
|