Compare commits

..

3 Commits

Author SHA1 Message Date
Jos de Jong 6bfd06cafb feat: extract generic parameter from the reflectedType (see #18) 2023-10-18 15:22:21 +02:00
Jos de Jong 0cdc9aba78 chore: fix typo in type definition of `FunctionDef` 2023-10-18 15:11:54 +02:00
Glen Whitney 40146c2f48 feat: Runtime type reflection (#17)
Now each behavior specification "knows" its type information.
  Also bumps version number and sets up so that the scripts will run on Windows as well as Unix (thanks to Jos).
  Resolves #5.
  Resolves #16.

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
Reviewed-on: #17
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Co-committed-by: Glen Whitney <glen@studioinfinity.org>
2023-10-17 22:02:18 +00:00
1 changed files with 8 additions and 2 deletions

View File

@ -1,4 +1,4 @@
export type FunctionDef {
export type FunctionDef = {
name: string,
aliasOf?: string,
signatures: Array<{
@ -11,6 +11,7 @@ export type FunctionDef {
export type ImplementationDef = {
fn: FunctionDef,
dependencies: Record<string, FunctionDef>
genericParameter: string | null
}
/**
@ -23,6 +24,11 @@ export function parseReflectedType(name: string, reflectedType: string): Impleme
const [factoryArgs, fnsClause] = split(reflectedType, '=>', 2).map(trim)
const fn = parseAlias(name, fnsClause)
// extract the generic parameter like '<T>' at the start of the type
const genericParameter = factoryArgs.trim().startsWith('<')
? findBlockContents(factoryArgs, '<', '>')?.innerText || null
: null
const factoryArgsInner = findBlockContents(factoryArgs, '(', ')')
const depArg = split(factoryArgsInner.innerText, ':').map(trim)[1]
const depArgBlocks: string[] = depArg ? split(depArg, '&').map(trim) : []
@ -39,7 +45,7 @@ export function parseReflectedType(name: string, reflectedType: string): Impleme
const dependencies: Record<string, FunctionDef> = groupBy(deps, 'name')
return {fn, dependencies}
return {fn, dependencies, genericParameter }
}
function parseDependencies(deps: string): FunctionDef[] {