mirror of
https://github.com/betagouv/mon-entreprise
synced 2025-02-10 01:05:02 +00:00
18 lines
530 B
TypeScript
18 lines
530 B
TypeScript
import { evaluationFunction } from '.'
|
|
import { ASTNode } from './AST/types'
|
|
|
|
export let evaluationFunctions = {
|
|
constant: (node) => node,
|
|
} as any
|
|
|
|
export function registerEvaluationFunction<
|
|
NodeName extends ASTNode['nodeKind']
|
|
>(nodeKind: NodeName, evaluationFunction: evaluationFunction<NodeName>) {
|
|
evaluationFunctions ??= {}
|
|
if (evaluationFunctions[nodeKind]) {
|
|
throw Error(
|
|
`Multiple evaluation functions registered for the nodeKind \x1b[4m${nodeKind}`
|
|
)
|
|
}
|
|
evaluationFunctions[nodeKind] = evaluationFunction
|
|
}
|