Skip to content

Commit 912f9f4

Browse files
authored
Merge pull request #34 from mkantor/simplify-unelaboratedness
Avoid manual unelaboratedness tracking
2 parents 166cfca + e80cf4a commit 912f9f4

File tree

12 files changed

+36
-93
lines changed

12 files changed

+36
-93
lines changed

src/language/runtime/keywords.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ import {
1414
type KeywordHandlers,
1515
type SemanticGraph,
1616
} from '../semantics.js'
17-
import {
18-
lookupPropertyOfObjectNode,
19-
makeUnelaboratedObjectNode,
20-
} from '../semantics/object-node.js'
17+
import { lookupPropertyOfObjectNode } from '../semantics/object-node.js'
2118
import { prettyJson } from '../unparsing.js'
2219

2320
const unserializableFunction = () =>
@@ -169,10 +166,7 @@ const lookupWithinExpression = (
169166
expression: Expression,
170167
): Option<SemanticGraph> => {
171168
for (const key of keyAliases) {
172-
const result = lookupPropertyOfObjectNode(
173-
key,
174-
makeUnelaboratedObjectNode(expression),
175-
)
169+
const result = lookupPropertyOfObjectNode(key, makeObjectNode(expression))
176170
if (!option.isNone(result)) {
177171
return result
178172
}

src/language/semantics.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,13 @@ export {
5959
isObjectNode,
6060
lookupPropertyOfObjectNode,
6161
makeObjectNode,
62-
makeUnelaboratedObjectNode,
6362
type ObjectNode,
6463
} from './semantics/object-node.js'
6564
export { prelude } from './semantics/prelude.js'
6665
export {
6766
applyKeyPathToSemanticGraph,
6867
containsAnyUnelaboratedNodes,
6968
isSemanticGraph,
70-
isUnelaborated,
7169
matchSemanticGraph,
7270
serialize,
7371
stringifySemanticGraphForEndUser,

src/language/semantics/expression-elaboration.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ import type { Atom, Molecule, SyntaxTree } from '../parsing.js'
77
import type { Expression } from './expression.js'
88
import type { KeyPath } from './key-path.js'
99
import { isKeyword, type Keyword } from './keyword.js'
10-
import {
11-
makeObjectNode,
12-
makeUnelaboratedObjectNode,
13-
type ObjectNode,
14-
} from './object-node.js'
10+
import { makeObjectNode, type ObjectNode } from './object-node.js'
1511
import {
1612
extractStringValueIfPossible,
1713
updateValueAtKeyPathInSemanticGraph,
@@ -44,10 +40,7 @@ export const elaborate = (
4440
elaborateWithContext(program, {
4541
keywordHandlers,
4642
location: [],
47-
program:
48-
typeof program === 'string'
49-
? program
50-
: makeUnelaboratedObjectNode(program),
43+
program: typeof program === 'string' ? program : makeObjectNode(program),
5144
})
5245

5346
export const elaborateWithContext = (
@@ -161,7 +154,7 @@ const handleObjectNodeWhichMayBeAExpression = (
161154
const { 0: possibleKeyword, ...possibleArguments } = node
162155
return isKeyword(possibleKeyword)
163156
? context.keywordHandlers[possibleKeyword](
164-
makeUnelaboratedObjectNode({
157+
makeObjectNode({
165158
...possibleArguments,
166159
0: possibleKeyword,
167160
}),

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import either, { type Either } from '@matt.kantor/either'
22
import type { ElaborationError } from '../../errors.js'
33
import type { Molecule } from '../../parsing.js'
44
import { isSpecificExpression } from '../expression.js'
5-
import { makeUnelaboratedObjectNode, type ObjectNode } from '../object-node.js'
6-
import { type SemanticGraph, type unelaboratedKey } from '../semantic-graph.js'
5+
import { makeObjectNode, type ObjectNode } from '../object-node.js'
6+
import { type SemanticGraph } from '../semantic-graph.js'
77
import { readArgumentsFromExpression } from './expression-utilities.js'
88

99
export type ApplyExpression = ObjectNode & {
@@ -34,8 +34,8 @@ export const makeApplyExpression = ({
3434
}: {
3535
readonly function: SemanticGraph | Molecule
3636
readonly argument: SemanticGraph | Molecule
37-
}): ApplyExpression & { readonly [unelaboratedKey]: true } =>
38-
makeUnelaboratedObjectNode({
37+
}): ApplyExpression =>
38+
makeObjectNode({
3939
0: '@apply',
4040
function: f,
4141
argument,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import either, { type Either } from '@matt.kantor/either'
22
import type { ElaborationError } from '../../errors.js'
33
import type { Molecule } from '../../parsing.js'
44
import { isSpecificExpression } from '../expression.js'
5-
import { makeUnelaboratedObjectNode, type ObjectNode } from '../object-node.js'
6-
import { type SemanticGraph, type unelaboratedKey } from '../semantic-graph.js'
5+
import { makeObjectNode, type ObjectNode } from '../object-node.js'
6+
import { type SemanticGraph } from '../semantic-graph.js'
77
import { readArgumentsFromExpression } from './expression-utilities.js'
88

99
export type CheckExpression = ObjectNode & {
@@ -34,8 +34,8 @@ export const makeCheckExpression = ({
3434
}: {
3535
value: SemanticGraph | Molecule
3636
type: SemanticGraph | Molecule
37-
}): CheckExpression & { readonly [unelaboratedKey]: true } =>
38-
makeUnelaboratedObjectNode({
37+
}): CheckExpression =>
38+
makeObjectNode({
3939
0: '@check',
4040
value,
4141
type,

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { Expression } from '../expression.js'
77
import { stringifyKeyPathForEndUser } from '../key-path.js'
88
import {
99
lookupPropertyOfObjectNode,
10-
makeUnelaboratedObjectNode,
10+
makeObjectNode,
1111
type ObjectNode,
1212
} from '../object-node.js'
1313
import {
@@ -18,8 +18,7 @@ import {
1818

1919
export const asSemanticGraph = (
2020
value: SemanticGraph | Molecule,
21-
): SemanticGraph =>
22-
isSemanticGraph(value) ? value : makeUnelaboratedObjectNode(value)
21+
): SemanticGraph => (isSemanticGraph(value) ? value : makeObjectNode(value))
2322

2423
export const locateSelf = (context: ExpressionContext) =>
2524
option.match(applyKeyPathToSemanticGraph(context.program, context.location), {
@@ -73,10 +72,7 @@ const lookupWithinExpression = (
7372
expression: Expression,
7473
): Option<SemanticGraph> => {
7574
for (const key of keyAliases) {
76-
const result = lookupPropertyOfObjectNode(
77-
key,
78-
makeUnelaboratedObjectNode(expression),
79-
)
75+
const result = lookupPropertyOfObjectNode(key, makeObjectNode(expression))
8076
if (!option.isNone(result)) {
8177
return result
8278
}

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ import either, { type Either } from '@matt.kantor/either'
22
import type { ElaborationError } from '../../errors.js'
33
import type { Atom, Molecule } from '../../parsing.js'
44
import { isSpecificExpression } from '../expression.js'
5-
import { makeUnelaboratedObjectNode, type ObjectNode } from '../object-node.js'
6-
import {
7-
serialize,
8-
type SemanticGraph,
9-
type unelaboratedKey,
10-
} from '../semantic-graph.js'
5+
import { makeObjectNode, type ObjectNode } from '../object-node.js'
6+
import { serialize, type SemanticGraph } from '../semantic-graph.js'
117
import {
128
asSemanticGraph,
139
readArgumentsFromExpression,
@@ -46,8 +42,8 @@ export const readFunctionExpression = (
4642
export const makeFunctionExpression = (
4743
parameter: Atom,
4844
body: SemanticGraph | Molecule,
49-
): FunctionExpression & { readonly [unelaboratedKey]: true } =>
50-
makeUnelaboratedObjectNode({
45+
): FunctionExpression =>
46+
makeObjectNode({
5147
0: '@function',
5248
parameter,
5349
body,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { isSpecificExpression } from '../expression.js'
55
import { keyPathFromObjectNodeOrMolecule } from '../key-path.js'
66
import {
77
isObjectNode,
8-
makeUnelaboratedObjectNode,
8+
makeObjectNode,
99
type ObjectNode,
1010
} from '../object-node.js'
11-
import { type SemanticGraph, type unelaboratedKey } from '../semantic-graph.js'
11+
import { type SemanticGraph } from '../semantic-graph.js'
1212
import {
1313
asSemanticGraph,
1414
readArgumentsFromExpression,
@@ -61,8 +61,8 @@ export const makeIndexExpression = ({
6161
}: {
6262
readonly query: ObjectNode | Molecule
6363
readonly object: ObjectNode | Molecule
64-
}): IndexExpression & { readonly [unelaboratedKey]: true } =>
65-
makeUnelaboratedObjectNode({
64+
}): IndexExpression =>
65+
makeObjectNode({
6666
0: '@index',
6767
object,
6868
query,

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ import {
77
keyPathFromObjectNodeOrMolecule,
88
keyPathToMolecule,
99
} from '../key-path.js'
10-
import {
11-
makeObjectNode,
12-
makeUnelaboratedObjectNode,
13-
type ObjectNode,
14-
} from '../object-node.js'
15-
import { type SemanticGraph, type unelaboratedKey } from '../semantic-graph.js'
10+
import { makeObjectNode, type ObjectNode } from '../object-node.js'
11+
import { type SemanticGraph } from '../semantic-graph.js'
1612
import {
1713
asSemanticGraph,
1814
readArgumentsFromExpression,
@@ -56,8 +52,8 @@ export const readLookupExpression = (
5652

5753
export const makeLookupExpression = (
5854
query: ObjectNode | Molecule,
59-
): LookupExpression & { readonly [unelaboratedKey]: true } =>
60-
makeUnelaboratedObjectNode({
55+
): LookupExpression =>
56+
makeObjectNode({
6157
0: '@lookup',
6258
query,
6359
})

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import type { ElaborationError } from '../../errors.js'
33
import type { Molecule } from '../../parsing.js'
44
import { isSpecificExpression } from '../expression.js'
55
import { isFunctionNode } from '../function-node.js'
6-
import { makeUnelaboratedObjectNode, type ObjectNode } from '../object-node.js'
6+
import { makeObjectNode, type ObjectNode } from '../object-node.js'
77
import {
88
containsAnyUnelaboratedNodes,
99
type SemanticGraph,
10-
type unelaboratedKey,
1110
} from '../semantic-graph.js'
1211
import {
1312
asSemanticGraph,
@@ -46,10 +45,8 @@ export const readRuntimeExpression = (
4645
message: 'not an expression',
4746
})
4847

49-
export const makeRuntimeExpression = (
50-
f: SemanticGraph,
51-
): RuntimeExpression & { readonly [unelaboratedKey]: true } =>
52-
makeUnelaboratedObjectNode({
48+
export const makeRuntimeExpression = (f: SemanticGraph): RuntimeExpression =>
49+
makeObjectNode({
5350
0: '@runtime',
5451
function: f,
5552
})

0 commit comments

Comments
 (0)