diff --git a/src/language/compiling/semantics/keyword-handlers/lookup-handler.ts b/src/language/compiling/semantics/keyword-handlers/lookup-handler.ts index a04d733..0c37b07 100644 --- a/src/language/compiling/semantics/keyword-handlers/lookup-handler.ts +++ b/src/language/compiling/semantics/keyword-handlers/lookup-handler.ts @@ -4,6 +4,7 @@ import type { ElaborationError, InvalidExpressionError, } from '../../../errors.js' +import type { Molecule } from '../../../parsing.js' import { applyKeyPathToSemanticGraph, isObjectNode, @@ -27,7 +28,7 @@ export const lookupKeywordHandler: KeywordHandler = ( context: ExpressionContext, ): Either => either.flatMap(readLookupExpression(expression), ({ query }) => - either.flatMap(keyPathFromObjectNode(query), relativePath => { + either.flatMap(keyPathFromObject(query), relativePath => { if (isObjectNode(context.program)) { return either.flatMap( lookup({ @@ -55,8 +56,8 @@ export const lookupKeywordHandler: KeywordHandler = ( }), ) -const keyPathFromObjectNode = ( - node: ObjectNode, +const keyPathFromObject = ( + node: ObjectNode | Molecule, ): Either => { const relativePath: string[] = [] let queryIndex = 0 diff --git a/src/language/semantics/expressions/lookup-expression.ts b/src/language/semantics/expressions/lookup-expression.ts index a2801b7..a01af48 100644 --- a/src/language/semantics/expressions/lookup-expression.ts +++ b/src/language/semantics/expressions/lookup-expression.ts @@ -17,7 +17,7 @@ import { export type LookupExpression = ObjectNode & { readonly 0: '@lookup' - readonly query: ObjectNode + readonly query: ObjectNode | Molecule } export const readLookupExpression = ( @@ -52,7 +52,7 @@ export const readLookupExpression = ( }) export const makeLookupExpression = ( - query: ObjectNode, + query: ObjectNode | Molecule, ): LookupExpression & { readonly [unelaboratedKey]: true } => makeUnelaboratedObjectNode({ 0: '@lookup', diff --git a/src/language/semantics/prelude.ts b/src/language/semantics/prelude.ts index deb697d..7251f09 100644 --- a/src/language/semantics/prelude.ts +++ b/src/language/semantics/prelude.ts @@ -2,13 +2,13 @@ import either, { type Either } from '@matt.kantor/either' import option from '@matt.kantor/option' import type { DependencyUnavailable, Panic } from '../errors.js' import type { Atom } from '../parsing.js' +import { makeApplyExpression, makeLookupExpression } from '../semantics.js' import { isFunctionNode, makeFunctionNode } from './function-node.js' import { keyPathToMolecule, type KeyPath } from './key-path.js' import { isObjectNode, lookupPropertyOfObjectNode, makeObjectNode, - makeUnelaboratedObjectNode, type ObjectNode, } from './object-node.js' import { @@ -47,9 +47,8 @@ const handleUnavailableDependencies = const serializePartiallyAppliedFunction = (keyPath: KeyPath, argument: SemanticGraph) => () => either.makeRight( - makeUnelaboratedObjectNode({ - 0: '@apply', - function: { 0: '@lookup', query: keyPathToMolecule(keyPath) }, + makeApplyExpression({ + function: makeLookupExpression(keyPathToMolecule(keyPath)), argument, }), ) @@ -63,13 +62,7 @@ const preludeFunction = ( ) => makeFunctionNode( signature, - () => - either.makeRight( - makeUnelaboratedObjectNode({ - 0: '@lookup', - query: keyPathToMolecule(keyPath), - }), - ), + () => either.makeRight(makeLookupExpression(keyPathToMolecule(keyPath))), option.none, handleUnavailableDependencies(f), )