Skip to content

Commit 38dd453

Browse files
committed
Leverage keyword expression constructors in prelude
1 parent cd2a9ff commit 38dd453

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

src/language/compiling/semantics/keyword-handlers/lookup-handler.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
ElaborationError,
55
InvalidExpressionError,
66
} from '../../../errors.js'
7+
import type { Molecule } from '../../../parsing.js'
78
import {
89
applyKeyPathToSemanticGraph,
910
isObjectNode,
@@ -27,7 +28,7 @@ export const lookupKeywordHandler: KeywordHandler = (
2728
context: ExpressionContext,
2829
): Either<ElaborationError, SemanticGraph> =>
2930
either.flatMap(readLookupExpression(expression), ({ query }) =>
30-
either.flatMap(keyPathFromObjectNode(query), relativePath => {
31+
either.flatMap(keyPathFromObject(query), relativePath => {
3132
if (isObjectNode(context.program)) {
3233
return either.flatMap(
3334
lookup({
@@ -55,8 +56,8 @@ export const lookupKeywordHandler: KeywordHandler = (
5556
}),
5657
)
5758

58-
const keyPathFromObjectNode = (
59-
node: ObjectNode,
59+
const keyPathFromObject = (
60+
node: ObjectNode | Molecule,
6061
): Either<InvalidExpressionError, KeyPath> => {
6162
const relativePath: string[] = []
6263
let queryIndex = 0

src/language/semantics/expressions/lookup-expression.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717

1818
export type LookupExpression = ObjectNode & {
1919
readonly 0: '@lookup'
20-
readonly query: ObjectNode
20+
readonly query: ObjectNode | Molecule
2121
}
2222

2323
export const readLookupExpression = (
@@ -52,7 +52,7 @@ export const readLookupExpression = (
5252
})
5353

5454
export const makeLookupExpression = (
55-
query: ObjectNode,
55+
query: ObjectNode | Molecule,
5656
): LookupExpression & { readonly [unelaboratedKey]: true } =>
5757
makeUnelaboratedObjectNode({
5858
0: '@lookup',

src/language/semantics/prelude.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import either, { type Either } from '@matt.kantor/either'
22
import option from '@matt.kantor/option'
33
import type { DependencyUnavailable, Panic } from '../errors.js'
44
import type { Atom } from '../parsing.js'
5+
import { makeApplyExpression, makeLookupExpression } from '../semantics.js'
56
import { isFunctionNode, makeFunctionNode } from './function-node.js'
67
import { keyPathToMolecule, type KeyPath } from './key-path.js'
78
import {
89
isObjectNode,
910
lookupPropertyOfObjectNode,
1011
makeObjectNode,
11-
makeUnelaboratedObjectNode,
1212
type ObjectNode,
1313
} from './object-node.js'
1414
import {
@@ -47,9 +47,8 @@ const handleUnavailableDependencies =
4747
const serializePartiallyAppliedFunction =
4848
(keyPath: KeyPath, argument: SemanticGraph) => () =>
4949
either.makeRight(
50-
makeUnelaboratedObjectNode({
51-
0: '@apply',
52-
function: { 0: '@lookup', query: keyPathToMolecule(keyPath) },
50+
makeApplyExpression({
51+
function: makeLookupExpression(keyPathToMolecule(keyPath)),
5352
argument,
5453
}),
5554
)
@@ -63,13 +62,7 @@ const preludeFunction = (
6362
) =>
6463
makeFunctionNode(
6564
signature,
66-
() =>
67-
either.makeRight(
68-
makeUnelaboratedObjectNode({
69-
0: '@lookup',
70-
query: keyPathToMolecule(keyPath),
71-
}),
72-
),
65+
() => either.makeRight(makeLookupExpression(keyPathToMolecule(keyPath))),
7366
option.none,
7467
handleUnavailableDependencies(f),
7568
)

0 commit comments

Comments
 (0)