Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
ElaborationError,
InvalidExpressionError,
} from '../../../errors.js'
import type { Molecule } from '../../../parsing.js'
import {
applyKeyPathToSemanticGraph,
isObjectNode,
Expand All @@ -27,7 +28,7 @@ export const lookupKeywordHandler: KeywordHandler = (
context: ExpressionContext,
): Either<ElaborationError, SemanticGraph> =>
either.flatMap(readLookupExpression(expression), ({ query }) =>
either.flatMap(keyPathFromObjectNode(query), relativePath => {
either.flatMap(keyPathFromObject(query), relativePath => {
if (isObjectNode(context.program)) {
return either.flatMap(
lookup({
Expand Down Expand Up @@ -55,8 +56,8 @@ export const lookupKeywordHandler: KeywordHandler = (
}),
)

const keyPathFromObjectNode = (
node: ObjectNode,
const keyPathFromObject = (
node: ObjectNode | Molecule,
): Either<InvalidExpressionError, KeyPath> => {
const relativePath: string[] = []
let queryIndex = 0
Expand Down
4 changes: 2 additions & 2 deletions src/language/semantics/expressions/lookup-expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {

export type LookupExpression = ObjectNode & {
readonly 0: '@lookup'
readonly query: ObjectNode
readonly query: ObjectNode | Molecule
}

export const readLookupExpression = (
Expand Down Expand Up @@ -52,7 +52,7 @@ export const readLookupExpression = (
})

export const makeLookupExpression = (
query: ObjectNode,
query: ObjectNode | Molecule,
): LookupExpression & { readonly [unelaboratedKey]: true } =>
makeUnelaboratedObjectNode({
0: '@lookup',
Expand Down
15 changes: 4 additions & 11 deletions src/language/semantics/prelude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}),
)
Expand All @@ -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),
)
Expand Down