import { ASTNode, NodeType } from "./common"; import { Lex } from "./lexer"; import { Parse } from "./parser"; export type FnError = `Function execution error: ${T}`; export type ToStringInner = T extends | string | number ? `${T}` : T extends readonly any[] ? T extends [infer Head, ...infer Tail] ? `${ToStringInner< Tail, `${Carry extends "" ? "" : `${Carry}, `}${ToStringInner}` >}` : `[${Carry}]` : FnError<`Can't stringify`>; export type BUILTIN_ToString = { [Idx in Exclude]: Args[Idx] extends ASTNode ? ToStringInner> : never; }; // export type BUILTIN_Print export type SENTINEL_NO_BUILTIN = "__NO_BUILTIN__"; export type MapBuiltins = Node["name"] extends "tostring" ? BUILTIN_ToString : SENTINEL_NO_BUILTIN; export type EvalError = `Eval error: ${T}`; export type Evaluate = Node["type"] extends NodeType.INT ? Node["value"] : Node["type"] extends NodeType.ROOT ? { // FIXME render as array?? [Idx in Exclude< keyof Node["children"], keyof any[] >]: Node["children"][Idx] extends ASTNode ? Evaluate : never; // indexing for now to remove object syntax // pls fix }[Exclude] : Node["type"] extends NodeType.EXT ? MapBuiltins : EvalError<`Unhandled node type ${Node["type"]}`>; const input = `tostring(5, 3)` as const; const lex_result = null as unknown as Lex; const parse_result = null as unknown as Parse; const eval_result = null as unknown as Evaluate;